7 years, 7 months ago.

SPI protocol Communication (SPI.h library, .write function)

Hi, once i've instantiated an SPI Master and i send data through .write operation ( for example spi.write(measurement) where measurement is an int), how can i understand which is the response returned from the slave connected to my master? Shoul i access a certain register or is necessary to write this statement ( int data_received=spi.write(measurement) ) ?

Thanks

1 Answer

7 years, 7 months ago.

That depends on the behaviour of the slave device. Check the datasheet.

Typically you first have to select some register and/or send a command byte to the slave. The next write operation sends some dummy byte(s) and at the same time receives the data you want to read.

spi.write(''insert the read command''); // send a specific command to prepare the slave device to send data on the next operation

char data_received = spi.write(0xFF); // write dummy byte to receive the data you need
 

Accepted Answer