Skip to main content
EBurk.1
Associate II
March 20, 2023
Solved

SPI transmit with interrupt not work

  • March 20, 2023
  • 5 replies
  • 3716 views

Hello to everybody,

I have program for stm32f103 mcu. Now I want to do my SPI transmit routine using interrupt.

Before:

HAL_StatusTypeDef status = HAL_SPI_Transmit(&afe_spi, (uint8_t*) pData, 4,100);

Now I tried this (and many variants also):

HAL_StatusTypeDef status = HAL_SPI_Transmit_IT(&afe_spi, (uint8_t *) pData, 4);
	while (status != HAL_OK){
		status = HAL_SPI_Transmit_IT(&afe_spi, (uint8_t *) pData, 4);
	}

But data isn't sended. And in debug mode i can see:

0693W00000aJKXCQA4.pngMy project settings:

0693W00000aJKXWQA4.png0693W00000aJKXqQAO.pngOther interrupt also not works.

Best regerds, Egor

This topic has been closed for replies.
Best answer by EBurk.1

I changed &afe_spi to &hspi1 and it works! I forget about pointer =0

Thanks to everybody

5 replies

Bubbles
ST Employee
March 20, 2023

Hi @EBurk.1​ ,

looks like you didn't implement the callbacks correctly. The IRQ handler will use callback functions to notify your software about events, like for example buffer empty or buffer full. You need to implement these. Look at some examples from the intro pack repository to get inspiration.

BR,

J

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
waclawek.jan
Super User
March 20, 2023

Where and how is afe_spi defined?

JW

EBurk.1
EBurk.1Author
Associate II
March 20, 2023

afe_spi is hspi1 SPI_HandleTypeDef

main.c:

AFE_INIT(hspi1);

and my afe.c:

void AFE_INIT(SPI_HandleTypeDef hspi) {
	afe_spi = hspi;
...

Without interrupt Tx and Rx working, but i can't get how to implement callback function. I need just to send data with interrupt without any special things for a start

waclawek.jan
Super User
March 20, 2023

OK so how is hspi1 defined?

In debugger, look at where it is placed in memory, and what it its content, and show.

JW

EBurk.1
EBurk.1Author
Associate II
March 20, 2023
// HAL_StatusTypeDef status = HAL_SPI_Transmit(&afe_spi, (uint8_t *) pData, 4, 100); // works fine
 
	HAL_StatusTypeDef status = HAL_SPI_Transmit_IT(&afe_spi, (uint8_t *) pData, 4);
		while (status != HAL_OK){
			status = HAL_SPI_Transmit_IT(&afe_spi, (uint8_t *) pData, 4);
		}

0693W00000aJL7eQAG.png

EBurk.1
EBurk.1AuthorBest answer
Associate II
March 20, 2023

I changed &afe_spi to &hspi1 and it works! I forget about pointer =0

Thanks to everybody

Tesla DeLorean
Guru
March 20, 2023

For IT and DMA also watch the scope of the data pointer (pData)

Using local/auto variables for parameters passed in can lead to stack data corruption and failure if/when the scope collapses.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..