I tried porting this simple program that echos a character sent over the UART from GCC to IAR. I have attached my attempt. It recieves the character fine, but it doesn't get echoed back. Any ideas?
Problem with a simple UART program
Could this line, from usart.c be the problem?
UCSR0B = (1<<RXEN0)|(0<<TXEN0)|(0<<RXCIE0)|(0<<UDRIE0);
Note the (0<<TXEN)
Could this line, from usart.c be the problem?UCSR0B = (1<<RXEN0)|(0<<TXEN0)|(0<<RXCIE0)|(0<<UDRIE0);Note the (0<<TXEN)
it works great now! thanks a bunch for finding my silly mistake :shock: :oops:
Now I have a new problem. sprintf doesn't seemt to want to work. The program is supposed to print a stream of random 1s and 0s to the terminal. Main now looks like:
__C_task void main(void) { char c; int num; // Program initalization Initialization(); for (;;) // Main loop { num = rand() & 1; // Set num to either 1 or 0 sprintf(&c, "%d", num); // Print num to c Usart_Tx(c); } //End Main loop }
The problem is that c never changes from '1'! Going through the AVR studio simulator, it shows that while num DOES change randomly between 1 and 0, c never seems to be changed at all. What could be the causes of this? Also, sprintf seems to be very finicky, I had to quadruple the stack sizes to even get it to work. Is this normal?
One more thing, when programming my butterfly using AVRProg, the same memory address always fails to verify. Is it toast? How can that affect the results that I'm seeing?
If you're expecting to see the characters you might want to convert them to ASCII first. If all you want are '0' and '1', there are a lot faster ways than sprintf to do it. Such as:
Usart_Tx((rand() & 1) + 0x30);
Dave
If you're expecting to see the characters you might want to convert them to ASCII first. If all you want are '0' and '1', there are a lot faster ways than sprintf to do it. Such as:Usart_Tx((rand() & 1) + 0x30);Dave
Any ideas on my sprintf weirdness for the future though?
Well, for one thing, sprintf works on strings which are a sequence of one or more characters terminated by a NULL. That's a lot to try and stuff in to a "char" which is one byte.
Dave
Well, for one thing, sprintf works on strings which are a sequence of one or more characters terminated by a NULL. That's a lot to try and stuff in to a "char" which is one byte.Dave
__C_task void main(void) { char c[2]; int num; // Program initalization Initialization(); for (;;) // Main loop { num = rand() & 1; sprintf(c, "%d", num); Usart_Tx(c[0]); } //End Main loop }
Still does the all 1's thing. :?