Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

Reply To: spi communication

Home Forums MPLAB XC8 Tutorial Discussions spi communication Reply To: spi communication

#3373

chris
Participant

So underneath i made an example of how to sent four bytes of data to a slave

LATC0 = 0;                                        // Select slave 1 (Active low for Device 1)
SPI_Exchange8bit     (0xff);          //this is the first byte to be sent                                          SPI_Exchange8bit     (0xe5);         // this is the second byte to be sent                                SPI_Exchange8bit     (ox34);         // third byte to be sent                                                        SPI_Exchange8bit      (0x8b);        //  fourth byte to be sent
LATC0 = 1;                                        // Deselect slave 1

and this is the code for the slave to receive 4 bytes of data from the master:

while (1) {
data= SPI1_Exchange8bit(0x00);      //first byte of data to receive                                                   variable2= SPI1_Exchange8bit(0x00);      //second byte of data to receive                             variable3= SPI1_Exchange8bit(0x00);      //third byte of data to receive                                    variable4= SPI1_Exchange8bit(0x00);      //fourth byte of data to receive
LATB = data;

this is the right procedure for sending four bytes of data to an slave

 

  • This reply was modified 2 months, 1 week ago by  chris.
  • This reply was modified 2 months, 1 week ago by  chris.
  • This reply was modified 2 months, 1 week ago by  chris.