I'm trying to communicate with a single NeoPixel (WS2812B) using the PWM module.
I've configured a sequence array with the compare values necessary to turn on the red and the blue leds.
I would like to transmit this data without having to poll EVENTS_SEQEND[0] before moving on. This doesn't seem to be possible even if I use the shortcut EVENTS_SEQEND[0] and STOP task. The communication doesn't seem to work.
However, if I insert the following polling before the while(); statement everything works ok. Any ideas?
while(!NRF_PWM1->EVENTS_SEQEND[0])
{
yield();
}
NRF_PWM1->EVENTS_SEQEND[0] = 0;
Here's the code:
#define PIXPIN 7 //data pin for neopixel
void main()
{
NRF_GPIO->DIRSET = (1 << PIXPIN); //set ref pin as output
NRF_GPIO->OUTCLR = (1 << PIXPIN); //set ref pin low
NRF_PWM1->MODE = 0; //up counter
NRF_PWM1->PRESCALER = 0; //16MHz ticks
NRF_PWM1->COUNTERTOP = 20; //1.25 µsec pwm frequency
NRF_PWM1->LOOP = 0; //looping disabled
NRF_PWM1->DECODER = 0; //common, refresh count
NRF_PWM1->SEQ[0].REFRESH = 0;
NRF_PWM1->SEQ[0].ENDDELAY = 0;
NRF_PWM1->PSEL.OUT[0] = PIXPIN;
NRF_PWM1->ENABLE = 1;
NRF_PWM1->SHORTS = 0b00001; //Shortcut between SEQEND[0] event and STOP task
uint16_t neoPixelWavFrm[64] = {32774, 32774, 32774, 32774, 32774, 32774, 32781, 32774,
32774, 32774, 32774, 32774, 32774, 32774, 32781, 32774,
32774, 32774, 32774, 32774, 32774, 32774, 32781, 32774,
32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768,
32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768};
NRF_PWM1->SEQ[0].PTR = (uint32_t)(neoPixelWavFrm);
NRF_PWM1->SEQ[0].CNT = 64; //one uint16_t for each of the 24 bits per pixel plus 40 extra
NRF_PWM1->SEQ[0].REFRESH = 0;
NRF_PWM1->SEQ[0].ENDDELAY = 0;
NRF_PWM1->EVENTS_SEQEND[0] = 0;
NRF_PWM1->TASKS_SEQSTART[0] = 1;
while(1);
}