Hallo Markus,
heisst das, ich muss die CS Leitung für jedes Byte tooglen oder kann ich die gesamte Übertragung mit einem Low CS fahren, wenn ich mehre Bytes zu übertragen habe.
Bin derzeitig am Debuggen mit Logikanalyser..
Gruss R.
- - - Aktualisiert - - -
Hallo Markus,
hier die Startroutine, welche im Hauptprogramm liegt und die Interruptverarbeitung startet:
Hier die eigentliche Startroutine, welche auch noch andere Steuerfunktionen übernimmtCode:CLEAR_BIT(PORTB,OUTPUT_SELECT_SPI_GYRO); // Select the slave // ReadGyroADIS16265(); // load Data for command ReadAngleADIS16265(); Master_Start_Send_SPI( SPI_SLAVE_GYRO, GYRO_SPEED_CALCULATION );
Code:// ================================================================== // Start the communication with the Slave // ================================================================== void Master_Start_Send_SPI (int iChannel, int iBit ) { m_Active_SPI_Channel=iChannel; // Select the channel m_SPIByteToSend--; // Send the first byte out SPDR=SPISendBuffer[0]; // Send it m_ArrayReadPointer=0; // Set Pointer to first byte to receive m_ArrayWritePointer=1; // Set Pointer to the next byte m_DummyByteReceived=false; // Dummy byte not received CLEAR_BIT( m_SPI_Status, iBit); // Clear the request }
Hier die Interruptroutine
Code:/ ================================================================== // SPI Interrupt for the received chars from Slaves // ================================================================== SIGNAL (SPI_STC_vect) { unsigned char data=0; // Clear data bytes data=SPDR; // get the data byte from the register if(m_SPIByteToSend > 0) { SPDR=SPISendBuffer[m_ArrayWritePointer]; // Send the next byte out to slave m_ArrayWritePointer++; m_SPIByteToSend--; // to get the complete answer } if( m_SPIBytetoReceive > 0) // Do we wait still for answers { SPIReceiveBuffer[m_ArrayReadPointer]=data; // Store the byte received if( m_DummyByteReceived == true ) // We have to send one more byte { m_SPIBytetoReceive--; // Still a byte received m_ArrayReadPointer++; // Set pointer to the next position } if(m_SPIBytetoReceive > 0 && m_SPIByteToSend == 0 ) // Send of data finished SPDR=0x0; // Send a dummy Byte to get the next bytes } if(m_SPIBytetoReceive == 0) // transmission block finished { SET_BIT(PORTB,OUTPUT_SELECT_SPI_GYRO); // De select the all slave SET_BIT(PORTB,OUTPUT_SELECT_SPI_COMPASS); SET_BIT(PORTB,OUTPUT_SELECT_SPI_ATMEGA8); // Select of which to select costs more CPU power, than all once } m_DummyByteReceived=true; // Dummy byte received }
Im Anhang das Impulsdiagram der Schnittstelle.
Sieht meiner Meinung nach o.k. aus.
Wenn, nicht bitte komentar, sonst benutzt jemand anderes das hier und hat Probleme.
Ich teste noch weiter mit meinem Atmega8 Slave, den Code kann ich ja dann auch posten, wenn erst fertig ist.
Gruss R.







Zitieren

Lesezeichen