eeprom

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

I have a very simple USART program to send a charecter to my hyper terminal. I want to copy those charecters into ATMEGA8515's EEPROM. USART is working fine. Could anyone tell me how to copy USART RECEIVED DATA into EEPROM.I tried to use eeprom_write_byte(). But it is not generating the .eep file.Here is my code Is this correct?
USART protocal:2400baudrate, 8 data,1 stop bit, no parity, f_cpu = 1MHZ.

include 
#include 
#include 

#define BAUD_RATE			2400
#define UART_CLOCK_DIVIDER	16
#define UBRR_VALUE 		(((F_CPU/UART_CLOCK_DIVIDER)/BAUD_RATE) - 1)

void SCIInitialize(void)
{
	// Set the baud rate 
	UBRRH = UBRR_VALUE >> 8;
	UBRRL = UBRR_VALUE;
	
	/* Setup the frame format
	 * UCSRC: 
	 *   Bit 7: URSEL   = 1, Not used
	 *       6: UMSEL  = 0, Asynchronous operation
	 *       5: UPM1   = 0, Odd Parity
	 *       4: UPM0   = 0
	 *       3: USBS   = 0  1 stop bit
	 *       2: UCSZ1  = 1, 8 data bits 
	 *       1: UCSZ0  = 1
	 *       0: UCPOL  = 0, Not used for asynchronous mode
	 */

	UCSRC =  _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0) ;
 
	/* UCSRB: 
	 *   Bit 7: RXCIE  = 0, RX interrupt enabled
	 *       6: TXCIE  = 0, TX Complete interrupt disabled 
	 *       5: UDRIE  = 0, Data Reg Empty interrupt disabled. This will be
	 * 						enabled when we're ready to transmit.
	 *       4: RXEN   = 1, Receiver enabled
	 *       3: TXEN   = 1, Transmitter enabled
	 *       2: UCSZ2  = 0, 8 data bits (see UCSRC)
	 *       1: RXB8   = 0, No 9th data bit
	 *       0: TXB8   = 0, No 9th data bit
	 */

	UCSRB  =  _BV(RXEN) | _BV(TXEN);

	/* UCSRA: 
	 *   Bit 7: RXC   = 0, Input
	 *       6: TXC   = 0, Input
	 *       5: UDRE  = 0, Input
	 *       4: FE    = 0, Input
	 *       3: DOR   = 0, Input
	 *       2: UPE   = 0, Input
	 *       1: U2X   = 0, Do not want to double TX rate
	 *       0: MPCM  = 0, No multi-processor mode
	 */
	UCSRA = 0;

}


void tx(unsigned char data)
{
	while ( ( UCSRA & 0x20) == 0);
	
	UDR = data;		
		
}

unsigned char rx()
{
	unsigned char a;
	while ( ( UCSRA & 0x80) == 0);

	return UDR;
}

int main()
{
	unsigned char val = 0;
	DDRB = 0XFF;
	PORTB = 0XFF;
	
	SCIInitialize();

			
	for(;;)
	{
	
	  //tx(rx());	
		eeprom_write_byte((unsigned char*)0x03, (unsigned char)rx());
			}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

eeprom_write_byte does NOT generate any file, it simply writes a byte to the EEPROM.

You need to have eeprom constants in your code in order for a eep file to be generated. ie

	uint8_t EEMEM Timeout_m=0, Timeout_s=30;
	uint8_t EEMEM On_time_h=0x08, On_time_m=0x00;
	uint8_t EEMEM Off_time_h=0x21,Off_time_m=0x00;

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Topic locked