| ??? 09/09/03 13:20 Read: times |
#54393 - Having trouble with 89S8252 SPI |
Hi there.
I am trying to get two 89S8252 to talk to each other on SPI. Therefore, I have configured one as the MASTER and the other as the SLAVE. The MASTER receives data to be sent from PC (via serial port). After getting the data, it sends it to the SLAVE (and receives the data as well). Now, first time it receives garbage (agreed). However, it so happens, that it receives garbage even in between. I am pasting my code here for your review. (SLAVE SPI is implemented in ISR, I tried w/o ISR as well but it gave same results). MASTER CODE ----------- SPCR = (SPE_ | MSTR_); // enable SPI and put in master mode while (1) { if (RI == 1) { RI = 0; // clear RI P1_3 = 0; // select slave SPDR = SBUF; //Rx from PC, Tx to slave while ((SPSR & SPIF_) == 0); // wait for end of Tx P1_3 = 1; // deselect slave SBUF = SPDR; // Rx from slave, Tx to PC while (TI != 1); // Wait for the byte to be sent TI = 0; // Clear flag } // if (RI == 1) } // while (1) FOR SLAVE --------- SPCR = (SPE_ | SPIE_); // enable SPI and enable its interrupt (global and serial interrupt is also enabled elsewhere is code) void spi () interrupt SIO_VECTOR { SPDR = SPDR; } I believe that upon interrupt, on reading the SPDR, the interrupt flag is cleared. Also I send back the received data, which master receives on its next Tx. If I send, for example, 0xAA to slave, sometimes I receive the correct data, and sometimes I receive 0xD5. Regards Aman Regards Aman |
| Topic | Author | Date |
| Having trouble with 89S8252 SPI | 01/01/70 00:00 | |
| RE: Having trouble with 89S8252 SPI | 01/01/70 00:00 | |
| RE: Having trouble with 89S8252 SPI | 01/01/70 00:00 | |
RE: Having trouble with 89S8252 SPI | 01/01/70 00:00 |



