Problem with SPI interrupt

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with SPI interrupt

1,043 Views
durgeshtanuku
Contributor II

In my code, I need to write data into flash, which is interfaced to my KL26Z through SPI.


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

error = SM0_SendBlock(masterDevData, (LDD_TData*)Data,Number_Of_Bytes);

if(error !=ERR_OK)

return SLLD_ERROR;

error = SM0_ReceiveBlock(masterDevData, (LDD_TData*)dummyBuffer,Number_Of_Bytes);

if(error!=ERR_OK)

return SLLD_ERROR;

while(Tx_CompleteFlag==0);

Tx_CompleteFlag=0;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

I am setting Tx_CompleteFlag in SPI_OnBlockSent event in Events.c

My requirement needs Tx_CompleteFlag to be set after transmission of Number_Of_Bytes mentioned above. But I am getting interrupt after tx of only a single character.

If any of you know the solution kindly reply me

regards,

Durgesh

Labels (1)
Tags (1)
0 Kudos
3 Replies

736 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Durgesh,

The transmit interrupt is triggered by the either SPI transmit buffer empty flag ( when FIFO is not supported or not enabled ) or SPI transmit FIFO empty flag ( when FIFO is supported and enabled ),

So you can't get the code by PE which can active a interrupt after the accomplishment of transfer the number of bytes you defined, and as the Mark suggested,

I think you need to modify the original code that PE created to work it out.
Have a great day,
Ping

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

0 Kudos

736 Views
mjbcswitzerland
Specialist V

Hi Durgesh

It looks like you are using PE generated code as a base for the operation.

This tends to be very simply code that just gives you a starting point by writing a flag when an interrupt occurs. If you want it to be more intelligent and recognise the completion of a block of data you will probably need to modify the interrupt routine to count the interrupts that occur and compare with the amount of data bytes originally sent and then set the flag only when they match.

Note also that you should be checking the busy state of SPI Flash between writing and reading since the chip will require some time to complete write operations.

Regards

Mark

µTasker Kinetis support

0 Kudos

736 Views
durgeshtanuku
Contributor II

Hello Mark

Thanks for your reply.

If the interrupt is occuring after exactly one character, I could use the the logic you have suggested. But today I have observed that as I am changing the SPI clock rate, The interrupt is occuring at different intervals for different SPI frequencies irrespective of number of transmitted characters. Some times after getting the interrupt, I could not even see the tx data on logic analyser

0 Kudos