How to implement bit banging in NCS via TIME+GPIOTE+PPI

Hello everyone,

Currently we're working on improving our DALI driver on the nRF52840 chip and NCS2.6.0, because we've experienced issues with transmitting DALI bits with the correct timing. The issues we experience are similar with a previous blog post here on the support channel.

I need to implement DALI tx rx on OpenThread and BLE multiprotocol.

Many people on devzone have implemented this function through TIMER+GPIOTE+PPI, and implemented pin toggle through CC events.But I don't understand how to exactly control the pin to be high or low.

Can you tell me how to achieve this?I'd be very grateful.

Parents
  • Quay,

    The managing of Dali tx and rx is an IP in itself which many Lighting companies do it themselves and the efficiency of the implementation is never shared. Unfortunately we do not have a template to show to you on how this can be done.

    The timer can be setup somthing like below to achieve 1200bps baud on the Dali transport layer

    static struct dali_timer_data dali_timer_data =
    {
        .p_instance = NRFX_TIMER_INSTANCE(CONFIG_DALI_TIMER_INSTANCE),
        .cfg = 
        {
            .frequency = NRF_TIMER_FREQ_16MHz,
            .mode = NRF_TIMER_MODE_TIMER,
            .bit_width = NRF_TIMER_BIT_WIDTH_32,
            .interrupt_priority = 0
        }
    };
    
    static void timer_handler(nrf_timer_event_t event_type, void *p_context)
    {
        struct dali_timer *timer = (struct dali_timer *)p_context;
        struct dali_timer_data * timer_data = (struct dali_timer_data *)timer->timer_data;
        if(event_type == NRF_TIMER_EVENT_COMPARE0)
        {
            timer->callback(timer, timer->user_data);
        }
    }

    GPIOTE and PPI can be configured something like this

    NRF_GPIOTE->CONFIG[GPIOTE_CH_OUT] = GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos |
                                        GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos |
                                        PIN << GPIOTE_CONFIG_PSEL_Pos |
                                        GPIOTE_CONFIG_OUTINIT_High << GPIOTE_CONFIG_MODE_Pos;
    
    NRF_TIMER3->BITMODE = TIMER_BITMODE_BITMODE_32Bit << TIMER_BITMODE_BITMODE_Pos;
    NRF_TIMER3->PRESCALER = 0;
    NRF_TIMER3->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Enabled << 0;
    NRF_TIMER3->MODE = TIMER_MODE_MODE_Counter << TIMER_MODE_MODE_Pos;
    NRF_TIMER3->CC[0] = COUNT_LIMIT;
    NRF_TIMER3->TASKS_START = 1;
    
    NRF_PPI->CH[PPI_CH_0].EEP = (uint32_t)&NRF_GPIOTE->EVENTS_IN[GPIOTE_CH_IN];
    NRF_PPI->CH[PPI_CH_0].TEP = (uint32_t)&NRF_TIMER3->TASKS_COUNT;
    

Reply Children
No Data
Related