xbee and atmega16l - help needed

I’m trying to get the range test to work in x-ctu with an xbee module and an atmega16L. I’m using codevision to program the chip.

Here’s what I’m working with:

xbee: http://www.sparkfun.com/commerce/produc … ts_id=8664

usb explorer: http://www.sparkfun.com/commerce/produc … ts_id=8687

for remote chip logic shift: http://www.adafruit.com/index.php?main_ … 4d8e5e1cde

I updated both xbee chips to version 10CD. I left all settings default except PANID = 25 and BD = 19200 for both chips.

The code I used in my Atmega is:

#include <stdio.h>
#include <mega16.h>

void main(void)
{       
        unsigned char num;
  
        UCSRA=0x00; //clear control and status register
        UBRRL = 12; //set the Baud Rate at 19200
        UBRRH = 0;                             
        UCSRB = 0x18; //enable the transmitter and receiver
        UCSRC = 0x86; //8-data bits, no parity, 1-stop bit  
        
        DDRA =  (DDRA & 0x00);
        PORTA = (PORTA | 0xFF);
        DDRB =  (DDRB & 0x00);
        PORTB = (PORTB | 0xFF);
        DDRC =  (DDRC & 0x00);
        PORTC = (PORTC | 0xFF);
        DDRD =  (DDRD & 0x00);
        PORTD = (PORTD | 0xFC);
                 
        while(1)
        {
                scanf("%c", &num);
                printf("%c", num);
        }
}

I also attempted connecting Dout to Din of the remote xbee with the atmega removed, but was unable to get any response on my computer with the range test or the command: atci12. However, the red data LED came on the adafruit breakout board, leading me to think the remote xbee was receiving data.

This is my first attempt at xbee. Any help would be appreciated.

baud rate constant

12 decimal. Is 19,200baud if the AVR’s oscillator is 4MHz. That’s unusually low.

Also, check AVR’s fuse settings: internal versus external crystal.

Before using stdio such as printf and scanf, you have to provide I/O routines for the UART and hook them to the stdio calls.

Better for you to start by not using stdio until later. Try not to use them on a small micro because of the RAM you lose to stdio buffering, and the large code size of printf and scanf and its subordinates. Mega16 is a low end micro.

See examples of UART IO on avrfreaks.net forum’s projects section. One ready to use code set is

http://www.avrfreaks.net/index.php?modu … tem_id=563

and there are many others there.

Best to learn how to UART I/O on the AVR by connecting that serial port to an RS232 level shifter then that to a PC’s serial port or USB to serial adapter. Then use a dumb terminal program on the PC. This simplifies things.

The micro is running on an internal 4MHz oscillator. I will bump it up. I will try some of your tweaks, thank you!

Without looking at the datasheets right now to verify it, as I am working on something else right now, I was able to short out the din/dout pins on the remote chip and was able to use x-ctu to perform a successful range test.

Before, I was running all my signals through the logic shifter, so I can’t be certain that the 3.3V acts as a high for the buffer on Ada’s daughter board. However, bypassing the buffer and just shorting out the pins worked.

The Atmega was running at 5V, so the 3.3V signals from the xbee may not have been enough to act as a high input to the chip. I will eventually have to look this up in the datasheet to verify it.