cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_SPI_ReceiveIT not working on STM32F4

GVega.1
Associate

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

3 REPLIES 3

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
Principal III

> 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
Associate

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