-
-
Notifications
You must be signed in to change notification settings - Fork 86
Incorrect transfer of SPI packets with BitOrder LSBFIRST when count is >= 4 #244
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
ping @RudolphRiedel |
I took a brief look at this and I have an idea what is causing it and how to fix it. |
I can confirm the issue, looks like so far nobody tried to use LSBFIRST with buffer transfers. I fixed it here and this is how I currently have it up and running, MSBFIRST: Note, I am using two decoders to not switch between readings, the top is configured for LSBFIRST, the bottom for MSBFIRST. I changed line 447 of SPI.cpp from to: This one does a byte-swap for the 32 bit transfers that happen as optimization when doing buffered transfers. And for the background, while I was happy to see that Renesas finally released new versions of the datasheet and user manual back in September 2023, the user-manual is at Rev.1.10 now, for the SPI they only fixed the issue that in register SPDCR the bit SPBYT was not documented. |
Thank you for this quick & efficient analysis @RudolphRiedel ! Will continue to test against real device. BTW, any reason to use |
No, I just wanted to inverse the value after I saw that SPCMD_b[0].LSBF needed a 1 to activate LSBFIRST. I just checked, !bit_order does also work. Now I am not sure what the most appropriate variant is, especially in the C++ context. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Thanks for your report @gentilkiwi and to @RudolphRiedel for your pull request. Although it is very interesting, I would appreciate it if we can keep this discussion tightly focused on the original subject matter. Discussion of @gentilkiwi's project is off topic for this issue and for this repository. You are welcome to continue the conversations on Arduino Forum: |
- fix for #244, byte-order wrong for LSBFIRST buffer transfers
When using
void transfer(void *buf, size_t count);
of the SPI Class, with BitOrder LSBFIRST, group of 4 bytes are reversed.It seems to be here because of the optimization to handle arrays 4 bytes by 4 bytes (then byte(s) left), but it reverse the whole DWORD, not only bits of the byte.
Captures
MSBFIRST
- OK(left is using
void transfer(void *buf, size_t count);
right is multipletransfer(uint8_t data);
)LSBFIRST
- KO(left is using
void transfer(void *buf, size_t count);
right is multiplestransfer(uint8_t data);
)Remarks:
R3
, only onR4
;LSBFIRST
is not very common, butNXP PN532
is using it by eg ;The text was updated successfully, but these errors were encountered: