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

nrf_esb not optimized?

Hi

I have been looking at the nrf_esb code for nRF24LE1 $LastChangedRevision: 5717 $

It seems like the nrf_write_multibyte_reg is not written very efficient. The function writes a number of bytes to the radio SPI, which is buffered so it is possible to get uninterrupted flow. But the code does not utilize that. Instead it writes one byte at a time, and waits until that is fully clocked out, before loading the next.

Below is the original version.

The question is, if there are any situations, where it causes unintended "features" to use the buffered SPI? Or maybe revision 5717 is not the latest.

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

void nrf_write_multibyte_reg(uint8_t cmd, const uint8_t *pbuf, uint8_t length)

{
  uint8_t i, next, dummy;
  NRF_CSN_LOW;

  NRF_SPI_WRITE(cmd);

  for(i = 0; i < length; i++)
  {
    next = *(pbuf + i);
    while(!NRF_SPI_TX_EMPTY);  // wait for byte transfer finished
    ;
    dummy = NRF_SPI_READ;
    NRF_SPI_WRITE(next);
  }

  while(!NRF_SPI_TX_EMPTY);  // wait for byte transfer finished
  ;
  dummy = NRF_SPI_READ;
  NRF_CSN_HIGH;
}

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

void nrf_write_multibyte_reg(uint8_t cmd, const uint8_t *pbuf, uint8_t length)

{
  uint8_t i, next, dummy;
  NRF_CSN_LOW;

  NRF_SPI_WRITE(cmd);

  for(i = 0; i < length; i++)
  {
    next = *(pbuf + i);
    while(!NRF_SPI_TX_EMPTY);  // wait for byte transfer finished
    ;
    dummy = NRF_SPI_READ;
    NRF_SPI_WRITE(next);
  }

  while(!NRF_SPI_TX_EMPTY);  // wait for byte transfer finished
  ;
  dummy = NRF_SPI_READ;
  NRF_CSN_HIGH;
}

Related