When I read the code of the SPI_Slave_Demo, I found there have nothing about the spi slave working route in the program. So can some geniuses give some examples of ke06 spi slave working mode. Thx and Merry X'mas!
I just glanced at it and I see this:
/* initialize SPI0 as master */
sSPIConfig.sSettings.bMasterMode = 0;
So... maybe someone was lazy and didn't change the comments? In spi_app.c the init routine sets a slave callback. If it is an SPI slave demo, it's not very well documented. The readme file has a little info. I realize NXP/Freescale has engineers from all over, but I would be so happy if they had one native English speaker who could proofread the app notes and example docs.
Hi, XuMan
As Scott said the example SPI_Slavedemo located at:"D:\Freescale\kexx_drv_lib\build\cw\ke06\SPI_Slave_demo" is the SPI slave example exactly although there is note which says that the example is in master mode.
Regarding the architecture of the example, it uses the interrupt driven mechanism. Firstly, we initialize a structure called sSPIConfig and use the SPI_Init(SPI0, &sSPIConfig); function to initialize the SPI module registers. we use the SPI_Transfer() to assign both address of the transmitting data array and receiving data array which customer has defined to data pointer, enable SPI interrupt, and assign the "SPI_STATUS_BUSY" to status variable u8SPI_Status[0] or u8SPI_Status[1] , depending on whether you use SPI0 or SPI1 modules. when the SPI interrupt happens, the SPI0_Isr() is executed automatically, accordingly, the registered callback function void SPI0_SlaveCallback(void) is executed. In the SPI0_SlaveCallback(void) function, one data from the transmitting array[] is written to the SPIx_D register, one data is read from SPIx_D register and written to receiving data array for each interrupt. If all the predefined number of data has be written or received, the status u8SPI_Status[0]/u8SPI_Status[1] is updated with SPI_STATUS_TX_OVER and disable SPI interrupt, the transfer is over.
Hope it can help you understand the example code, I have not found any doc to elaborate the example code yet.
BR
Xiangjun Rong
void SPI0_Isr(void)
{
if( SPI_Callback[0] )
{
SPI_Callback[0]();
}
}