-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Update hspi_slave.c #5489
Update hspi_slave.c #5489
Conversation
I found that SPI communication did not work due te a wrong timing of the MISO signal with respect to SCK. With slower processores like Arduino UNO (and a small delay of sck due to th level converter) it works, but with a faster Arduino DUE (without converter) it did not. Together with Jiri Bilek I found that MISODM_S has to be set. In the documentation for the ESP32 (should have a very similar SPI interface) I found that also MOSIDN_S should be set in SPI1C2. The MISO timing is correct, I tested it for a clock of 4 MHZ and 320 kHz. With experiments I found that also the timing of MOSI is robust. Neither a delay of 70 ns in SCK nor in MOSI did disturb the communication. Some oscillograms are here: http://homepage.o2mail.de/g.ackermann/hspi_slave.htm Jiri Bilek added the ICACHE_RAM_ATTR to the function hspi_slave_setStatus() because this function may be indirect called from an interrupt handler.
@GuaAck @JiriBilek thank you for this, timing issues are difficult to find and resolve. |
libraries/SPISlave/src/hspi_slave.c
Outdated
@@ -114,7 +114,7 @@ void hspi_slave_end() | |||
SPI1P = B110; | |||
} | |||
|
|||
void hspi_slave_setStatus(uint32_t status) | |||
void ICACHE_RAM_ATTR hspi_slave_setStatus(uint32_t status) // GuaAck. 30.10.2018 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You provided an explanation for why this function should have the decorator. I suggest replacing the comment with that.
Also, I suggest inline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, please change the comment to add the explanation.
Hi, there is a problem with this PR. |
|
||
void hspi_slave_end() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you delete hspi_slave_end function?
@@ -0,0 +1 @@ | |||
Dummy, should be deleted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope you can delete the file in your repository and the deletion is then propagated to master.
@Makuna is this PR relevant to your SPI testing? |
@JiriBilek @GuaAck what is the status here? I see a deleted function and an unneeded dummy file. |
This timing relationship of the data pulse to clock pulse is defined by the SPI mode. See WikiPedia SPI. |
I have nothing to do with deleted functions and dummy files, Perhaps I did siomething by accident, Ia am very beginner in github. With my changes, the SPI communication in my project works reliable for different clock rates. For me the matter is closed. Me and Jiri provided in github a I lot of notes and diagrams with measured wave forms . The owner of hspi_slave has to decide what to do. I am open for any technical questions, |
@GuaAck @JiriBilek What SPI mode are your changes setting the SPI Slave to? When you tested with a SPI Master, did you test all the modes? |
Yes, I tested the original hspi_slave with all modes (selected in the master), all failed. The changed hspi_slave is only valid for mode 0. I found no switch to select the mode and mode 0 seems to be most common. To remember: The problem came up, when I changed over from my UNO to the very much faster DUE. Then I found the incorrect timing. Best regards |
Closing in favor of #6022 . |
I found that SPI communication did not work due te a wrong timing of the MISO signal with respect to SCK. With slower processores like Arduino UNO (and a small delay of sck due to th level converter) it works, but with a faster Arduino DUE (without converter) it did not. Together with Jiri Bilek I found that MISODM_S has to be set. In the documentation for the ESP32 (should have a very similar SPI interface) I found that also MOSIDN_S should be set in SPI1C2. The MISO timing is correct, I tested it for a clock of 4 MHZ and 320 kHz. With experiments I found that also the timing of MOSI is robust. Neither a delay of 70 ns in SCK nor in MOSI did disturb the communication. Some oscillograms are here: http://homepage.o2mail.de/g.ackermann/ESP8266.htm
Jiri Bilek added the ICACHE_RAM_ATTR to the function hspi_slave_setStatus() because this function may be indirect called from an interrupt handler.