cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f042k6 - SPI and UART not working together in Non-Blocking Mode.

SNaga.1
Associate

I am using an stm32f042k6 - Nucleo Board. I am using SPI and UART in non - blocking mode initialized through Cube-MX. I am trying to interface an RPI through SPI1 and a BMS through USART1.

SPI1 is configured as a Full-Duplex Slave. USART1 is configured to be asynchronous. Global interrupts are enabled for both.

Pinout:

  1. SPI NSS PA4
  2. SPI SCLK PA5
  3. SPI MISO PA6
  4. SPI MOSI PA7
  5. UART TX PB6
  6. UART RX PB7

The issue is that as soon as I call 

HAL_SPI_Receive_IT();

in the User Code 2 Section, both peripherals stop working.

In SPI, SCLK, NSS and MOSI work fine. The callback functions are triggered fine and the stm reads the incoming data but MISO is always high. As a result the Rpi keeps getting 0xff. UART stops working completely with the RX remaining high.

I have tried using UART in blocking mode along with SPI in interrupt mode as well but the same issue happens. I can't use SPI in blocking mode because data from the Rpi can come at any time.

Note that both peripherals work fine separately be it in Blocking or Non-Blocking mode.

What I have tried so far:

  1. Changed priorities of interrupts setting SPI to higher, lower or equal to UART.
  2. Changed the order in which each peripheral is initialized.
  3. Removed the Rpi connections. SPI Interrupts wont occur but USART still fails.
  4. Changed pins to different ones for each peripheral in CUBE-MX.
  5. Enabled I2C interfaced with an IMU to see if it also fails when other peripherals are enabled. I2C works fine in all cases.
  6. Placed a UART state check before the first transmit with SPI enabled. 
while(HAL_UART_GetState(&huart1) != HAL_UART_STATE_READY);

It never leaves the loop. Rxstate is 34. gstate is 32.

I can't share the code because this is work related. I hope you guys can point me in the right direction to figure this out. I am not sure what to try next? Is this a bug with CubeMX?

Thank you very much.

1 REPLY 1
cihadkck
Associate II

Hello, did you find a solution for your problem ? I am struggling with same problem for 3-4 days and deadline is getting closer. I will be very happy if you share the solution that you applied for your project.