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.
- SPI NSS PA4
- SPI SCLK PA5
- SPI MISO PA6
- SPI MOSI PA7
- UART TX PB6
- 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:
- Changed priorities of interrupts setting SPI to higher, lower or equal to UART.
- Changed the order in which each peripheral is initialized.
- Removed the Rpi connections. SPI Interrupts wont occur but USART still fails.
- Changed pins to different ones for each peripheral in CUBE-MX.
- Enabled I2C interfaced with an IMU to see if it also fails when other peripherals are enabled. I2C works fine in all cases.
- 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.