I have having some problems with making two XBEE Series 1 stay in communications.
I am running them at 115200 baud rate to transfer real time audio across the link.
I have it setup to run without 802.15.4 ACKS to make the latency very low.
One Xbee is connected to an XBee USB explorer and the other is connected to an Arduino.
The audio quality is pretty good but then it suddenly stops playing after between 5 and 90 seconds and I need to unplug and reconnect the TX XBee and restart the sender application before it will link up again until it stops working again.
Here is the sender code (very ugly):
#include <stdio.h>
#include <fcntl.h>
#include <windows.h>
int main(){
// Open the serial port.
HANDLE hPort = CreateFile ("COM6", // Pointer to the name of the port
GENERIC_READ | GENERIC_WRITE,
// Access (read-write) mode
1, // Share mode
NULL, // Pointer to the security attribute
OPEN_EXISTING,// How to open the serial port
0, // Port attributes
NULL); // Handle to port with attribute
// to copy
DCB PortDCB;
// Initialize the DCBlength member.
PortDCB.DCBlength = sizeof (DCB);
// Get the default port setting information.
GetCommState (hPort, &PortDCB);
// Change the DCB structure settings.
PortDCB.BaudRate = 115200; // Current baud
PortDCB.fBinary = TRUE; // Binary mode; no EOF check
PortDCB.fParity = FALSE; // Enable parity checking
PortDCB.fOutxCtsFlow = TRUE; // No CTS output flow control
PortDCB.fOutxDsrFlow = FALSE; // No DSR output flow control
PortDCB.fDtrControl = DTR_CONTROL_ENABLE;
// DTR flow control type
PortDCB.fDsrSensitivity = FALSE; // DSR sensitivity
PortDCB.fTXContinueOnXoff = FALSE; // XOFF continues Tx
PortDCB.fOutX = FALSE; // No XON/XOFF out flow control
PortDCB.fInX = FALSE; // No XON/XOFF in flow control
PortDCB.fErrorChar = FALSE; // Disable error replacement
PortDCB.fNull = FALSE; // Disable null stripping
PortDCB.fRtsControl = RTS_CONTROL_ENABLE;
// RTS flow control
PortDCB.fAbortOnError = FALSE; // Do not abort reads/writes on
// error
PortDCB.ByteSize = 8; // Number of bits/byte, 4-8
PortDCB.Parity = NOPARITY; // 0-4=no,odd,even,mark,space
PortDCB.StopBits = ONESTOPBIT; // 0,1,2 = 1, 1.5, 2
// Configure the port according to the specifications of the DCB
// structure.
SetCommState (hPort, &PortDCB);
CloseHandle(hPort);
char buf[32];
long x;
FILE *snd = fopen("C:\\thq.wav", "rb");
FILE *ser = fopen("COM6", "wb");
while(!feof(snd)){
fread(&buf, 32, 1, snd);
fwrite(&buf, 32, 1, ser);
for(x = 0;x < 2000;x++){asm("nop");}
}
}
and the receiver code:
void setup(){
Serial.begin(115200); //Begin serial link to XBee
pinMode(11, OUTPUT);
TCCR2B = TCCR2B & 0b11111000 | 0x1; //Enable fast PWM
}
void loop(){
if(Serial.available()){analogWrite(11, Serial.read());} //Play samples as we get them
}
I really do not understand why the Xbee keeps needing to be reset.
Thanks in advance.