Skip to content

Commit 96fc85c

Browse files
authored
Merge pull request adafruit#7229 from dhalbert/rp2040-spi-mode-3
RP2040: have clock start high when SPI polarity high
2 parents c837ac4 + 1611cf9 commit 96fc85c

File tree

1 file changed

+9
-0
lines changed
  • ports/raspberrypi/common-hal/busio

1 file changed

+9
-0
lines changed

ports/raspberrypi/common-hal/busio/SPI.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
151151

152152
spi_set_format(self->peripheral, bits, polarity, phase, SPI_MSB_FIRST);
153153

154+
// Workaround to start with clock line high if polarity=1. The hw SPI peripheral does not do this
155+
// automatically. See https://github.com/raspberrypi/pico-sdk/issues/868 and
156+
// https://forums.raspberrypi.com/viewtopic.php?t=336142
157+
// TODO: scheduled to be be fixed in pico-sdk 1.5.0.
158+
if (polarity) {
159+
hw_clear_bits(&spi_get_hw(self->peripheral)->cr1, SPI_SSPCR1_SSE_BITS); // disable the SPI
160+
hw_set_bits(&spi_get_hw(self->peripheral)->cr1, SPI_SSPCR1_SSE_BITS); // re-enable the SPI
161+
}
162+
154163
self->polarity = polarity;
155164
self->phase = phase;
156165
self->bits = bits;

0 commit comments

Comments
 (0)