cancel
Showing results for 
Search instead for 
Did you mean: 

What causes SPI transmit to timeout on STM32WLE5 and how can I fix this?

charles23
Associate III

I have used the Device Configuration Tool to set up an SPI1 peripheral on PB3, PB4, PB5 with manual control of the chip select, and polled (not interrupt driven). Writes to SPI slave chips registers execute without error, but register reads give a HAL_TIMEOUT error in HAL_SPI_TransmitReceive() because the RXNE flag (data in fifo) is never set.

The clock is enabled to the SPI and I can read/write SPI registers. CR1, CR2, SR values look sensible. I have not yet tried different pins, or SPI2.

Has this been tried, and can someone point to a known working example?

Unfortunately, the SPI examples that ST provide don't build (at least for me, with Eclipse), but in any event they are special cases: two processor chips connected, one as master and one as slave, with no chip select. A real example (e.g. talkig to an accelerometer chip) is missing.

1 ACCEPTED SOLUTION

Accepted Solutions
charles23
Associate III

My mistake. When I moved some pins to GPIOB I failed to enable Port B clocks: __HAL_RCC_GPIOB_CLK_ENABLE();

View solution in original post

2 REPLIES 2
charles23
Associate III

I have spent a bunch more time on this problem. I have tried all sorts of combinations of pins for SCK, MISO, MOSI, and both SPI1 and SPI2 peripherals. Consistently I see that if the SCK is on a Port A pin the RXNE flag behaves as expected, but if SCK is on a Port B pin, RXNE is never set so HAL_SPI_Receive() fails with HAL_TIMEOUT. Example: SCK=PA1, MISO=PB4, MOSI=PB5 works. Change SCK to PB3 fails.

As far as I can tell the alternate functions on the GPIO pins are correctly configured. The SPI control and status registers contain expected values (except RXNE). Clocks are enabled to the SPI peripheral...

I would be very grateful to know if anyone can repeat this, and to know if anyone has had SPI working with a port B pin for SCK.

charles23
Associate III

My mistake. When I moved some pins to GPIOB I failed to enable Port B clocks: __HAL_RCC_GPIOB_CLK_ENABLE();