cancel
Showing results for 
Search instead for 
Did you mean: 

Background function

SGian.1
Senior

Hi there!

I still work on my project for read Ibutton. In the main i check every 500ms if there is any key(unfortunally i can’t use interrupt) . Now i want use a W2812B for report some error. Soo my question is how I can implement one function work in back ground for example turn on and off led every second without give a error with function check the presence of the key ? I saw freerots but i think is too much for this project. Because my worry is how mange the timer dosen’t stay in the error function and stop to check the key

Thank you so much

Sergio

 

3 REPLIES 3

@SGian.1 wrote:

I still work on my project for read Ibutton.


This one: https://community.st.com/t5/others-hardware-and-software/dallas-ibutton-and-uart/td-p/755993 ?

 


@SGian.1 wrote:

unfortunately i can’t use interrupt


Why not?

 


@SGian.1 wrote:

Now i want use a W2812B for report some error.


You mean those "smart" RGB LEDs with the single wire interface - known by some as "NeoPixels", etc?

Note that you can apply a similar technique to synthesise the drive for these using, eg, SPI.

 

There are also version available which work directly on SPI; eg, SK9822 or APA102C:

https://learn.sparkfun.com/tutorials/apa102-addressable-led-hookup-guide/all

https://www.pololu.com/product/3089 (I think AdaFuit call these "DotStar"?)

 


@SGian.1 wrote:

Soo my question is how I can implement one function work in back ground for example turn on and off led every second without give a error with function check the presence of the key ?


You said you're polling, so you have full control of the timing of these things.

Just sequence your LED drive and your 1-WireTM access so that they don't interfere with each other!

If you're polling the 1-WireTM every 500ms, and updating the LEDs every second, then you just need to do the LED update with every other transaction 1-WireTM;

eg, have a 500ms "tick", and do the LED update on the odd ticks

 

if( tick_count & 1 )
{ 
  // The tick count is odd 
  update_LEDs();
}

do_1wire();

tick_count++;

 

 

gbm
Lead III

Use interrupt driven UART or timer for OneWire, use UART or SPI with DMA for WS2812. There is no reason for not using interrupts.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice

@gbm wrote:

use UART or SPI with DMA for WS2812. .


You wouldn't need DMA ...

 


@gbm wrote:

There is no reason for not using interrupts.


Indeed.

@SGian.1 The whole point of using the UART for 1-WireTM is that all the critical timing is handled by the UART hardware - so you don't have to worry about interrupts messing-up software bit-bang timing.

Similarly for driving WS2812 via SPI (or UART).