Buenos dias:
Resulta que estoy haciendo un programa simple para comunicar un Atmega32 con un Atmega 2560 mediante USART; requiero enviar una trama: 1#1# desde el Atmega32 hacía el Atmega 2560. Al simular en proteus me aparece constantemente el mensaje Rx Frame error y el UDR0 no lee el dato.
Algún consejo?..
Código Atmega32:
Código Atmega2560:
Gracias
Resulta que estoy haciendo un programa simple para comunicar un Atmega32 con un Atmega 2560 mediante USART; requiero enviar una trama: 1#1# desde el Atmega32 hacía el Atmega 2560. Al simular en proteus me aparece constantemente el mensaje Rx Frame error y el UDR0 no lee el dato.
Algún consejo?..
Código Atmega32:
Código:
/*
* eje1_p2.c
*
* Created: 21/05/2015 05:50:17 p.m.
* Author: Flia Burgos
*************NOTE: This file is for ATMEGA-32 which commands the RS232 to ATMEGA-2560**********************
*/
#define F_CPU 16000000UL
#include <avr/io.h>
#include <avr/delay.h>
//Function that send the frame through RS232 protocol
void usart_send(unsigned char data){
while((UCSRA & (1<<UDRE))){ //Waits until the buffer is empty
UDR = data; //Upload the frame to be sent into buffer
}
}
unsigned char car_direction;
unsigned char car_dimension;
unsigned char final_frame;
int main(void)
{
//Ports initialization - PortA (DC) and PortB (TC) will receive the data which will be transmitted through USART
DDRA = 0x00;
PORTA = 0x00;
DDRB = 0x00;
PORTB = 0x00;
//To set up correctly the USART we have to set the PORTD.1 as Output as the Tx is assigned there.
PORTD=0x00;
DDRD=0b00000010;
// USART initialization
// Communication Parameters: 6 Data, 1 Stop, Even Parity
// USART Receiver: Off
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0x08;
UCSRC=0x84;
UBRRH=0x00;
UBRRL=0x67;
while(1)
{
car_direction = PINA;
car_dimension = PINB;
final_frame = car_direction + '#' + car_dimension + '#';
usart_send(final_frame);
}
}
Código Atmega2560:
Código:
/*
* _2560_usart_memory.c
*
* Created: 21/05/2015 07:49:42 p.m.
* Author: Flia Burgos
*******************************This file is for the Atmega-2560, this one receive through RS-232 the frame that will be storage into the RAM, readed and show it up
*/
#define F_CPU 16000000UL
#define MEMORY_OFFSET 0x8000
#define TAM_MEMORY 32768
#include <avr/io.h>
#include <avr/delay.h>
#include "lcd.h"
unsigned char read_buffer;
void SRAMWrite(unsigned char dato){
unsigned char *xMem= (unsigned char *) (MEMORY_OFFSET);
*xMem = dato;
}
unsigned char SRAMread(){
unsigned char valRead;
unsigned char *xMem= (unsigned char *) (MEMORY_OFFSET);
valRead = *xMem;
return(valRead);
_delay_ms(10);
}
unsigned char usar_receiver(){
//Wait for reception flag (bit 7 UCSRA)
while(!(UCSR0A & (1<<RXC0))){
//Do nothing
}
//Now we can read the buffer
return UDR0;
}
int main(void)
{
//Variable
unsigned char data_received;
unsigned char data_to_show;
//Usart configuration
UCSR0A = 0x00;
UCSR0B = 0x10;
UCSR0C = 0x04;
UBRR0H = 0x00;
UBRR0L = 0x67;
//Port initialization for USART
DDRE = 0x00;
PORTE = 0x00;
//PORTL as output for LCD
DDRL = 0x00;
PORTL = 0x00;
lcd_init(LCD_DISP_ON);
lcd_clrscr();
lcd_home();
lcd_puts(" Welcome ");
lcd_gotoxy(0,1);
lcd_puts(" to my exam ");
_delay_ms(100);
lcd_clrscr();
XMCRA = 0x80;
XMCRB = 0x00;
while(1)
{
data_received = usar_receiver();
SRAMWrite(data_received);
data_to_show = SRAMread();
}
}
Gracias