SPI blocked by a flag

Post here first, or if you can't find a relevant section!
Post Reply
gauthierDCC
Posts: 6
Joined: Tue Oct 10, 2023 2:50 pm

SPI blocked by a flag

Post by gauthierDCC »

Hi all,
For I project, I would like to switch from an Arduino Nano to a Nucleo-G431KB.
I use a pressure sensor HRCDRRN100MDSA3 from Honeywell, with the HoneywellTruStabilitySPI library.

Using the Arduino, I have no problem to run the exemple code.

But I can't made it work with my Nucleo, even with adjusting the SPI pin.

I tried to use the debugger to understand where the problem is, but it's to complexe for me to understand :lol:
All I know is that I'm blocked in a infinite loop:
In spi_com.c, at line 546

Code: Select all

 while (!LL_SPI_IsActiveFlag_TXE(_SPI));
I have no clue of what that flag is.

Do you have any idea?
Thanks

Full test sketch

Code: Select all

/*
 * PressureSensorTest
 *
 * Fetch and print values from a Honeywell 
 * TruStability HSC Pressure Sensor over SPI
 * 
 * The sensor values used in this demo are 
 * for a -15 to 15 psi gauge pressure sensor. 
 * 
 */

#include <HoneywellTruStabilitySPI.h>

#define SLAVE_SELECT_PIN PA11 // D10 on Arduino
TruStabilityPressureSensor sensor( SLAVE_SELECT_PIN, -100.0, 100.0 );


void setup() {
  Serial.begin(115200); // start Serial communication
  SPI.setMOSI(PB5);       // D11 on Arduino
  SPI.setMISO(PB4);       // D12 on Arduino
  SPI.setSCLK(PB3);       // D13 on Arduino
  SPI.begin();            // start SPI communication
  sensor.begin();         // run sensor initialization
}

void loop() {

  // the sensor returns 0 when new data is ready
  if( sensor.readSensor() == 0 ) {
    Serial.print( "temp [C]: " );
    Serial.print( sensor.temperature() );
    Serial.print( "\t pressure [psi]: " );
    Serial.println( sensor.pressure() );
  }
  
  delay( 100 ); // Slow down sampling to 10 Hz. This is just a test.

}
gauthierDCC
Posts: 6
Joined: Tue Oct 10, 2023 2:50 pm

Re: SPI blocked by a flag

Post by gauthierDCC »

On the STM32G4 Nulceo user manual, it's written that by default, T_SWO is connected to PB3 (SPI1_CLK). https://www.st.com/resource/en/user_man ... ronics.pdf p.17
Could that T_SWO interfere with the SPI?
If I remove the solder bridge (SB4), would I still have access to the debugging functions?

I also tried with PA5 as SCLK and PA6 as MISO (my sensor does not use MOSI), without success.
I'm not blocked in the sensor.readSensor() function, but data are fully corrupted (temps of 150°C or -50°C)
gauthierDCC
Posts: 6
Joined: Tue Oct 10, 2023 2:50 pm

Re: SPI blocked by a flag

Post by gauthierDCC »

I've seen in an errata from ST that my µC is subjected to problem with the BSY bit in the SPI protocol (note that I don't really understand what it means :D )
2.13 SPI
2.13.1 BSY bit may stay high when SPI is disabled
Description
The BSY flag may remain high upon disabling the SPI while operating in:
• master transmit mode and the TXE flag is low (data register full).
• master receive-only mode (simplex receive or half-duplex bidirectional receive phase) and an SCK strobing
edge has not occurred since the transition of the RXNE flag from low to high.
• slave mode and NSS signal is removed during the communication.
Workaround
When the SPI operates in:
• master transmit mode, disable the SPI when TXE = 1 and BSY = 0.
• master receive-only mode, ignore the BSY flag.
• slave mode, do not remove the NSS signal during the communication
I operate in maser receive-only mode, now I have to find a way to ignore that flag (does it mean modifying the library?)
gauthierDCC
Posts: 6
Joined: Tue Oct 10, 2023 2:50 pm

Re: SPI blocked by a flag

Post by gauthierDCC »

I think I went on a wrong direction looking at the BSY flag...
Looking at the oscilloscope, I have the following result with the Arduino:
Using the Arduino
Using the Arduino
SDS00012.png (25.49 KiB) Viewed 549 times
And I have that using the STM32:
Using the STM32, without initialization
Using the STM32, without initialization
SDS00010.png (21.2 KiB) Viewed 549 times
As they suggest here, I might need to reset the SPI pin before using it: https://electronics.stackexchange.com/q ... rms-poorly
But I have no idea of how to program directly with the registers (I tried copy/past of the given code, but "CRL" is not recognized)
So I tried initializing this way:

Code: Select all

  pinMode(SLAVE_SELECT_PIN, OUTPUT);
  pinMode(PB4, INPUT);
  pinMode(PB3, OUTPUT);
Not working...
But it does change something:
Using the STM32, withinitialization
Using the STM32, withinitialization
SDS00013.png (23.1 KiB) Viewed 549 times
Post Reply

Return to “General discussion”