About SPI_anything

Hi

I found Nick Gammon simple way to use SPI Gammon Forum : Electronics : Microprocessors : SPI - Serial Peripheral Interface - for Arduino by using SPI_anything. But there is master sends, slave receive. I want to use master request, slave sends. Does somebody have that example? Sorry for noob question...

something like this?

https://forum.arduino.cc/index.php?topic=488171.msg3331154#msg3331154

Not exactly. I want that slave reads some sensors and master requests those readings.

FiveO:
Not exactly. I want that slave reads some sensors and master requests those readings.

Ok but the the principle on that diagram still holds. just need to tweak the code a bit! :slight_smile:

so it pseudo code it would be something like this

MASTER: 
//request slave to send sensor data
slave_reply = spi.transfer(READ_SENSOR); //at this point slave_reply will hold no valid data
             
do{
   delaymicroseconds(20);
   slave_reply = spi.transfer(0xFF);  //in your slave code it replies READING while its reading the sensors.

}while(spi_reply == READING);


if(spi_reply = DATA_READY){

 //if u now the number of sensor readings u getting can use a for loop
 //else implement on your slave side that is sends out how many sensor reading its got available

   spi_reply = spi.transfer(SEND_DATA);

   for(uint_8t i=0; i<ARR_SIZE;++i){
       sensor_data[i] = spi.transfer(SEND_DATA);
       delaymicroseconds(20);
   }
}

hope that helps