Home/Support/Support Forum/Serial communiction between Raspberry Pi 3 and Xbee S2C using SparkFun's Xbee USB dongle
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Serial communiction between Raspberry Pi 3 and Xbee S2C using SparkFun's Xbee USB dongle

0 votes
I am using the Xbee in API mode, the XBee is connected to the SparkFun's XBee explorer dongle (www.sparkfun.com/products/11697). There are multiple of them to create a mesh the implementation is done in C code (show below). The problem is that the dongle lights up showing that it is receiving the data but there is no data being printed when reading from the serial port.

I have checked the frame in XCTU and it is correct. The problem seems to be the sending of the data from the Raspberry pi to the Xbee. I have transmitted data using XCTU to the device to verify that the hardware is working.

The raspberry pi is running the latest version of OS.
uname -a
Linux pi-desktop 4.9.40-v7+ #1022 SMP armv7l GNU/Linux

OS NAME="Ubuntu"
VERSION="16.04.3 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.3 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial


Xbee serial interface configuration:
115200 baudrate
No parity
1 stop bit
3 character times for packetization timeout
CTS flow control is disabled
RTS flow control is disabled
API mode is enabled
API output mode is native

C code:
This part initializes the port

int initport (int fd){
struct termios tty;
memset (&tty, 0, sizeof tty);
if (tcgetattr (fd, &tty) != 0)
{
fprintf(stderr, "error %d from tcgetattr", errno);
return -1;
}
cfsetospeed (&tty, B115200);
cfsetispeed (&tty, B115200);
tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; // 8-bit chars
tty.c_iflag &= ~IGNBRK; // disable break processing
tty.c_lflag = 0; // no signaling chars, no echo,
tty.c_oflag = 0; // no remapping, no delays
tty.c_cc[VMIN] = 0; // read doesn't block
tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout
tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl
tty.c_cflag |= (CLOCAL | CREAD);// ignore modem controls,
tty.c_cflag &= ~(PARENB | PARODD); // shut off parity
tty.c_cflag |= CS8;
tty.c_cflag &= ~CSTOPB;
tty.c_cflag &= ~CRTSCTS;
tty.c_cc[VMIN] = 1;
tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout
if (tcsetattr (fd, TCSANOW, &tty) != 0)
{
fprintf (stderr, "error %d from tcsetattr", errno);
return -1;
}
return 0;
}

This opens the port
int open_port(void){
int fd; /* File descriptor for the port */
fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY| O_SYNC );

if (fd == -1)
{
/* Could not open the port. */
perror("Open_port: Unable to open /dev/ttyUSB0 --- \n");
}
else{
//perror("Connnecte to ttyUSB0 --- \n");
/*{message print....};*/
}
return (fd);
}

The packet we are sending is

unsigned char packet[] = {0x7E, 0x00, 0x13, 0x10, 0x01, 0x00, 0x13, 0xA2, 0x00, 0x41, 0x49, 0x70, 0x48, 0x2F, 0x80, 0x00, 0x00, 0x68, 0x6F, 0x6C, 0x61, 0x21, 0x83};

rt = write(serial, &packet, sizeof packet);


then read is

n1 = read(serial, (void*)read_buf, 1024)



The problem could be in the flags or the configuration of the OS.
If you have any idea or can point me to something that could be helpful it would be greatly appreciated.
asked Aug 9, 2017 in USB Serial by rmuno039 New to the Community (2 points)

Please log in or register to answer this question.

2 Answers

0 votes
The radio indicates that you are sending and receiving. So this is really an issue you need to take to either Sparkfun electronics or your processor manufacture.
answered Aug 9, 2017 by mvut Veteran of the Digi Community (12,761 points)
0 votes
Solution was found in this https://www.digi.com/support/forum/65330/what-does-xctu-perform-while-adding-a-radio-module
answered Jul 25, 2018 by rmuno039 New to the Community (2 points)
...