Skip to content

Commit b440883

Browse files
committed
mimxrt: SPI: Set the TCR value returned by MasterBaudSetRate
without this, the baud rate could be wrong; in my testing, it was low by a factor of 2 when requesating baudrate=1_000_000 (1MHz). When passing the baudrate in to LPSPI_MasterInit, the setting is made automatically, but LPSPI_MAster_SetBaudRate just returns it via the out-parameter tcrPrescaleValue.
1 parent c81007a commit b440883

File tree

1 file changed

+2
-0
lines changed
  • ports/mimxrt10xx/common-hal/busio

1 file changed

+2
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
187187
LPSPI_Enable(self->spi, false);
188188
uint32_t tcrPrescaleValue;
189189
self->baudrate = LPSPI_MasterSetBaudRate(self->spi, config.baudRate, LPSPI_MASTER_CLK_FREQ, &tcrPrescaleValue);
190+
self->spi->TCR = (self->spi->TCR & ~LPSPI_TCR_PRESCALE_MASK) | LPSPI_TCR_PRESCALE(tcrPrescaleValue);
190191
LPSPI_Enable(self->spi, true);
191192

192193
claim_pin(self->clock->pin);
@@ -236,6 +237,7 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
236237
LPSPI_Enable(self->spi, false);
237238
uint32_t tcrPrescaleValue;
238239
self->baudrate = LPSPI_MasterSetBaudRate(self->spi, baudrate, LPSPI_MASTER_CLK_FREQ, &tcrPrescaleValue);
240+
self->spi->TCR = (self->spi->TCR & ~LPSPI_TCR_PRESCALE_MASK) | LPSPI_TCR_PRESCALE(tcrPrescaleValue);
239241
LPSPI_Enable(self->spi, true);
240242

241243
if ((polarity == common_hal_busio_spi_get_polarity(self)) &&

0 commit comments

Comments
 (0)