STM32F103 SPI Slave strategy
I use STM32F103C8T6 as SPI slave and want to send data on request by master.
The master sends to the slave a byte, which has to be used to decide, what has to be done
or what data data has to be sent to the master, and a fill byte which is needed
to shift out the interesting byte to the master. In the slave, I use SPI RX interrupt, which
is called after the master has sent its request byte:
void spi_rxhandler(SPI_HandleTypeDef *hspi){
leds_toggle(LED2);
//check data from SPI rxbuffer
switch(hspi->Instance->DR){
case 0x47:
execute_a_useful_function();
break;
case 0x8F:
hspi->Instance->DR=0x12;
break;
case 0xC8:
hspi->Instance->DR=0x34;
break;
default:
hspi->Instance->DR=0x56;
break;
}
__HAL_SPI_CLEAR_OVRFLAG(hspi);
}But this is too late. The TX-Buffer has to be filled much earlier, this implementation
leads to sending the byte which is written to DR to the master in the next try, when
the master repeats its read attempt.
Transferred to the image 242 of the RM008, my slave has to read 0xA1 to decide to
send 0xF2 to master.
Is there a strategy to achieve this? I use the HAL API.