Open UKTailwind opened 2 years ago
I also encountered this on a Mode 3 device (Analog Devices accelerometer). Code above is also discussed here: https://forums.raspberrypi.com/viewtopic.php?t=336142
This looks related to #713. I submitted a pull request which should work for this also. (#1158)
Sounds like this was actually fixed in 1.5.0; please reopen otherwise
Hi @kilograham , I find the same issue with spi slave mode0. I use raspi 4 as spi master. I try the latest pico sdk master&develop branch but the issue still here. spi slave mode1 is fine.
Please give the SDK version in use?
Please give the SDK version in use?
I use the latest github version of the pico-sdk, both master and develop branch has the same issue. (I see the submit which @daveythacher mentioned above is merged into develop branch so I also try this branch )
Is this relevant? I would recommended filing SPI slave issues independently.
Overall I noticed ARM SPI is a little different. Also the SDK interface is mostly based on master mode. Not all SPI hardware features are available in the SDK. I view the SDK methods as helpers rather than a complete API.
Did you try this? (The order could matter.)
{
spi_init(SPI0, 4000000);
spi_set_slave(SPI0, true);
spi_set_format(SPI0, 8, SPI_CPOL_1, SPI_CPHA_1, SPI_MSB_FIRST);
}
Edit: Any objection to an enable method? That is the only thing spi_init actually does.
Yes, I just modify a little the pico-example/spi/spi_master_slave/spi_slave.c as below:
61 // Enable SPI 0 at 1 MHz and connect to GPIOs
62 spi_init(spi_default, 1000 * 1000);
63 spi_set_slave(spi_default, true);
64 spi_set_format(spi_default, 8, SPI_CPOL_0, SPI_CPHA_1, SPI_MSB_FIRST);
This is mode1 which work fine. But if I comment the line 64 or modify line 64 as
64 spi_set_format(spi_default, 8, SPI_CPOL_0, SPI_CPHA_0, SPI_MSB_FIRST);
The mode0 will not work.
I also check this but it just say it should be a sdk issue because the arduino-pico lib is just a encapsulation of the pico-sdk I think.
I haven't capture the waveform. But the mode0 behave no matter how many the master clk one time, the slave only return one correct byte one time in the first 8 bit clk position, then the slave return the next one correct byte when I use spi master to send again.
The correct behave of the spi slave example demo should be that it will return BUF_LEN
bytes in one time. That also what happen in mode1.
I am thinking this is a different issue. Please verify the CS line.
Corrected code in spi.h