Posts: 11
Joined: Tue Oct 25, 2016 10:58 am

Strange Timing in SPI

Mon Sep 27, 2021 1:17 pm

I'm using the package "earlephilhower/arduino-pico", based on the pico SDK.
There I found a strange timing in SPI.cpp and analyzed it:
The "beginTransaction (...)" function takes 67 µs! The following 16-bit SPI transfer then takes 1.09 µs. Why is SPI slowed down so much?
I analyzed the function calls and probably identified the cause:

//---- in \rp2040\hardware\rp2040\1.9.4\libraries\SPI ----_
void SPIClassRP2040::beginTransaction(SPISettings settings)
utBegin2 = micros(); // My time measure start
spi_init(spi, spis.getClockFreq()); // -> the blocking function
utBegin2 = micros() - utBegin2; // My time measure end -> 67 µs
//---- in \rp2040\hardware\rp2040\1.9.4\pico-sdk\src\rp2_common\hardware_spi\spi.c ----
uint spi_init(spi_inst_t *spi, uint baudrate)
static inline void spi_unreset(spi_inst_t *spi)
unreset_block_wait(spi == spi0 ? RESETS_RESET_SPI0_BITS : RESETS_RESET_SPI1_BITS);
static inline void unreset_block_wait(uint32_t bits) // -> this is the cause (?)

Posts: 358
Joined: Mon Aug 19, 2019 9:56 pm

Re: Strange Timing in SPI

Mon Sep 27, 2021 3:03 pm

I am not familiar with this specific library, and it would help if you used 'code' tags round your code, but generally you only call the SPI inialisation once when your program starts, so it doesn't matter if it takes a while.

Are you calling spi_init before each SPI transfer? If so, I'm not surprised the code is slow.

Return to “SDK”