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.


  1. SPI NSS PA4
  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); 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?

Thank you very much.

  • 3
    \$\begingroup\$ The HAL _IT functions don't do what one would think they do, or probably want. Most end up writing their own solution. \$\endgroup\$ – Chris Stratton Dec 13 '19 at 7:48
  • \$\begingroup\$ When I did some test with UART IT functions it also did not work … I switched to DMA and was working (after some debugging). So if you want to use the IT function just as 'in between step' to use DMA, I would say, skip IT and move to DMA. \$\endgroup\$ – Michel Keijzers Dec 13 '19 at 9:52
  • \$\begingroup\$ @ChrisStratton True … I moved from IT to DMA (see above comment) \$\endgroup\$ – Michel Keijzers Dec 13 '19 at 9:53
  • \$\begingroup\$ Thanks for the input. I'll definitely try this out! \$\endgroup\$ – DigiJockforLife Dec 13 '19 at 9:55
  • \$\begingroup\$ To be clear, I was recommending more sensible interrupt code. DMA may be possible but is not always a great fit for needs. An SPI read from an MCU imposes some tricky timing, though if you control both ends then for a read operations you could send the register address then wait a bit before reading the response data. \$\endgroup\$ – Chris Stratton Dec 13 '19 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.