infinite loops

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
femec_2299216
Level 1
Level 1
First like received First like given

What can it be when the function (while(0u == (nRF_SPI_GetMasterInterruptSource() & nRF_SPI_INTR_MASTER_SPI_DONE))) goes to infinite loops?

void SPI_wait_done() {

  nRF_SPI_ClearMasterInterruptSource(nRF_SPI_INTR_MASTER_SPI_DONE); 

  while(0u == (nRF_SPI_GetMasterInterruptSource() & nRF_SPI_INTR_MASTER_SPI_DONE))

    ;  /* Wait while Master completes transfer */

    /* Clear interrupt source after transfer completion */

  nRF_SPI_ClearMasterInterruptSource(nRF_SPI_INTR_MASTER_SPI_DONE);

}

0 Likes
1 Solution
Yugandhar
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 5 likes given

Hello,

The API nRF_SPI_GetMasterInterruptSource() will returns Master interrupt request register. This register contains current status of Master interrupt sources. The master interrupt source nRF_SPI_INTR_MASTER_SPI_DONE will describe that SPI master transfer is completed.

The function (while(0u == (nRF_SPI_GetMasterInterruptSource() & nRF_SPI_INTR_MASTER_SPI_DONE))) goes to infinite loops when the SPI master transfer is not completed.

Thanks,

P Yugandhar.

View solution in original post

0 Likes
3 Replies
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I would do something like

=============================

int SPI_wait_done() {

  int result = OK ;

  uint32_t timeout = 0xFFFFFF ; /* some big number to wait */

  nRF_SPI_ClearMasterInterruptSource(nRF_SPI_INTR_MASTER_SPI_DONE);

  while(0u == (nRF_SPI_GetMasterInterruptSource() & nRF_SPI_INTR_MASTER_SPI_DONE)) {

     if (--timeout == 0) {

          result = TIMEOUT ;

          break ;

     }

  }

...

=============================

moto

0 Likes
Yugandhar
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 5 likes given

Hello,

The API nRF_SPI_GetMasterInterruptSource() will returns Master interrupt request register. This register contains current status of Master interrupt sources. The master interrupt source nRF_SPI_INTR_MASTER_SPI_DONE will describe that SPI master transfer is completed.

The function (while(0u == (nRF_SPI_GetMasterInterruptSource() & nRF_SPI_INTR_MASTER_SPI_DONE))) goes to infinite loops when the SPI master transfer is not completed.

Thanks,

P Yugandhar.

0 Likes
Yugandhar
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 5 likes given

Please refer the PSoC4 Serial communication Block(SCB) Component for more information in the below link.

http://www.cypress.com/file/220331/download

Thanks,

P Yugandhar.

0 Likes