cancel
Showing results for 
Search instead for 
Did you mean: 

SPI transmit with interrupt not work

EBurk.1
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions
EBurk.1
Associate II

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

Thanks to everybody

View solution in original post

7 REPLIES 7
Bubbles
ST Employee

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.

Where and how is afe_spi defined?

JW

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

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

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

Thanks to everybody

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 Venmo
Up vote any posts that you find helpful, it shows what's working..