I create a project in KDS, and it use MK10DX256VLH7. Now, I have a question to ask for your help.
I use PE to initial a SPI component, which involve Input interrupt and Output interrupt,and at the initial progress, PE auto enable SPI component also.Then, I define two variables, spi_tx_fin and spi_rx_fin. In the project, PE create two event functions, void SPI_OnBlockReceived(LDD_TUserData *UserDataPtr) and void SPI_OnBlockSent(LDD_TUserData *UserDataPtr). For the convenience of polling SPI transmit and/or receive progress success or not, I write the code: spi_tx_fin = Yes and spi_rx_fin = Yes (Macro: Yes=1, No=0) in the two event functions respectively. Afterward, I define another function MotorInit(), which call function LDD_TError SPI_SendBlock(LDD_TDeviceData *DeviceDataPtr, LDD_TData *BufferPtr, uint16_t Size) generated by PE to transmit data on the SPI module. The code as follows:
spi_tx_fin = No;
SPI_SendBlock(pSPI,if_configuration_429.buffer,4);
while(spi_tx_fin == No);
Unfortunately, when debug program, the progress was blocked here while(spi_tx_fin == No); I checked the debug progress and was sure in the event function void SPI_OnBlockSent(LDD_TUserData *UserDataPtr) the variable spi_tx_fin was set Yes
By the way, I offer my project to you. Thank you!
Original Attachment has been moved to: workspace.kds.rar
Solved! Go to Solution.
Hi, Guo Huoping,
I think i would come from the global optimization by C Compiler. Therefore,
while(spi_tx_fin == No);
would be always true (not exit from whle loop) because of the above statement as
spi_tx_fin = No;.
Do you add 'volatile' key word to declaration of the spi_tx_fin and spi_rx_fin? If not, by adding 'volatile' to those variable declarations, it would go well.
Best regards,
Yasuhiko Koumoto.
Hi, Guo Huoping,
I think i would come from the global optimization by C Compiler. Therefore,
while(spi_tx_fin == No);
would be always true (not exit from whle loop) because of the above statement as
spi_tx_fin = No;.
Do you add 'volatile' key word to declaration of the spi_tx_fin and spi_rx_fin? If not, by adding 'volatile' to those variable declarations, it would go well.
Best regards,
Yasuhiko Koumoto.
Thank you!Your advice is good, I have shoot the trouble!