Skip to main content
GVega.1
Associate
February 1, 2021
Question

HAL_SPI_ReceiveIT not working on STM32F4

  • February 1, 2021
  • 3 replies
  • 2326 views

I am working on a project where I am using two boards to communicate via SPI. The master board (TMS320F28377S) is sending data successfully via SPI

Now, my receiver board is running on a STM32F439 processor, I'm relatively new to this micro. I configured it as a a Receiver Only using CubeMX, rest of settings are show below,

hspi2.Instance = SPI2;

hspi2.Init.Mode = SPI_MODE_SLAVE;

hspi2.Init.Direction = SPI_DIRECTION_2LINES_RXONLY;

hspi2.Init.DataSize = SPI_DATASIZE_8BIT;

hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;

hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;

hspi2.Init.NSS = SPI_NSS_HARD_INPUT; //??

//hspi2.Init.NSS = SPI_NSS_SOFT;

hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;

hspi2.Init.TIMode = SPI_TIMODE_DISABLE;

hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;

hspi2.Init.CRCPolynomial = 10;

Once the code is ready for receiving, I call the following,

if(HAL_SPI_Receive_IT(&hspi2, (uint8_t *)GEU_RX_Buffer, 2) != HAL_OK)

{

Error_Handler();

}

while(1){}

I'm placing a breakpoint in the, setting a variable and calling receive interrupt again

void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)

{

Sys_Mode = DIAGNOSTIC_MODE;

// Trigger interrupt again to keep receiving datas

HAL_SPI_Receive_IT(&hspi2, (uint8_t *)rx_buffer, 2);

}

When I make a transfer from master, I'm watching rx_buffer variable and no data is being received, also RXNE flag is not being set.

Is there something I'm missing here? All I want is to be able to receive data on another platform in non-blocking mode using interrupt. Also, should I have the NSS pin physically connected to an I/0 on the receiver micro?

Your help is appreciated in advance.

Thank you.

Gil

This topic has been closed for replies.

3 replies

waclawek.jan
Super User
February 1, 2021

Try polled (blocking) SPI Rx first.

If works, in the interrupt-driven code check if interrupt is enabled both in SPI and NVIC, and if address of interrupt routine is properly inserted to interrupt vector table.

If does not work, read out and check SPI and relevant GPIO registers content.

JW

KnarfB
Super User
February 1, 2021

> Also, should I have the NSS pin physically connected

As you init

hspi2.Init.NSS = SPI_NSS_HARD_INPUT;

The STM32F4 NSS pin must be low to receive something. Either the master does that, or you pull it permanently low, or you use SPI_NSS_SOFT and set SSM and clear SSI bits in SPI_CR1 register.

GVega.1
GVega.1Author
Associate
February 2, 2021

Thank you for the feedback guys, they were helpful. I tried both approaches and after troubleshooting, I realized the NSS pin was pulled out wrong on my custom hardware.

Best,

Gil