Adafruit Nexopixel Library not working...

Working libraries, libraries being ported and related hardware
Post Reply
User avatar
Mangy_Dog
Posts: 103
Joined: Sat May 02, 2020 11:45 pm
Answers: 1

Adafruit Nexopixel Library not working...

Post by Mangy_Dog »

Hi @fpiSTM has said in other threads this lirbary has been forked/ported to stm32core.
But im having a real hard time getting it to work.
Basically my led strip is only showing white. (full RGB)
Whats interesting. if I set the leds less than my strip length, it only lights that number of leds. So some data at least the reset bit is getting across.
Just not the RGB...

Ive ran out of ideas has anyone else got any ideas what to check?

Running on STM32F030, 3.3V powered to the STM32, The strip 5V powered with a shared ground. Power supply is stable and clean.
Just a dogs body developer, mostly making props and stuff...
User avatar
Mangy_Dog
Posts: 103
Joined: Sat May 02, 2020 11:45 pm
Answers: 1

Re: Adafruit Nexopixel Library not working...

Post by Mangy_Dog »

2 things. Firstly im not convinced my mcu is running full speed. Even though I have this in my generic_clock.c

Code: Select all

void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

  /** Configure LSE Drive Capability
  */
  HAL_PWR_EnableBkUpAccess();
  __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_HIGH);

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.LSEState = RCC_LSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
  RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  {
    Error_Handler();
  }
  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
  PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  {
    Error_Handler();
  }
  HAL_RCC_MCOConfig(RCC_MCO, RCC_MCO1SOURCE_PLLCLK, RCC_MCODIV_1);
}
I also discovered a mistake in the adafruit library.
It uses these div calcs for the timings...

Code: Select all

uint32_t top = (F_CPU / 800000);       // 1.25µs
uint32_t t0 = top - (F_CPU / 2500000); // 0.4µs
uint32_t t1 = top - (F_CPU / 1250000); // 0.8µs
Assuming the 8mhz base clock of the crystal hsi/hse before pll. The deviders wont give the desired nanoseconds...
I tried changing it to

Code: Select all

uint32_t top = (F_CPU / 6400000);       	// 1.25µs
uint32_t t0 = top - (F_CPU / 20000000); 	// 0.4µs
uint32_t t1 = top - (F_CPU / 10000000); 	// 0.8µs
But still no luck. Which is whats leading me to think my MCU might not be running at 48mhz.
Im also looking at the signal on the oscilloscope, its only reaching 282Khz after my timing change. Its slower on the original dividers.
Nowhere near 800khz.
Which might explain why im getting just white.

How do I configure PA8 to output the MCO so I can check?
Just a dogs body developer, mostly making props and stuff...
User avatar
Mangy_Dog
Posts: 103
Joined: Sat May 02, 2020 11:45 pm
Answers: 1

Re: Adafruit Nexopixel Library not working...

Post by Mangy_Dog »

Not sure I set the pin correctly as the signal wasnt sharp but only in a few mV variance, but I manged to get 47-50mhz off PA8. So the mcu isnt underclocking.

But still only getting 284khz signal for the led string.

Im really out of ideas here.
its clear the signal is too slow coming out. But I cant increase the divider calcs any more as it seems to crash the mcu.

Not sure what else to do?

I cant swap the 8mhz crystal for a 16mhz one just yet. But that shouldnt cause this issue. Its still clocking the MCU correctly.
Just a dogs body developer, mostly making props and stuff...
User avatar
Mangy_Dog
Posts: 103
Joined: Sat May 02, 2020 11:45 pm
Answers: 1

Re: Adafruit Nexopixel Library not working...

Post by Mangy_Dog »

Even tried swapping the 8mhz crystal with a 16mhz.
And changed
uint32_t SystemCoreClock = 8000000;
to
uint32_t SystemCoreClock = 16000000;
in system_stm32f0xx.c

still having the exact same issue, even adjusting the dividers around to account for the new clock.
Just a dogs body developer, mostly making props and stuff...
ag123
Posts: 1678
Joined: Thu Dec 19, 2019 5:30 am
Answers: 25

Re: Adafruit Nexopixel Library not working...

Post by ag123 »

