2020-06-16 07:28 AM
I have configured STM32l496RG as slave and am trying to send data from my STM32L496RG slave to ESP32 master upon reception of data into buffer array. I am trying to echo the same data back to the master. My master ESP32 transmits data 'hello' and reads received data using SPI protocol. But on the STM32 side, when the master sends 'hello' the first time, receive interrupt callback is called. But after that, HAL_TRANSMIT_IT is called and executes but I don't receive anything back on the master. Next, when I send 'hello' from my master again, the receive interrupt callback is not called but I receive the 'hello' previously sent on my master. Hence, in order to receive the sent data on my master, I have to send the data twice from my master. If I comment out the transmission part in my code, the receive interrupt is triggered every time I send the data. How can I receive the SPI data and echo it back to my master? I have tried all combinations of transmit and receive, with interrupts and without interrupts, with DMA etc and none of them work when I want to receive and then transmit.
Here is my snippet of STM32 code -
while (1)
{
if(HAL_SPI_Receive_IT(&hspi1,(uint8_t*)buffer,sizeof(buffer))!=HAL_OK){
Error_Handler();
}
while(HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY);
}
}
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
{
if(HAL_SPI_Transmit(&hspi1,(uint8_t*)buffer,sizeof(buffer),200)!=HAL_OK){
Error_Handler();
}
and in case you need , here is my esp code - I am just sending some data received over telnet to stm32 .
for(i = 0; i < MAX_SRV_CLIENTS; i++){
if (serverClients[i] && serverClients[i].connected()){
if(serverClients[i].available()){
//get data from the telnet client and push it to the UART
while(serverClients[i].available())
{
// read the bytes incoming from the client:
char thisChar = serverClients[i].read();
inData += thisChar;
data_array[j]=thisChar;
j++;
// echo to the server what's been received to confirm we have the string
if (thisChar == '\n')
{
// Serial.print("\nreceived:");
// Serial.print(inData);
for(int i=0;i<(j-2);i++)
{
vspi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
digitalWrite(VSPI_SS, LOW); //pull SS slow to prep other end for transfer
{
received_data[i] = vspi->transfer(data_array[i]);
// Serial.print(data_array[m]);
// Serial.print('\t');
Serial.print(received_data[i]);
Serial.print('\t');
Serial.println(i);
}
digitalWrite(VSPI_SS, HIGH); //pull ss high to signify end of data transfer
vspi->endTransaction();
}
serverClients[i].write(received_data, (j-2));
j=0;
}
}
}
Can anyone try out any code where they can transmit after receiving?