Examples from the Product Specification

Dear forum,

I am trying to implement some examples from the nrf5340 Product Specification but the register names does not match with the ones in the include files. I am using nrf.h and <nrf5340_application.h>, <nrf5340_application_peripherals.h>

How can I determine which ones to use instead?

In this example (DPPI publish/subscribe), the PUBLISH_COMPARE0 is not available. DPPI_PUB_CHIDC_Ch0 as well.... The NRF_TIMER0 I assume should be NRF_TIMER0_S .. the list goes on....


NRF_TIMER0->PUBLISH_COMPARE0 = (DPPI_PUB_CHIDX_Ch0) | 
 (DPPI_PUB_EN_Msk);
NRF_SAADC->SUBSCRIBE_START = (DPPI_SUB_CHIDX_Ch0) | 
 (DPPI_SUB_EN_Msk);
 
NRF_DPPIC->CHENSET = (DPPI_CHENSET_CH0_Set << DPPI_CHENSET_CH0_Pos);


Any hints and pointers to working examples appreciated.

.. and yes, I know there are libraries like nrfx or others available but I prefer to code on bare metal in this case.

Parents
  • As a reply to myself I share this code snippet which I got to run

    #include <stdbool.h>
    #include <nrf.h>
    
    #define PPI_CHANNEL (3)
    #define PIN_GPIO    (28)
    
    int main(void)
    {
      // Configure GPIO pin for LED (0.28) as output
      NRF_P0_S->DIRSET = (1UL << PIN_GPIO);
      
      // Configure GPIOTE->TASKS_OUT[0] to toggle PIN_GPIO
      NRF_GPIOTE0_S->CONFIG[0] =  (GPIOTE_CONFIG_MODE_Task       << GPIOTE_CONFIG_MODE_Pos) |
                                  (GPIOTE_CONFIG_OUTINIT_Low     << GPIOTE_CONFIG_OUTINIT_Pos) |
                                  (GPIOTE_CONFIG_POLARITY_Toggle << GPIOTE_CONFIG_POLARITY_Pos) |
                                  (PIN_GPIO                      << GPIOTE_CONFIG_PSEL_Pos);
      
      // Configure TIMER0 to generate EVENTS_COMPARE[0] every half second.
      NRF_TIMER0_S->BITMODE = TIMER_BITMODE_BITMODE_32Bit << TIMER_BITMODE_BITMODE_Pos;
      NRF_TIMER0_S->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos;
      NRF_TIMER0_S->PRESCALER = 6;
      NRF_TIMER0_S->CC[0] = 100000;
      NRF_TIMER0_S->TASKS_START = 1;
      
      
      // Configure PPI channel with connection between TIMER0 and Pin event
      // The timer should publish the event onto the channel
      NRF_TIMER0_S->PUBLISH_COMPARE[0] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | PPI_CHANNEL;
      
      // and the pin handler should listen (subscribe) to the channel and trigger a change
      NRF_GPIOTE0_S->SUBSCRIBE_OUT[0] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | PPI_CHANNEL;
    
       // Enable PPI channel to get it running
      NRF_DPPIC_S->CHENSET = (1UL << PPI_CHANNEL);
     
      
      // Since this is all running in the background without involving the CPU
      // We can now just sit back and do nothing.
        while (1)
      {
        __WFE();
      }
    }



    It seems like the best thing to do is to carefully read the product specification but to look in the nrf5340_application_bitefields.h file to figure out the actual names. It is logically structured.

Reply
  • As a reply to myself I share this code snippet which I got to run

    #include <stdbool.h>
    #include <nrf.h>
    
    #define PPI_CHANNEL (3)
    #define PIN_GPIO    (28)
    
    int main(void)
    {
      // Configure GPIO pin for LED (0.28) as output
      NRF_P0_S->DIRSET = (1UL << PIN_GPIO);
      
      // Configure GPIOTE->TASKS_OUT[0] to toggle PIN_GPIO
      NRF_GPIOTE0_S->CONFIG[0] =  (GPIOTE_CONFIG_MODE_Task       << GPIOTE_CONFIG_MODE_Pos) |
                                  (GPIOTE_CONFIG_OUTINIT_Low     << GPIOTE_CONFIG_OUTINIT_Pos) |
                                  (GPIOTE_CONFIG_POLARITY_Toggle << GPIOTE_CONFIG_POLARITY_Pos) |
                                  (PIN_GPIO                      << GPIOTE_CONFIG_PSEL_Pos);
      
      // Configure TIMER0 to generate EVENTS_COMPARE[0] every half second.
      NRF_TIMER0_S->BITMODE = TIMER_BITMODE_BITMODE_32Bit << TIMER_BITMODE_BITMODE_Pos;
      NRF_TIMER0_S->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos;
      NRF_TIMER0_S->PRESCALER = 6;
      NRF_TIMER0_S->CC[0] = 100000;
      NRF_TIMER0_S->TASKS_START = 1;
      
      
      // Configure PPI channel with connection between TIMER0 and Pin event
      // The timer should publish the event onto the channel
      NRF_TIMER0_S->PUBLISH_COMPARE[0] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | PPI_CHANNEL;
      
      // and the pin handler should listen (subscribe) to the channel and trigger a change
      NRF_GPIOTE0_S->SUBSCRIBE_OUT[0] = DPPIC_SUBSCRIBE_CHG_EN_EN_Msk | PPI_CHANNEL;
    
       // Enable PPI channel to get it running
      NRF_DPPIC_S->CHENSET = (1UL << PPI_CHANNEL);
     
      
      // Since this is all running in the background without involving the CPU
      // We can now just sit back and do nothing.
        while (1)
      {
        __WFE();
      }
    }



    It seems like the best thing to do is to carefully read the product specification but to look in the nrf5340_application_bitefields.h file to figure out the actual names. It is logically structured.

Children
No Data
Related