How to send SPI data via interrupt?

cancel
Showing results for 
Search instead for 
Did you mean: 

How to send SPI data via interrupt?

1,100 Views
Contributor I

Hi everybody,

I would like to send block of data using SPI interface and relevant interrupt. In CW there is function "byte SM1_SendBlock(SM1_TComData *Ptr, word Size, word *Snd)", but I think, it is blocking. My aim is to fill output buffer and then to use interrupt to dispatch it away without waiting in the loop.

My current solution of this problem is:

a) in main loop I activate interrupt from SPI (SM1_OnTxChar) and then I send one byte from buffer via byte SM1_SendChar(SM1_TComData Chr) function

b) in interrupt routine I use the same function to dispatch the rest of data

It works, but in my opinion this way is not so elegant. Is there any method to start interrupt without first call of function mentioned in the point a) above? For example set up the flag of this interrupt and so induce it "artificially"?

Thank you a lot.

Mira

P.S.: I know DMA, but I am not familiar with it...... My platform is FRDM-KL25Z

0 Kudos
3 Replies

182 Views
Contributor I

Hi Kerry,

thank you for your advice and confirmation of my ideas. Nowadays I am out of my work, therefore I am not able to use my development tools, so I am going to check and test your attached example as soon as possible.

Have a nice day,

Miroslav

0 Kudos

182 Views
NXP TechSupport
NXP TechSupport

Hi Miroslav,

   You are welcome.

    It doesn't matter, just test it on your side when you have time, no hurry on my side.

    Any question about this topic, just let me know and follow the post after you check it.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

182 Views
NXP TechSupport
NXP TechSupport

HI Miroslav Martisek,

    Yes, of course, if you don't want to call the send function with interrupt mode, you can just enable the TX IE, and make sure your send data is ready, then the interrupt will send it.

   You just need to write the according code in your interrupt service function.

  I have attached a SPI interrupt code for KL25 SPI master and slave which I wrote it by myself a long time ago.

  You can refer to it. Please use function:

SPI_Master_Interrupt_test ,this is for interrupt.

SPI_Master_Query_test, this is used for polling mode.

Wish it helps you!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos