Hello. I send data packets from one Xbee S1 to another. When a packet bigger than 64 bytes is sent there is lost of data. I use readPacket() method from Arduino library (run in every 20ms). There is also a method called available() which returns number of bytes in buffer. I print this value and what I see is that until any data is received it returns always 0 (this is normal), but if data is sent buffer immediately is equal to size of sent packets.
So if I send a packet of size 20 -> serial buffer goes immediately from 0 to 20
If I send a packet of size 80 -> serial buffer goes immediately from 0 to 64 and causes loss of data
From my knowledge reading should start when there is any data, not when whole data packet is in serial buffer, then buffer will be not overflowed. I tried setting Xbee which sends data to 9600 baud rate(thought that then data will be sent slower so receiver will have much more time for processing, but it wont help).
My configuration:
Xbee S1(sender - coordinator):
Firmware: 10ec
API: 2
No encryption
Baudrate: 57600
Xbee S1(receiver - end device)
Firmware: 10ec
API: 2
No encryption
Baudrate: 57600
I tried to use simplified version of code.
Every two seconds I send a message:
Send start: 7e 00 50 01 01 ff ff 00
Payload: 05 00 01 03 84 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 7d 31 12 7d 33 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 03
#include
XBee xbee = XBee();
uint8_t start_data[] = { 0x7E, 0x00, 0x50, 0x01, 0x01, 0xff, 0xff,
0x00, 0x05, 0x00, 0x01, 0x03, 0x84, 0x00 };
void setup()
{
Serial.begin(57600);
}
void loop()
{
for( int i = 0; i < 14; i++)
{
Serial.write(start_data[i]);
}
for( int i = 1; i < 70; i++)
{
Serial.write(i);
}
Serial.write(0x03);
delay(2000);
}
For receiving I tried with code:
#include
XBee xbee = XBee();
void setup()
{
Serial.begin(57600);
Serial1.begin(57600);
}
void loop()
{
Serial.print("Serial: ");
Serial.println(Serial1.available(), DEC);
if (Serial1.available() > 0)
{
char c = Serial1.read();
Serial.print("Read: ");
Serial.println(c, HEX);
}
}
Output is:
...
Serial: 0
Serial: 0
Serial: 0
Serial: 0
Serial: 0
Serial: 1
Read: 7E
Serial: 23
Read: 0
Serial: 45
Read: 50
Serial: 63
Read: FFFFFF81
Serial: 63
Read: 12
Serial: 62
Read: 35
Serial: 61
Read: 1A
Serial: 60
Read: 2
Serial: 59
Read: 5
Serial: 58
Read: 0
Serial: 57
Read: 1
Serial: 56
Read: 3
Serial: 55
Read: FFFFFF84
Serial: 54
Read: 0
Serial: 53
Read: 1
Serial: 52
Read: 2
Serial: 51
Read: 3
Serial: 50
Read: 4
Serial: 49
Read: 5
Serial: 48
Read: 6
Serial: 47
Read: 7
Serial: 46
Read: 8
Serial: 45
Read: 9
Serial: 44
Read: A
Serial: 43
Read: B
Serial: 42
Read: C
Serial: 41
Read: D
Serial: 40
Read: E
Serial: 39
Read: F
Serial: 38
Read: 10
Serial: 37
Read: 7D
Serial: 36
Read: 31
Serial: 35
Read: 12
Serial: 34
Read: 7D
Serial: 33
Read: 33
Serial: 32
Read: 14
Serial: 31
Read: 15
Serial: 30
Read: 16
Serial: 29
Read: 17
Serial: 28
Read: 18
Serial: 27
Read: 19
Serial: 26
Read: 1A
Serial: 25
Read: 1B
Serial: 24
Read: 1C
Serial: 23
Read: 1D
Serial: 22
Read: 1E
Serial: 21
Read: 1F
Serial: 20
Read: 20
Serial: 19
Read: 21
Serial: 18
Read: 22
Serial: 17
Read: 23
Serial: 16
Read: 24
Serial: 15
Read: 25
Serial: 14
Read: 26
Serial: 13
Read: 27
Serial: 12
Read: 28
Serial: 11
Read: 29
Serial: 10
Read: 2A
Serial: 9
Read: 2B
Serial: 8
Read: 2C
Serial: 7
Read: 2D
Serial: 6
Read: 2E
Serial: 5
Read: 2F
Serial: 4
Read: 30
Serial: 3
Read: 31
Serial: 2
Read: 32
Serial: 1
Read: 3C
Serial: 0
Serial: 0
Serial: 0
Serial: 0
Serial: 0
...
So it can’t read with the same speed as it is sent… even if both devices are configured for the same baud rate… I also tried to add 500 ms delays between Serial.write() on sender side and IR value on XBees to 0x64(100ms) and 0x0C(200ms), but problem still occured…
Thank you in advance