cancel
Showing results for 
Search instead for 
Did you mean: 

How to apply SPI between ESP8266 and STM32f07 with FreeRTOS ?

CLi H.1
Associate II

Recently, I've been worked with the esp8266 and stmf407 discovery board.

I used stm32f407 (master), and connect to esp8266 (slave) via SPI

However, the package I got always missed 1 package. To be more specific, I've tried to send some uint8_t dummy datas, but all the results i got always had a missing part.

Arduino code in esp8266 :

https://github.com/esp8266/Arduino/blob/master/libraries/SPISlave/examples/SPISlave_Test/SPISlave_Test.ino

uvision code :

void StartDefaultTask(void const * argument)
{
  /* USER CODE BEGIN 5 */
  /* Infinite loop */
  for(;;)
  {
	 xSemaphoreTake(DeliverHandle,portMAX_DELAY);
	 xSemaphoreGive(DeliverHandle);
	 osDelay(20);	
	}
}	
 
void StartTask02(void const * argument)
{
  /* USER CODE BEGIN StartTask02 */
  /* Infinite loop */
 
  uint8_t SPI_data[4]={0x01,0x02,0x03,0x04};
  for(;;)
  {
	 xSemaphoreTake(DeliverHandle,portMAX_DELAY);	
	//ss low
	WPC_GPIO_Write_Pin(GPIOA,GPIO_PIN_15, 0x00); //CS = 0
	//spi transmit
	HAL_SPI_Transmit(&hspi2,SPI_data,4,1000);  //Send data
	//ss high
	WPC_GPIO_Write_Pin(GPIOA,GPIO_PIN_15, 0x01); //CS = 1
   }
       osDelay(20);
	xSemaphoreGive(DeliverHandle);
  /* USER CODE END StartTask02 */
	}
}

// I sent SPI_data[4]={0x01,0x02,0x03,0x04} through stm32f407 (master)

// esp8266(slave) debugging return from Arduino

0693W000006HAnaQAG.png// Nevertheless, the result i got is {0x00, 0x04, 0x03, 0x02}

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

The code you're using to send SPI is fine.

The bytes are reversed because the Arduino stores them blindly as they are received and then reads them back in little-endian.

i'm pretty sure the first byte (0x01) is lost because it indicates the status register, although it's quite hard to trace the logic in the Arduino code.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
TDK
Guru

The code you're using to send SPI is fine.

The bytes are reversed because the Arduino stores them blindly as they are received and then reads them back in little-endian.

i'm pretty sure the first byte (0x01) is lost because it indicates the status register, although it's quite hard to trace the logic in the Arduino code.

If you feel a post has answered your question, please click "Accept as Solution".

Thanks , you give me a big hand.