Reputation: 51
I am trying to send a hexadecimal data over UART to my AVR. The problem is, I can't send more than two pair of hex. I need to send more than two, like 9-10.
For example:
I could only send 0x2f
and 0x3f
.
If I send more than that, its always minus.
I need to send 0xff234f3a3f
.
My code:
sendString("wish me luck\n");
while(1)
{
char str[35];
int i;
printf("enter the code :\n");
scanf("%x", &i);
printf("%#x (%d)\n",i,i);
}
What did I do wrong?
Upvotes: 2
Views: 2656
Reputation: 111
You can achieve this by storing the data you wish to send in a software buffer and as soon as avr sends the 1byte of uart data fill the uart register with the byte from Software buffer. You can do something like this:-
char ar[] = "hello";
for (i = 0; i < strlen(ar); i++) {
while ((UCSR0A & (1<<UDRE0)) == 0);
UDR0 = ar[i];
}
Hope this helps
Upvotes: 1
Reputation: 387
AVR UART has a size limitation as it is in embedded environment so the UART buffer is only 8/16 bits . You are able to send 2 bytes of data , to send more you need to make a loop to send the remaining data bytes.
Upvotes: 0