cancel
Showing results for 
Search instead for 
Did you mean: 

STM32l431 spi slave interrupt not work

JSanz.1
Associate III

hi all,

I need to use a SPI1 as slave and receive character by character via interrupt and not works.

I have placed a break point to "void NMI_Handler(void)" and "void SPI1_IRQHandler(void)" but never fire into the functions.

static void MX_SPI1_Init(void)

{

 /* USER CODE BEGIN SPI1_Init 0 */

 /* USER CODE END SPI1_Init 0 */

 /* USER CODE BEGIN SPI1_Init 1 */

 /* USER CODE END SPI1_Init 1 */

 /* SPI1 parameter configuration*/

 hspi1.Instance = SPI1;

 hspi1.Init.Mode = SPI_MODE_SLAVE;

 hspi1.Init.Direction = SPI_DIRECTION_2LINES;

 hspi1.Init.DataSize = SPI_DATASIZE_8BIT;

 hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;

 hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;

 hspi1.Init.NSS = SPI_NSS_HARD_INPUT;

 hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;

 hspi1.Init.TIMode = SPI_TIMODE_DISABLE;

 hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;

 hspi1.Init.CRCPolynomial = 7;

 hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;

 hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;

 if (HAL_SPI_Init(&hspi1) != HAL_OK)

 {

  Error_Handler();

 }

 /* USER CODE BEGIN SPI1_Init 2 */

 /* USER CODE END SPI1_Init 2 */

}

and just before to enter into "main()"

HAL_SPI_Receive_IT(&hspi1, (uint8_t*)buffer, 1);

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
JSanz.1
Associate III

hi JW,

thanks for your help, finally I got the SPI running via interrupt.

I restart from scratch a new project and configuring the SPI receiver with global interrupt ant SPI transmitter via DMA.

By setting "HAL_SPI_Receive_IT" as minimal spected length.

It seems it's begining to work.

Regards

View solution in original post

6 REPLIES 6
TDK
Guru

Is data being sent to it?

Does it receive data if you use HAL_SPI_Receive instead?

If you feel a post has answered your question, please click "Accept as Solution".
JSanz.1
Associate III

No, the function "HAL_SPI_Receive" return by timeout.

But If I configure as DMA "HAL_SPI_TransmitReceive_DMA" and configuring the "NSS" disabled and as interrupt, it works but this configuration is useless for my current application, I need to read character by character to build the answer on fly.

Thanks

TDK
Guru

If HAL_SPI_Receive times out, it's probably not being sent data, which would explain why HAL_SPI_Receive_IT never fires the interrupt either.

If you feel a post has answered your question, please click "Accept as Solution".
JSanz.1
Associate III

Hi thanks for answering,

The source is sending a well known message with random length every 10 seconds, I can see a led connected to spi clock line to ilumine every time it receive data.

As I told in previous message, if I configure "HAL_SPI_TransmitReceive_DMA" it recive data but this configuration is useless becose I need to taylor the answer on fly.

The problen is, I can't do "HAL_SPI_Receive_IT" to work

Thanks

Is this a "known good" board such as Nuclei, or your own board? In later case, disconnect master, set SCK and NSS pins as GPIO output, toggle them in software and observe at the output (I am aiming at bad solder joints and shorts).

If this works and your slave SPI still does not receive (pool the RXNE pin instead of interrupt or any Cube/HAL function), read it and check/post SPI and relevant GPIO registers content.

JW

JSanz.1
Associate III

hi JW,

thanks for your help, finally I got the SPI running via interrupt.

I restart from scratch a new project and configuring the SPI receiver with global interrupt ant SPI transmitter via DMA.

By setting "HAL_SPI_Receive_IT" as minimal spected length.

It seems it's begining to work.

Regards