esp8266 / esp8266/Arduino

SPISlave.h Missing packets and all packets after first 32 byte packet are received incorrectly

Open
#8,217 10 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
16.7k
Forks
13.1k
PR merge metrics
No merged PRs in 30d

Description

### Basic Infos

- [x] This issue complies with the [issue POLICY doc](https://github.com/esp8266/Arduino/blob/master/POLICY.md).
- [x] I have read the documentation at [readthedocs](https://arduino-esp8266.readthedocs.io/en/latest) and the issue is not addressed there.
- [x] I have tested that the issue is present in current master branch (aka latest git).
- [x] I have searched the issue tracker for a similar issue.
- [x] If there is a stack dump, I have decoded it.
- [x] I have filled out all fields below.

#### Platform

- Hardware: Ai Thinker ESP-12F
- Core Version: 3.0.1
- Development Env: Arduino IDE
- Operating System: Windows 10

### Settings in IDE

- Module: [Generic ESP8266 Module]
- Flash Mode: unknown
- Flash Size: [4MB]
- lwip Variant: [v1.4|v2 Lower Memory|Higher Bandwidth]
- Reset Method: [ck|nodemcu]
- Flash Frequency: [40Mhz]
- CPU Frequency: [80Mhz|160MHz]
- Upload Using: [OTA]
- Upload Speed: [115200|other] (serial upload only)

### Problem Description

I am using the SPIslave.h library to receive data from a board developed by another company. the board is setup as the master and transmits 2000 SPI packets to the ESP8266 board that is configured as a slave. Each packet is 32 bytes long and there is a 20ms delay between each packet. When receiving data the ESP8266 board only reads in just under 1000 packets. When the ESP8266 board receives the data it correctly receives the first packet of 32 bytes correctly but all subsequent packets are read incorrectly. I have set the sketch up to print out the first 5 packets to the Serial monitor and looks like this:

78,0,0,255,229,244,0,127,248,128,112,7,255,192,12,255,129,10,0,64,2,128,196,4,0,224,2,255,75,246,0,135,
204,0,128,2,128,165,248,0,64,0,255,192,12,0,191,255,0,248,11,255,64,8,255,86,12,0,133,255,75,246,0,135,
204,0,0,128,12,128,228,7,255,192,0,255,187,8,0,127,248,128,250,75,255,86,255,86,12,0,133,255,75,246,0,135,
204,0,0,12,128,226,111,255,64,8,255,18,98,0,63,255,0,63,163,255,63,245,127,15,173,255,150,255,75,246,0,135,
204,0,127,251,127,113,167,255,0,12,128,130,160,0,224,10,255,124,174,0,255,246,128,119,36,0,83,255,75,246,0,135

The first packet in this output matches what I see on an oscilloscope but the rest don't match the scope output. Also the last 5 bytes of all subsequent packets are always the same and i have no idea why.

I have included the SPISlave.onData function below but let me know if it would be worth including the full sketch. i based the function off the SPISlave example. the SPISlave.onData function is set up to add the data received over SPI into a buffer. I have also had an issue of the first 2 bytes of every packet being empty but i have managed to work around this.

### [MCVE](https://stackoverflow.com/help/mcve) Sketch

```cpp

SPISlave.onData([](uint8_t * data, size_t len)
{



(void) len;

if(count==0)
{
buff[count] = 0x4e; // this sets the start packet byte to the correct value to compensate for the missing first 2 bytes
count++;
}
else
{
buff[count] = 0xcc; // this sets the start packet byte to the correct value to compensate for the missing first 2 bytes
count++;
}
buff[count] = 0;
count++;
for(int i = 0; i<(len-2); i++) //loop to add the data to the buffer
{
buff[count] = data[i];
count++;

}
packet_count++; //this is just used to count the number of packets recieved

;

});
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.