This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRFGo SDK nRF24LE1 SPI questions

Dear All,

Could some one help to answer my commented questions below ? thank you so much !

1.

//Definition at line 743 of file hal_nrf.c.

uint8_t hal_nrf_read_reg  ( uint8_t  reg )  

{
  uint8_t temp;

  CSN_LOW();

  HAL_NRF_HW_SPI_WRITE(reg);
  while(HAL_NRF_HW_SPI_BUSY) {}
  temp = HAL_NRF_HW_SPI_READ();     

  HAL_NRF_HW_SPI_WRITE(0U);         // Why this second SPI write operation is needed? what is the Parameter 0U means ? reg or command? or dummy ?
  while(HAL_NRF_HW_SPI_BUSY) {}     
  temp = HAL_NRF_HW_SPI_READ();     // Seems the temp above already got the value, why need this temp and returned ?  does this related to SPIRDAT have both two bytes deep?

  CSN_HIGH();

  return temp;
}

-------------------------------------------------------------------------
2.
//Definition at line 762 of file hal_nrf.c.
uint8_t hal_nrf_write_reg(uint8_t reg, uint8_t value)
{
uint8_t retval;
/*lint -esym(550,dummy) symbol not accessed*/
/*lint -esym(438,dummy) last assigned value not used*/
/*lint -esym(838,dummy) previously assigned value not used*/
uint8_t volatile dummy;

CSN_LOW();

HAL_NRF_HW_SPI_WRITE((W_REGISTER + reg));
while(HAL_NRF_HW_SPI_BUSY) {}
retval = HAL_NRF_HW_SPI_READ();

HAL_NRF_HW_SPI_WRITE(value);
while(HAL_NRF_HW_SPI_BUSY) {}
dummy = HAL_NRF_HW_SPI_READ();

CSN_HIGH();

return retval; // Why return retval rather than dummy ?
}

Best regards,
Kevin.
  • Hi Kenneth, 

    Thanks a lot for your answers !

    i updated comments according my understanding, please correct me if anything wrong, thanks.

    1:
    uint8_t hal_nrf_read_reg ( uint8_t reg )

    {
    uint8_t temp;

    CSN_LOW();

    HAL_NRF_HW_SPI_WRITE(reg);           // SPIRDAT = reg;
    while(HAL_NRF_HW_SPI_BUSY) {}
    temp = HAL_NRF_HW_SPI_READ();     // temp is the value of STATUS

    HAL_NRF_HW_SPI_WRITE(0U);           // Here write a extra dummy value in order to get the output from above command.
    while(HAL_NRF_HW_SPI_BUSY) {}
    temp = HAL_NRF_HW_SPI_READ();      // Here this temp stored the real reg value.
    CSN_HIGH();

    return temp;
    }


    2:
    uint8_t hal_nrf_write_reg(uint8_t reg, uint8_t value)
    {
    uint8_t retval;

    uint8_t volatile dummy;

    CSN_LOW();

    HAL_NRF_HW_SPI_WRITE((W_REGISTER + reg));          // SPIRDAT = W_REGISTER + reg;
    while(HAL_NRF_HW_SPI_BUSY) {}
    retval = HAL_NRF_HW_SPI_READ();                             // retval is the value of STATUS

    HAL_NRF_HW_SPI_WRITE(value);                                 // SPIRDAT = value;
    while(HAL_NRF_HW_SPI_BUSY) {}
    dummy = HAL_NRF_HW_SPI_READ();                            // dummy is not useful, because our value already wrote in. one of this extra READ Operation's purpose i think maybe for clearing up the SPIRDAT

    CSN_HIGH();

    return retval;
    }

  • I agree with your comments.

    Best regards,
    Kenneth

Related