espressif / ESP8266_RTOS_SDK

Latest ESP8266 SDK based on FreeRTOS, esp-idf style.
http://bbs.espressif.com
Apache License 2.0
3.32k stars 1.56k forks source link

SPI transmit data on HSPI_HOST is wrong (GIT8266O-355) #791

Open Bresenham opened 4 years ago

Bresenham commented 4 years ago

Environment

Problem Description

The ESP8266 is configured as an SPI-Master and transmits 2 messages to an SPI-Slave. After these two message are transmitted, one SPI-read of 8-bits is performed. The first message, called writeMsg in code, consists of five individual bytes. The second message, called readMsg in code, consists of four individual bytes. writeMsg[1:3] and readMsg[1:3] are equal (as you can see in the example code) but for whatever reason, readMsg[1:3] show up as 0 on my LogicAnalyzer even though writeMsg is transmitted perfectly fine. However, if I don't transmitwriteMsg, readMsg is sent correctly.

Expected Behavior

Bytes readMsg[1:3] should be equal to [0x00, 0x16, 0xC5].

Actual Behavior

Bytes readMsg[1:3] are [0x00, 0x00, 0x00].

Steps to repropduce

  1. Copy linked code
  2. Compile and flash
  3. Watch SPI-Pins of HSPI_HOST via LogicAnalyzer / digital oscilloscope

Code to reproduce this issue

https://gist.github.com/Bresenham/f5c016361e21b9a3711ef5e7565f7874

Another version of the code which behaves the same but is more refined: https://gist.github.com/Bresenham/fdda4ff163c68188a6f150df19bc4727

LogicAnalyzer of writeMsg: https://pasteboard.co/IMVfzCV.png

LogicAnalyzer of readMsg: https://pasteboard.co/IMVfHs1.png

Debug Logs

<27>[0;33mW (102718) spi: Using unaligned data may reduce transmission efficiency<27>[0m

Other items if possible

donghengqaz commented 4 years ago

It is hard to using the SPI driver directly, but you can refer to the new SPI example and the new SPI high level driver.

vargavik commented 3 years ago

Hi, this problem is related with a small error in the spi driver. When the data is unaligned, only the first byte is sent (or read), all the other bytes will be zero. Since your first byte is already zero, you will end up with 3 zeros. Check out #723.