Hallo,
Hat jemand für mich vielleicht einen Code für das SSP Modul mit
Interrupts.
Das Beispiel von NXP funktioniert nicht bei mir zudem finde ich es auch
etwas kommisch.
Warum: Das ist ein Teil vom ISR Handler RX IRQ.
1 | /* please be aware that, in main and ISR, CurrentRxIndex and CurrentTxIndex
|
2 | are shared as global variables. It may create some race condition that main
|
3 | and ISR manipulate these variables at the same time. SSPSR_BSY checking (polling)
|
4 | in both main and ISR could prevent this kind of race condition */
|
5 | if ( regValue & SSPMIS_RXMIS ) /* Rx at least half full */
|
6 | {
|
7 | interruptRxStat++; /* receive until it's empty */
|
8 |
|
9 | while ( SSPSR & SSPSR_RNE )
|
10 | {
|
11 | SPIRDData[CurrentRxIndex++] = SSPDR;
|
12 | /* Wait until the Busy bit is cleared */
|
13 | while ( !(SSPSR & SSPSR_BSY) );
|
14 | } /* interrupt will be cleared when */
|
15 | /* data register is read or written */
|
16 | }
|
Wenn man aber ssptest analysiert, findet man folgendes:
1 | /* No need to consider CurrentTxIndex because it will always transmit
|
2 | as long as CurrentRxIndex is less than BUFSIZE. Once CurrentRxIndex reaches
|
3 | BUFSIZE, it has received the complete block of data, then we bail out on
|
4 | transmit. */
|
5 | IOCLR0 = SPI1_SEL;
|
6 | while ( CurrentRxIndex <= BUFSIZE )
|
7 | {
|
8 | /* to check the RXIM and TXIM interrupt, I send a block data at one time
|
9 | based on the FIFOSIZE(8). */
|
10 | SPI1Send( (BYTE *)&SPIWRData[CurrentTxIndex], FIFOSIZE );
|
11 | SPI1Receive( (BYTE *)&SPIRDData[CurrentRxIndex], FIFOSIZE );
|
12 | }
|
13 | IOSET0 = SPI1_SEL;
|
Die Funktion für SPI1Receive sollte doch aus dem Buffer lesen solange
was vorhanden ist macht Sie aber nicht diese holt es direkt aus dem
Empfangsregister:
1 | /*****************************************************************************
|
2 | ** Function name: SPI1Receive
|
3 | ** Descriptions: the module will receive a block of data from
|
4 | ** the SPI1(SSP), the 2nd parameter is the block
|
5 | ** length.
|
6 | ** parameters: buffer pointer, and block length
|
7 | ** Returned value: None
|
8 | **
|
9 | *****************************************************************************/
|
10 | void SPI1Receive( uint8_t *buf, uint8_t Length )
|
11 | {
|
12 | uint8_t i;
|
13 |
|
14 | for ( i = 0; i < Length; i++ )
|
15 | {
|
16 | /* As long as Receive FIFO is not empty, I can always receive. */
|
17 | /* since it's a loopback test, clock is shared for both TX and RX,
|
18 | no need to write dummy uint8_t to get clock to get the data */
|
19 | /* if it's a peer-to-peer communication, SSPDR needs to be written
|
20 | before a read can take place. */
|
21 | SSPDR = 0xFF;
|
22 | while ( !(SSPSR & SSPSR_RNE) );
|
23 | *buf = SSPDR; // <<-- ????
|
24 | buf++;
|
25 | CurrentRxIndex++;
|
26 | }
|
27 | return;
|
28 | }
|
Also kann mir vielleicht mal jemand das Beispiel erkären? Das ist doch
nicht korrekt. Der Interrupt kann doch nie zustande kommen wenn die
Recieve Routine das Register immer gleich aussliest, und diese sollte
doch nicht aus dem Register sonder aus dem Buffer lesen oder nicht?
Besten Dank schon mal