SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By gcds
#123597
Hello, everyone I'm new here but not new at embedded things. So I was newbie and know how hard is to start something. So I will make some code snippets for you guys. So here is my first snippet. Sorry guys for link cause I'm too lazy to copy it here... And Sorry if I posted to incorrect category I saw in PIC's Code Snippets but in AVR dont :D

Aurimas
By gcds
#123690
I just forgot to remove it was status led just incase if it get stuck inside :D But it never shows up :P
Last edited by gcds on Fri Mar 25, 2011 12:33 am, edited 1 time in total.
By frank26080115
#123711
When did your code get stuck? I don't see any loops, so you might have had a loop in your interrupt code.

Also, where did you learn this ring buffer technique? It's usually done with a read and write pointer, instead of a single pointer and length. I'm not sure about the advantages of the methods but this is the first time I've seen it done your way.
By gcds
#123722
frank26080115 wrote:When did your code get stuck? I don't see any loops, so you might have had a loop in your interrupt code.

Also, where did you learn this ring buffer technique? It's usually done with a read and write pointer, instead of a single pointer and length. I'm not sure about the advantages of the methods but this is the first time I've seen it done your way.
Sorry, It not get stuck just mistake in writing :D

I don't know this should be like this. You create like 10 byte variable filling it and updating dataindex and datalength and when you get full you starting from index 0 and so on...
By stevech
#123845
lots of examples of ring buffer code on avrfreaks.net, forum, projects section.

Most ring buffers have a "head" pointer and a "tail" pointer. the buffer size is a power of two so it's easy to use an AND operation to wrap the pointers in a circular manner.

You can use two index numbers in the same manner.

When head == tail, the buffer is empty. Storing into the buffer advances the head. Retrieving advances the tail pointer or index.
Beware interrupts and use of the volatile declaration if interrupts alter the buffer contents.