lavallc / nrf51-neopixel

WS2812(Neopixel) library for the Nordic Semiconductor 51822 Bluetooth Low Energy ARM SoC.
MIT License
60 stars 22 forks source link

Not working with nRF52 #4

Open paultanner opened 6 years ago

paultanner commented 6 years ago

Presumably there is an assumption about the clock rate of the SoC and that's why. Tested empirically (adjusting # of NOPs): nRF51: 9,0,1,8 nRF52: 41,20, 20,41 This works ok for first LED on strip but cracks up after that. Not accurate enough. On the 52 it may be possible to do this better with interrupts. Not tried yet.

CarlosPena00 commented 5 years ago

Hello, Paultanner, I am having some problems trying to work with nRF52, I change the # of NOPs but still not working, Could you provide your sorce code ? ( I just need one LED)

Thanks,

etx commented 5 years ago

I trying to use this on a nRF52840. Did you guys figure anything out?

pstids commented 4 years ago

The core of the nRF52840 is clocked at 64MHz. Referencing this document https://learn.adafruit.com/adafruit-neopixel-uberguide/advanced-coding describing the transmission protocol, I modified the number of NOPs to the following, which works for me. Don't forget that if you are using the radio, then softdevice interrupts could scupper your timings: there are a number of ways to solve this issue (timeslots, or temporarily disabling the softdevice).

Note, I didn't bother taking into account the loop/if cycles: at 64MHz they execute quick enough to be within the margin of error - so you could probably make this tighter, if you were inclined.

Coding 1: 52 High; 28 Low Coding 0: 25 High; 58 Low

define NEOPIXEL_SEND_ONE NRF_GPIO->OUTSET = (1UL << PIN); \

__ASM ( \ " NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t" \ " NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t" \ " NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t" \ " NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t" \ " NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t" \ " NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t" \ " NOP\n\t NOP\n\t NOP\n\t NOP\n\t" \ ); \ NRF_GPIO->OUTCLR = (1UL << PIN); \ __ASM ( \ " NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t" \ " NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t" \ " NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t" \ " NOP\n\t NOP\n\t NOP\n\t NOP\n\t" \ ); \

define NEOPIXEL_SEND_ZERO NRF_GPIO->OUTSET = (1UL << PIN); \

__ASM (  \ 
    " NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t" \ 
    " NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t" \ 
    " NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t" \ 
    " NOP\n\t"  \ 
);  \ 
NRF_GPIO->OUTCLR = (1UL << PIN);  \ 
__ASM ( \ 
    " NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t" \ 
    " NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t" \ 
    " NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t" \ 
    " NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t" \ 
    " NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t" \ 
    " NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t NOP\n\t" \ 
    " NOP\n\t NOP\n\t NOP\n\t NOP\n\t" \ 
    " NOP\n\t" \ 
    " NOP\n\t" \ 
);
Protonerd commented 4 years ago

Has anyone tried out the above code on the nRF52? I'm interested in an alternate method to the Adafruit library

Protonerd commented 4 years ago

The core of the nRF52840 is clocked at 64MHz. Referencing this document https://learn.adafruit.com/adafruit-neopixel-uberguide/advanced-coding describing the transmission protocol, I modified the number of NOPs to the following, which works for me. Don't forget that if you are using the radio, then softdevice interrupts could scupper your timings: there are a number of ways to solve this issue (timeslots, or temporarily disabling the softdevice).

Note, I didn't bother taking into account the loop/if cycles: at 64MHz they execute quick enough to be within the margin of error - so you could probably make this tighter, if you were inclined.

@pstids Could you include a simple but full sketch which works for you? Do you work with Arduino?

schosdas commented 3 years ago

Hello I would like to use this library in nrf52832. Could you tell me about the NOP correction for 52832?

Thank you.

Protonerd commented 3 years ago

@schosdas: look here https://github.com/Protonerd/nrf52-neopixel

This library is based on the nRF51 lib here, modified and fully debugged by myself and my friend Stefan with a logic analyser. Works great in our project.

Protonerd commented 3 years ago

Kudos to lavallc and pstids for the hints, it did only take a bit of an effort to port it to nRF52