SPI callback event

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

SPI callback event

267 Views
chris_010
Contributor II

hi, when  using spi callback function, I meet a trouble, need some help.

 my code description: I use LPSI0 as slave to communicate with external device,using interrupt mode.here is my code:

callback function defined:

void lpspi_callback_int(uint8 Instance, Lpspi_Ip_EventType Event)
{
Event_global = Event;
 
if(Event ==LPSPI_IP_EVENT_END_TRANSFER)
{
// Cache_Ip_InvalidateByAddr(CACHE_IP_CORE,CACHE_IP_DATA, (uint32)&rxBuffer[0U], 8);
// read data from rxBuffer
t++;
__asm volatile ("nop");
 
}
else if (Event ==LPSPI_IP_EVENT_FAULT)
{
__asm volatile ("nop");
 
}
}
 
start receive data:
 
lpspi_status = Lpspi_Ip_AsyncTransmit(&SLAVE_EXTERNAL_DEVICE_1, TxSlaveBuffer, RxSlaveBuffer, NUMBER_OF_BYTES, lpspi_callback_int);
 
 

Phenomenon: The callback function is invoked when the master sends data for the first time, but it is not invoked during subsequent data transmissions.

How to fix this issue? Ensure the callback function is triggered on every external SPI data transmission.

 

Tags (1)
0 Kudos
Reply
1 Reply

201 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

do you call Lpspi_Ip_AsyncTransmit again after callback is invoked, to prepare slave for next transfer? This must be called before master sends new frame.

BR, Petr

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2288765%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ESPI%20callback%20event%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2288765%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3Ehi%2C%20when%26nbsp%3B%20using%20spi%20callback%20function%2C%20I%20meet%20a%20trouble%2C%20need%20some%20help.%3C%2FP%3E%3CP%3E%26nbsp%3Bmy%20code%20description%3A%20I%20use%20LPSI0%20as%20slave%20to%20communicate%20with%20external%20device%2Cusing%20interrupt%20mode.here%20is%20my%20code%3A%3C%2FP%3E%3CP%3Ecallback%20function%20defined%3A%3C%2FP%3E%3CDIV%3Evoid%20lpspi_callback_int(uint8%20Instance%2C%20Lpspi_Ip_EventType%20Event)%3C%2FDIV%3E%3CDIV%3E%7B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EEvent_global%20%3D%20Event%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eif(Event%20%3D%3DLPSPI_IP_EVENT_END_TRANSFER)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%2F%2F%20Cache_Ip_InvalidateByAddr(CACHE_IP_CORE%2CCACHE_IP_DATA%2C%20(uint32)%26amp%3BrxBuffer%5B0U%5D%2C%208)%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F%2F%20read%20data%20from%20rxBuffer%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Et%2B%2B%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E__asm%20volatile%20(%22nop%22)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eelse%20if%20(Event%20%3D%3DLPSPI_IP_EVENT_FAULT)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E__asm%20volatile%20(%22nop%22)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3Estart%20receive%20data%3A%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3Elpspi_status%20%3D%20Lpspi_Ip_AsyncTransmit(%26amp%3BSLAVE_EXTERNAL_DEVICE_1%2C%20TxSlaveBuffer%2C%20RxSlaveBuffer%2C%20NUMBER_OF_BYTES%2C%20lpspi_callback_int)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CP%3EPhenomenon%3A%20The%20callback%20function%20is%20invoked%20when%20the%20master%20sends%20data%20for%20the%20first%20time%2C%20but%20it%20is%20not%20invoked%20during%20subsequent%20data%20transmissions.%3C%2FP%3E%3CP%3EHow%20to%20fix%20this%20issue%3F%20Ensure%20the%20callback%20function%20is%20triggered%20on%20every%20external%20SPI%20data%20transmission.%3C%2FP%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2289299%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20SPI%20callback%20event%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2289299%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%0A%3CP%3Edo%20you%20call%26nbsp%3B%3CSPAN%3ELpspi_Ip_AsyncTransmit%20again%20after%20callback%20is%20invoked%2C%20to%20prepare%20slave%20for%20next%20transfer%3F%20This%20must%20be%20called%20before%20master%20sends%20new%20frame.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EBR%2C%20Petr%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E