How to shoot the trouble?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How to shoot the trouble?

ソリューションへジャンプ
655件の閲覧回数
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

ラベル(1)
タグ(1)
0 件の賞賛
返信
1 解決策
572件の閲覧回数
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 件の賞賛
返信
2 返答(返信)
573件の閲覧回数
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 件の賞賛
返信
572件の閲覧回数
guohuoping
Contributor II

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

0 件の賞賛
返信