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

Quick check of my SPI code & a few related questions

Hi,

I've began making a SPI module for programming a PIC16. It only transmits data, so two pins.

My questions are:

1. any obvious errors?
2. does the EVENTS_ENDTX occur when the double buffer is empty? I need to ensure the cpu is a step ahead of the buffer emptying to ensure data continuity.  The 'ENDTX' suggests I could be in a race to fill the buffer again before the SPI has it's next clock. If so, best means to approach it?

inline void GLUE_Start (void) {

  NRF_SPIM0->ENABLE = 1;
}

static void wait (void) {

  while (! NRF_SPIM0->EVENTS_ENDTX) {}
  NRF_SPIM0->EVENTS_ENDTX = 0;
}

static void bulkErase (void) {

  NRF_SPI0->TXD = 0x18; // bulk erase
  nrf_delay_ms(10); // TERAB
}

static void loadAddress (uint24_t value) {

  NRF_SPI0->TXD = 0x80;
  wait();
  NRF_SPI0->TXD = value >> 15
  wait();
  NRF_SPI0->TXD = value >> 7 & 255;
  wait();
  NRF_SPI0->TXD = value & 255;
}

inline void GLUE_UpdateFirmware(void) {

  NRF_GPIO->OUTSET = 1 << CFG_PIN_GLUE_MODE; // into reset
  NRF_GPIO->OUTSET = 1 << CFG_PIN_GLUE_VBUSPOW; // enable 3.3v power

  GLUE_Start();

  NRF_SPI0->TXD = 'M';
  NRF_SPI0->TXD = 'C';
  wait();
  NRF_SPI0->TXD = 'H';
  wait();
  NRF_SPI0->TXD = 'P';
  wait();
  NRF_SPI0->TXD = 'P';
  wait();
  loadAddress(0x8000); // all areas
  bulkErase();

  GLUE_ShutDown();

  NRF_GPIO->OUTCLR = 1 << CFG_PIN_GLUE_MODE; // out of reset
  NRF_GPIO->OUTCLR = 1 << CFG_PIN_GLUE_VBUSPOW; // enable 5v power
}

Parents
  • You seems to be using the SPI functionality with the SPIM0 register context. This is a bit confusing.

    If you do not want to use the EasyDMA, then use NRF_SPI0 registers which do not have EVENTS_ENDTX. If you want to use the EasyDMA then I think the generation of EVENTS_ENDTX is dependent on the MAXTX setting. I haven't tried mixing the concept of SPIM and SPI even though they are in the same seriobox instance. So not sure if your code is correct or not.

Reply
  • You seems to be using the SPI functionality with the SPIM0 register context. This is a bit confusing.

    If you do not want to use the EasyDMA, then use NRF_SPI0 registers which do not have EVENTS_ENDTX. If you want to use the EasyDMA then I think the generation of EVENTS_ENDTX is dependent on the MAXTX setting. I haven't tried mixing the concept of SPIM and SPI even though they are in the same seriobox instance. So not sure if your code is correct or not.

Children
Related