-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Calling SPI.writeBytes or SPI.transferBytes after calling a SPI.transfer doesn't send correct data #5672
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
@earlephilhower nope, two different problems. This one maybe resolved by your comment above, will test that now. |
@earlephilhower The buffers are already aligned, extended the data to be 8 bytes and the problem is still reproduceable. So this remains active (updating the sketch above so this detail can be ignored). |
Agreed. It bit me when using the new SDFS and SDFat library (greiman/SdFat#125). Our bug is in #4967. For me, sdfat occasionally uses misaligned buffers which resulted in HW exceptions. |
@earlephilhower Looking at the code for transferBytes_, it does seem to assume the data is in 4 byte lengths. This seems all wrong as the size of data is device specific and may NEVER be 4 byte rounded lengths and sending extra data can mess things up. But again, this is not the problem this issue is tracking. |
OK, this will be closed shortly. This is due to user error. transfer will store the received data back into the buffer that was used to send; thus overwriting the original data with 0xFF. |
Confirmed, issue was the API overwrites the out data buffer as documented. User error. |
Basic Infos
Platform
Settings in IDE
Problem Description
(updated with new findings)
Calling SPI.writeBytes or SPI.transferBytes after calling a SPI.transfer doesn't send correct data and just sends 0xFF. Calling before SPI.transfer works correctly.
Further, once SPI.transferBytes is called and wrong data is sent, SPI.transfer may also fail.
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 lower case b and hit enter to send. This will cause the sketch to call SPI.transferBytes with a copy of the global buffer. The results will show that correct data was sent.

Set to probe to capture, 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 correct was sent.

Set to probe to capture, then in the Serial Monitor type lower case b and hit enter to send. This will cause the sketch to call SPI.transferBytes with a copy of 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 w and hit enter to send. This will cause the sketch to call SPI.writeBytes with a copy of the global buffer. The results will show that all 0xFF were sent.
(same as the above, so I didn't include another image)
The buffer addresses are as follows, these instructions are using the copied buffer.
global = 0x3FFE84EC
copied = 0x3FFEF6E4
MCVE Sketch
Below is a testing sketch, it exposes the ability for the Serial Monitor to trigger different actions, including ones that will test that your test rig is setup correctly (use lower case t).
The text was updated successfully, but these errors were encountered: