-
Notifications
You must be signed in to change notification settings - Fork 203
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
RX buffer overwrites the TX buffer in 'xfer2' #119
Comments
For better or worse, this is intentional- potentially since in-place modification of the TX/RX buffer isn't entirely uncommon in SPI communications. However I didn't write this code originally so I can only rationalize what's there in hindsight. If you supply your input as a You can see the relevant lines for conversion from a Lines 696 to 699 in a5d82b8
and back again here: Lines 737 to 741 in a5d82b8
Outside the context of a microcontroller this behavior is weird, surprising, very unpythonic, and somewhat conservative given I suspect most systems running this code could spare some memory for separate TX/RX buffers in all cases.... but it's a widely used library and I'm not convinced it's worth fixing when you can toss a Or, in your case, just use: tx1 = (0xCA, 0xFE, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff,
0xff, 0x00, 0x00, 0xff, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00,
0x00) |
This is a duplicate of #61 Though, having spent a good amount of time debugging due to this behavior, I disagree with the assertion this should be considered a feature and not a bug. While the input list to If you really wanted to copy data to and from SPI without allocating the additional memory, you could use a While converting the input to a tuple gets the desired behavior, I think this is not a particularly elegant solution in a duck-typed language, where precise typing should not cause a behavioral change. Having read the code, I'm still not sure how the code ends up correctly handling a bytes object. I think this behavior needs to be fixed, or at least enabled by an Edit: Just wanted to say this library has worked fine overall. Don't want to come off as too negative. |
Hi, I'm setting up a comms link between an
STM32F407
MCU and thePi3B+
. The code shown below works but when the data is printed out, it looks like the RX buffer overwrites the TX one. How do I stop that? The console output is shown below the code.The console output looks like this,
The text was updated successfully, but these errors were encountered: