kgavionics
Full Member level 3
- Joined
- Jun 12, 2012
- Messages
- 167
- Helped
- 7
- Reputation
- 14
- Reaction score
- 11
- Trophy points
- 1,298
- Location
- Alberta.Canada
- Activity points
- 2,482
Hello guys
I'm trying to send a string of characters from my Pc to an Atmega328, and It works if I send a character at a time, but not a string (I get missing characters)!
I know that the problem is due to LCD routine that takes too much time and the UDR0 gets overwritten several times!
Can someone give me a heads-up how can I store the UDR0 register into the string, so I can send it once it's completely received to the LCD?
This is my code:
I'm trying to send a string of characters from my Pc to an Atmega328, and It works if I send a character at a time, but not a string (I get missing characters)!
I know that the problem is due to LCD routine that takes too much time and the UDR0 gets overwritten several times!
Can someone give me a heads-up how can I store the UDR0 register into the string, so I can send it once it's completely received to the LCD?
This is my code:
C:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
unsigned char rc,i;
#define FOSC 16000000 // Clock Speed
#define BAUD 9600
#define MYUBRR FOSC/16/BAUD -1
int main(void)
{
/*Set baud rate */
UBRR0H = (MYUBRR >> 8);
UBRR0L = MYUBRR;
UCSR0B |= (1 << RXEN0) | (1 << TXEN0); // Enable receiver and transmitter
UCSR0B |= (1 << RXCIE0); // Enable reciever interrupt
UCSR0C |= (1 << UCSZ01) | (1 << UCSZ00); // Set frame: 8data, 1 stp
LCDinit();//init LCD bit, dual line, cursor right
LCDclr();//clears LCD
LCDcursorOFF();
while(1)
{
while (! (UCSR0A & (1<<RXC0)));
rc=UDR0;
LCDsendChar(rc);
}
retrun (0);
}
Thank you in advance!