cancel
Showing results for 
Search instead for 
Did you mean: 

SPI constantly sending Clock and OxFF over MOSI after enabling SPI in half duplex.

milindmishra87
Associate

Hi,

I have been trying to communicate with an SPI peripheral (NOR Flash). I want to use SPI in half duplex mode. The problem is that as soon as enable the SPI peripheral I see SPI constantly sending OxFF over MOSI even though I have not written anything on the SPI DR register.

Pasting the screenshot of the Salea LA

Screenshot 2026-01-31 134429.png

Below is the simple SPI TX code

 
void SPI_SendData(uint8_t* Txdata, uint32_t len) {
    if((spi_dev->SR & TXE_FLAG)) {
      spi_dev->DR = *(uint8_t*)Txdata;
      Txdata++;
      len--;
    }

  if(!(spi_dev->CR1 & SPI_EN)) {
    spi_dev->CR1 |= SPI_EN;
  }
  while(len > 0) {
    // Wait for TXE FLAG
    if((spi_dev->SR & TXE_FLAG)) {
      spi_dev->DR = *(uint8_t*)Txdata;
      Txdata++;
      len--;
    }
  }
}

Edited to apply source code formatting - please see How to insert source code for future reference.

2 REPLIES 2
TDK
Super User

In half duplex mode, you need to toggle between sending and receiving. When receiving, it is clocked constantly as shown in your logic analyzer traces.

If you feel a post has answered your question, please click "Accept as Solution".
FBL
ST Employee

Hello @milindmishra87 

The 0xFFs and clock activity after enabling SPI is normal behavior of the SPI master.. /CS does not stop the SPI peripheral from toggling SCK/MOSI; it only tells the flash when to pay attention.

To be sure there is no issue with your NOR flash, I recommend verifying the CPOL/CPHA, and half‑duplex direction bits and sharing your SPI register dump just before starting the transfer.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.




Best regards,
FBL