for neopixels I've been thinking about using Timers and DMA
https://www.thevfdcollective.com/blog/s ... 2-rgbw-led
https://ralimtek.com/posts/2021/ws2812/
think Adafruit's Neopixel lib uses SPI?
well nothing 'wrong about it' but that using Timers possibly 'saves' an SPI port and is possibly more accurate.
User avatar
Mangy_Dog
Posts: 103
Joined: Sat May 02, 2020 11:45 pm
Answers: 1

Re: Adafruit Nexopixel Library not working...

Post by Mangy_Dog »

I went with adafruit for this "quick" job thinking it be simple and off the shelf..... So you saying it needs to be tied to a spi out pin?
Just a dogs body developer, mostly making props and stuff...
User avatar
Mangy_Dog
Posts: 103
Joined: Sat May 02, 2020 11:45 pm
Answers: 1

Re: Adafruit Nexopixel Library not working...

Post by Mangy_Dog »

Also not working on a bluepill....!
Just a dogs body developer, mostly making props and stuff...
ozcar
Posts: 146
Joined: Wed Apr 29, 2020 9:07 pm
Answers: 5

Re: Adafruit Nexopixel Library not working...

Post by ozcar »

All white is an indication that the pulse durations are too long, resulting in every bit being interpreted as “1”. I looked at the Adafruit library some years ago, and the timing was a bit out, but the pulses were actually on the short side, which could cause the opposite problem of all LEDs off. In any event, for the LEDs I had it did work OK, but I’ve seen some differences in the LED specs.

At the time I looked at it, the Adafruit library used bit-banging for STM32, and I did see some variance in the timing due to that. Perhaps that has changed though, as you mention “divider calcs”???

Certainly at the time I looked at it they seemed to do very different things depending on the processor, and from what I remember it took a bit of effort to pinpoint the actual code that was being used. Roger, of “Roger’s Core” fame had a library which used SPI, but I don’t know how easy it would be to get that to work with the official ST core.

Given you have a scope, just send some data like 0x555555 or 0xaaaaaa and you should be able to see any problem immediately.
ag123
Posts: 1678
Joined: Thu Dec 19, 2019 5:30 am
Answers: 25

Re: Adafruit Nexopixel Library not working...

Post by ag123 »

I think there is one more trouble, I think neopixels are driven at 5 V
https://cdn-shop.adafruit.com/datasheets/WS2812B.pdf

it may take a 74LVC1G17 to interface it
https://www.nexperia.com/products/analo ... C1G17.html
https://assets.nexperia.com/documents/d ... VC1G17.pdf
rather available in 'online flea markets' as well
https://www.aliexpress.com/w/wholesale-74lvc1g17.html

based on the specs at VCC 5.5v it takes 2.5v to trigger (up) and 1.8v to trigger (down)

there is one inverted 74lvc1g14
https://www.nexperia.com/products/analo ... C1G14.html
https://assets.nexperia.com/documents/d ... VC1G14.pdf
https://www.aliexpress.com/w/wholesale-74lvc1g14.html
slightly bother some, but I'd guess doing output open drain with a pull-up to 3v3 would do the same

I looked at an alternative without the Schmitt trigger 74LVC1G34
https://assets.nexperia.com/documents/d ... VC1G34.pdf
VIH ( VCC = 4.5 V to 5.5 V ) - min 0.7 × VCC = 3.5v !
VIL (VCC = 4.5 V to 5.5 V) - max 0.3 x VCC = 1.5v

It may possibly work as well, but the high trigger VIH may be out of reach for stm32
so I'd guess 74LVC1G17 may be more useful for this purpose

for these 74LVCs I'm thinking of using them with those 'sot-23 to dip' adapters
https://www.aliexpress.com/w/wholesale-sot23-pcb.html
oh if you get TI versions you get exactly sot23 fits those 'dip adapter PCBs'
file:///home/andrew/it/electronics/logic/sn74lvc1g14a.pdf
a trouble is nxpress ones the pitch is 0.65 sot353 (package varies)
oh those 'sop8 to dip' would probably fit them
https://www.aliexpress.com/w/wholesale-sop8-to-dip.html
Post Reply

Return to “Libraries & Hardware”