How to shoot the trouble?

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

How to shoot the trouble?

Jump to solution
447 Views
guohuoping
Contributor II

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

Labels (1)
Tags (1)
0 Kudos
1 Solution
364 Views
yasuhikokoumoto
Senior Contributor I

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.

View solution in original post

0 Kudos
2 Replies
365 Views
yasuhikokoumoto
Senior Contributor I

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.

0 Kudos
364 Views
guohuoping
Contributor II

Thank you!Your advice is good, I have shoot the trouble!

0 Kudos