Society of Robots - Robot Forum
Software => Software => Topic started by: olegyef on March 31, 2011, 06:10:22 PM
-
Hello, so i recently got an Axon II and started messing around with it. I'm trying to communicate with Tera Term over the usb, that comes out of the axon. I tried different things for hours and thought id finally ask some one. I know there are built in libraries to make this stuff easier but i wanted to get it working on my own. All i'm getting out of Tera Term is junk. I'm assuming that the rates are some how off but i have no idea how to fix it. Thanks, Oleg.
/*
* test_serial.c
*
* Created: 3/31/2011 1:56:42 AM
* Author: Oleg
*/
#include <avr/io.h>
#include <util/delay.h>
#define FOSC 16000000ul //Clock Speed
#define BAUD 115200
#define MYUBRR (FOSC/16/BAUD-1)
void USART_Init( unsigned int ubrr){
/* Set baud rate */
UBRR1H = (unsigned char)(ubrr>>8);
UBRR1L = (unsigned char) ubrr;
/* Enable receiver and transmitter */
UCSR1B = (1<<RXEN1)|(1<<TXEN1);
/* Set frame format: 8data, 1stop bit */
UCSR1C = (0<<USBS1)|(3<<UCSZ10);
}
void USART_Transmit( unsigned char data )
{
/* Wait for empty transmit buffer */
while ( ( UCSR1A & (1<<UDRE1))==0 );
/* Put data into buffer, sends the data */
UDR1 = data;
}
int main(void)
{
USART_Init (MYUBRR);
while(1){
USART_Transmit('A');
_delay_ms(2000);
}
}
-
Look into webbotlib (http://webbot.org.uk/iPoint/ipoint)for your Axon :)
Also check out the Axon Tutorial (http://www.societyofrobots.com/axon2/axon2_setup1.shtml)on SoR
-
Junk from UART means either mis-matched baud, or on rare chance a *lot* of electrical noise interfering with the UART. On quick glance your code looks fine.
I strongly recommend using WebbotLib . . . but if not, it's still open source and having a look through it could help you pinpoint your mistake in your code.
-
Thanks i think i solved it. The issue was with "#define MYUBRR (FOSC/16/BAUD-1)" at 115.2k it would give me a UBRR of 7 instead of 8. So i just removed the -1 and and it works.