-
Notifications
You must be signed in to change notification settings - Fork 7.2k
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
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
[TW#16843] spi_slave.c #1346
Comments
Can I ask how you figured out this is incorrect? Does it not match other documentation, or do you have issues using mode 2 or 3 in practice? |
The driver code does not match
It also has hardcoded nodelay=true; esp-idf/components/driver/spi_slave.c Line 148 in eb659e4
|
There is also an ambiguous assignment esp-idf/components/driver/spi_slave.c Line 144 in eb659e4
|
It seems more likely the table row SPI_CK_I_EDGE is wrong and values should be inverted bc that would match all code. But nodelay should be false to match table. sync_reset is not ambiguous, it is set and then cleared intentionally. |
The
I see |
Well if table is right then all values of ck_i_edge should be inverted in code. But not swap 2&3. |
I think the code should also be setting
|
I checked the MISO for a mode3 spi-slave with an oscilloscope. To fix the timing I needed to change spihost[host]->hw->ctrl2.mosi_delay_mode to 1. |
As far as I know, the table given by the Technical Reference Manual can produce correct timing. But sometimes it does not work well with DMA, so there're 2 modes with different values with the TRM. Please try:
I prepare to refactor the code to make the workaround more obviously and influence smaller region. |
The code for setting the hardware according to the 'mode' parameter is incorrect. mode == 2 and mode == 3 should swap (see spi_master.c)
if (slave_config->mode == 0) {
spihost[host]->hw->pin.ck_idle_edge = 0;
spihost[host]->hw->user.ck_i_edge = 1;
spihost[host]->hw->ctrl2.miso_delay_mode = nodelay ? 0 : 2;
} else if (slave_config->mode == 1) {
spihost[host]->hw->pin.ck_idle_edge = 0;
spihost[host]->hw->user.ck_i_edge = 0;
spihost[host]->hw->ctrl2.miso_delay_mode = nodelay ? 0 : 1;
} else if (slave_config->mode == 2) {
spihost[host]->hw->pin.ck_idle_edge = 1;
spihost[host]->hw->user.ck_i_edge = 0;
spihost[host]->hw->ctrl2.miso_delay_mode = nodelay ? 0 : 1;
} else if (slave_config->mode == 3) {
spihost[host]->hw->pin.ck_idle_edge = 1;
spihost[host]->hw->user.ck_i_edge = 1;
spihost[host]->hw->ctrl2.miso_delay_mode = nodelay ? 0 : 2;
}
The text was updated successfully, but these errors were encountered: