cancel
Showing results for 
Search instead for 
Did you mean: 

3-wire SPI Receive - RXNE not working

BenMack99
Associate III

STM32G031 SPI in 3-wire half duplex mode. When reading data (BIDIMODE=1, BIDIOE=0), how can I tell when I have clocked in a complete u8/u16?

Neither RXNE or FRLVL appear to get updated until I stop the transaction.

I have it working by using a delay in the code:-

  CLEAR_BIT(SPI2->CR1, SPI_CR1_BIDIOE); // change to Bidirectional input mode
  delay_loop(40);
  SET_BIT(SPI2->CR1, SPI_CR1_BIDIOE);  // change back to Bidirectional output mode
  result = SPI2->DR;

but this seems a nasty cludge

I've RTFM and googled it, seems lots of people have the same problem. The STM32 in 3 wire receive mode just clocks away til you tell it to stop. Surely there's a better way?

Any suggestions gratefully received, thank you

13 REPLIES 13
AScha.3
Chief II

why not use: HAL_SPI_Receive_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, 1 ) , receive 1x then INT .

?

If you feel a post has answered your question, please click "Accept as Solution".
BenMack99
Associate III

Thanks Ascha, but I think the interrupt is generated by the RXNE event flag, so same problem (RXNE isn't generated while in input mode). I'm not using HAL, but if I get completely stuck on this I'll write a test project in HAL, just to double-check this.

AScha.3
Chief II

well, i never looked for RXNE event flag - 🙂

but i have SPI receive slave mode -> circular DMA running,

with 12 Mbit rate, using HAL . no problems (except cache management on H743 was some try and error, but this is not related to using HAL lib or not. )

If you feel a post has answered your question, please click "Accept as Solution".
S.Ma
Principal

So far, to have a real world working 3 wire SPI mode, I use 4 wire SPI mode and disable MOSI when reading data in. Most of my other attempt failed.

Thanks Ascha. I believe it works differently in slave mode, and I'm not using the DMA

Mmm yes, I've seen lots of posts to this effect, that's what is worrying me. My board is wired for 3-wire (only MOSI pin connected) and MISO pin is used elsewhere, so that's not really an option. Thanks though

In some cases, bitbanging the SPI may be a viable option.

JW

Chris21
Senior

On STM32L471, we have used SPI configured with direction SPI_DIRECTION_2LINES but configured the MISO pin as a regular GPIO (not set as Alternate, e.g., GPIO_AF5_SPI1) as we have no need to read from the connected SPI device.

RXNE operates as expected.

(This may be the same as S.Ma mentioned.)

Edit: This was acting as Master to write to the slave. You say you are reading from the device using MOSI?

Thanks JW, yes we have tried that, it works, but slow (we're running sysclk at 2MHz to save power). I wanted to use the SPI hardware and do it "properly". Just seems really weird that RXNE doesn't work in bidirectional rx mode. I would love someone from ST to confirm this