Skip to content
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

Change order of spi send and read #11

Closed
wants to merge 1 commit into from

Conversation

abjorck
Copy link

@abjorck abjorck commented Nov 27, 2020

Hey

I had trouble using SPI with my strip, constantly getting Overrun errors after a first successful write. After som trial and error guesswork, I made it work with the following changes to the lib.

Maybe it needs a config flag if it works differently for other hardware..
(I'm using stm32f4xx_hal on a STM32F401CEUx, the strip is just called "ws2812b led strip" (from "BTF-lighting"))

Copy link
Collaborator

@david-sawatzke david-sawatzke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why we didn't do this before is 'cause a small delay between both bytes (which will happen with this approach) messed up the previous implementation. Since #8 was merged, this might be less of an issue, but I'll need to test a few platforms to see if it makes a difference.

block!(self.spi.send(0))?;
self.spi.read().ok();
block!({
self.spi.send(0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.spi.send(0);
self.spi.send(0).ok();

@@ -101,8 +101,8 @@ where
block!({
// Some implementations (stm32f0xx-hal) want a matching read
// We don't want to block so we just hope it's ok this way
self.spi.read().ok();
self.spi.send(patterns[bits as usize])
self.spi.send(patterns[bits as usize]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this won't work properly.

block! will call send & read until read doesn't block any more, which means the same byte might be sent multiple times.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right, I'll be honest and say I don't understand any of the inner workings (not yet anyway). It just happened to work for my use case then ;)
..whereas the original code did not. I can try some more poking around, unless you have any hints/suggestions?

Btw, I've only found one other guy on the internet briefly describing the same issue as I'm having (before he gives up and uses the timer variant): https://albertskog.se/embedded-rust-timer-timeout-problem/

@david-sawatzke
Copy link
Collaborator

Hi, could you try if #12 works for you? Under the hood it should accomplish the same things as this PR, while being simpler

@abjorck
Copy link
Author

abjorck commented Nov 29, 2020

Hey.
The Overrun is gone, but it turned all leds white (except the first one slightly magenta?), whatever I send.

@david-sawatzke
Copy link
Collaborator

@abjorck I switched to a different approach, it now works for me on the stm32f1 which has a similar spi peripheral. Could you test it again?

@abjorck
Copy link
Author

abjorck commented Nov 29, 2020

yes! that does it :) thanks

@abjorck abjorck closed this Nov 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants