-
Notifications
You must be signed in to change notification settings - Fork 13.3k
SPI.transfer using global byte array doesn't send correct data #5670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm not at my bench, but the code and HW itself can't differentiate between a heap allocated bunch of RAM or a global allocation (i.e. just above the heap in the same RAM). It's all just some bytes in the 8-bit addressable RAM space. There may be some kind of hidden state, though, where it fails the first run and passes the 2nd (i.e. HW register not set up right until one pass, etc.). If it's easy, have you tried reversing the order of your test? Is it always the 1st run or is it always the heap run, etc.? |
The test sketch, its driven by the developer using the Serial Monitor, so you can have it call what ever order you want and as often as you want with what ever delays between the sends it takes you type T and then enter, or even TTTTT and then enter (runs five in row quickly). |
Also just tried t, then t, then t, and guess what, the first is sent correctly, the others fail. So ignoring the global completely causes an issue. Also note, I extended the data to full 8 bytes to see if this was causing an issue; it does not effect the outcome. |
It will take a while before I get a chance to run your sketch, but I'll give it a go as soon as I can. SPI hasn't been touched in ~6months per the git logs, and I've personally been using it lots while developing SDFS (and anyone using the existing SD lib would also be using it), so I'm pretty sure basic SPI functionality is OK. I'm not an SPI expert (8266 or otherwise), but I have the feeling there's some issue with the MCVE code here and need to sit down and look at it for a bit. Breaking basic functionality normally gets yells from users fast, and it'd be broken 6 months ago given the logs... |
Same issue as #5762? |
User error. SPI.transfer will overwrite the out buffer with what is received. |
Basic Infos
Platform
Settings in IDE
Problem Description
Using a global array passed into SPI.transfer sends all 0xFF. If the same array is copied into a buffer and then that buffer is used, it is correctly sent.
To reproduce:
run the following sketch with the Serial Monitor open and a logic probe attached to the CLK, MOSI, and SS pins (SS pin is useful to set the probe to trigger on; but otherwise really isn't needed).
Set to probe to capture, then in the Serial Monitor type upper case T and hit enter to send. This will cause the sketch to call SPI.transfer with the global buffer. The results will show that all 0xFF were sent.

Set the probe to capture again, then in the Serial Monitor type lower case t and hit enter to send. This will cause the sketch to call SPI.transfer with a copy of the global buffer. The results will show that the correct data was sent.

In the debug output, you will also see the addresses of the global buffer and copied buffer. These were
global = 0x3FFE84E4
copy = 0x3FFEF6E4
MCVE Sketch
The text was updated successfully, but these errors were encountered: