AVR UART programming

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hy guys!

I have a table in my program (volatile uint16_t table[261]={12345,23456,3456,3234,etc.}). I'd like to refresh the table with uart communication. I managed to do that but I totally forgot that when I reset the AVR, the table will return with the original data. How can I store the "uart refreshed data"? Here is my code:
 

volatile char received_data[10];
volatile uint16_t table[261]={};
volatile uint16_t i=0;
volatile uint16_t counter=0;

ISR(USART_RX_vect)
{
	char buffer[10];
	
	received_data[counter]=USART_Receive();
	if(received_data[counter]==',')
	{
		received_data[counter]='\0';
		table[i]=atoi(recived_data);
		counter=0;
		i++;
	}
	else
	{
		counter++;
	}
}

 

This topic has a solution.
Last Edited: Tue. Jul 14, 2015 - 07:37 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's pretty much exactly what eeprom memory is there for.  Load your table from eeprom and store it there when it gets updated...just try not to write too frequently or you'll wear it out.

 

https://www.avrfreaks.net/forum/t...

Last Edited: Mon. Jul 13, 2015 - 10:24 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Concur on EEPROM. That is its ideal use.

 

I put data as named members of a struct, and then do EEPROM update. See the AVR-libc manual for details. Its in your Studio installation, I believe.

 

Historically, there have been "problems" with EEPROM address 0x00 but that has been largely alleviated when you use the BrownOut Detector. However, I always add a dummy byte at the start of the struct, "just to be safe". I also add a couple of bytes at the start that tells the program whether or not the EEPROM has been initialized. I often use 0x55 (alternating 0,1,0,1...) for that purpose as it is not likely to appear there by accident. If that value is absent, then I have the program write default values to the EEPROM when it starts.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

You could also place the table into .noinit.  This will survive a reset.  It will not survive a power-cycle.  For that, as suggested, use EEPROM.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Tue. Jul 14, 2015 - 01:47 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks the tip!