In my earlier question at this link , i asked a question on how to use minicom in linux to communicate between two Xbee's in API mode and got the answer. While i tried the same with XCTU on Windows one one side and AVR + Xbee on the other side,i was able to communicate between 2 Xbee.

On the AVR side, i had written this code to receive the char and store it in string.

#include <yuktix.h>
#include <debug.h>
#include <uart2560.h>
#include <util/delay.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <debug.h>

/*for sensor readings*/
#include <AVRI2C.h>
#include <spi.h>

//char Id;
//char cmd;
static char ch;
static char *frame;
static uint8_t index = 0;
int main(){


    for(int j = 0; j < 1000 ; j++)

    uart_puts(0, " \r \nstarting Xbee Test \r \n");


    while(uart_available(2) > 0){
        KDEBUG("Inside uart_available");
        ch = uart_getc(2);
        KDEBUG("Saving it in frame \n");
        *frame++ = ch;
        KDEBUG("saved in frame \n");
        //if(ch == '\\');
        KDEBUG("COming out of While loop");
       *frame = '\0'; 


As per my last question answer, i am receiving char on the AVR side. As every frame of XBEE API mode start with 7E, where 7E is equivalent to ~, i am receiving it, but some of the chars were unreadable and data which i send in the API frame is totally readable. My question is

  1. How can i store received API frame in a string as my code don't seems to work.
  2. Should i convert the string into HEX via some binary_to_hex code and then parse it , as i need to know from which address this data is coming, what kind of frame it is, what is the number of the bytes in the frame, so that after excluding the source address , i can take out the data.
  3. Am i missing anything. Data on the AVR side will always be in Binary, but how can i process the data?
  • \$\begingroup\$ You define a char pointer called "frame", but don't initiaize it to point anywhere, nor do you reserve any storage to save your received data. \$\endgroup\$ Commented Aug 22, 2015 at 15:47
  • \$\begingroup\$ Other way could be to initialize a char array frame[100]; and then store frame[index++] = ch;?This was also not working. I am not good with coding. Can you help? \$\endgroup\$
    – srj0408
    Commented Aug 24, 2015 at 12:59

1 Answer 1


1) You need to intialize frame as array and it's length is the maximum frame length you may recieve. Now you are only making a pointer which point to one place then you write to bytes after that in RAM and it may cause errors. If you didn't see errors you only get lucky!!

2) Numbers is numbers 1 is the same as (0b00000001) in binary as the same as (0x01) in hex. you only need to compare as you want. For example to compare the start byte you could do one of the followings:

if(frame[0] == 0x7E){
    // Here you are comparing with Hexadicimal

if(frame[0] == 126){
    // Here you are comparing with Decimal

if(frame[0] == 0b01111110){
    // Here you are comparing with Binary

Note that any conditions of the above have the same machine code in AVR. You are only represent the number to yourself.

Also i have some notes on that code:

1) Why are you add statickeyword to ch , *frame , index it has no meaning at all here.

2) For frame it is better to be unsigend char or uint8_t as char alone is signed. intialize as array like uint8_t frame[10];


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.