Receiving doesn't work with Xbee
JChris
Posts: 58
Hello,
I try to exchange data between 2 XBees with propeller C3
I wrote a program with the fullDuplexSerial4port library to use RTS and CTS pins, but the receiving function doesn't work.
My program stops after sending and I don't understand why because when I use FullDuplexSerial library, it works well.
If anyone has a hint I would appreciate
[Code]
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
port = 0
XB_Rx = 0
XB_Tx = 1
XB_CTS = 2
XB_RTS = 6
XB_reset = 7
XB_Baud = 9600
TX_PIN = 2
BAUD = 19_200
VAR
Byte dataSet[120],_RxData[105], DigOffset, Inputbyte, Stringptr[200], mot[105]
Long _SrcAddr16, _RxLen, _RxValue, MY_Addr,stack[200], _srcAddr64_upper, _srcAddr64_lower
Byte _RxFlag,_RxIdent, _RSSIDec, _RxOpt, _RxFrameID, _RxCmd[3], _Status, _FrameID, _API_Ready, _RSSI, _RxOptions
Byte dataIn[255], PacketOut[105], PacketPtr
long _RxADC[6], _RxDig, _RxBit[8], _Temp2
Byte srcAddy[8]
''Bytes needed for TxStatus packet
Byte _RxRetries,_RxDeliveryStatus,_RxDiscoveryStatus
''Bytes needed for normal Rx
Byte _RxChkSum
OBJ
XB : "fullDuplexSerial4port"
pst : "Parallax Serial Terminal"
Pub main | ptr,a
pst.Start(115200)
XB.Init
XB.AddPort(port,XB_Rx, XB_Tx,XB_CTS,XB_RTS,XB_reset, 0, XB_Baud)
XB.Start
mot[0]:= "d"
mot[1]:= "a"
mot[2]:= "m"
mot[3]:= "i"
mot[4]:= "e"
mot[5]:= "n"
mot[6]:= 0
Stringptr[0] := "d"
Stringptr[1] := "a"
Stringptr[2] := "m"
Stringptr[3] := "i"
Stringptr[4] := "e"
Stringptr[5] := "n"
Stringptr[6] := 0
repeat
XB.rxflush(port)
API_str($00000000, $0000FFFF, @stringptr)
pst.str(string("String Sent!"))
API_Rx
waitcnt(clkfreq*2+cnt)
API_Query(String("DB"))
API_Rx
pst.Str(String(pst#NL, "RxIdent est:"))
pst.Hex(_RxIdent,2)
pst.Str(String(pst#NL,"le RSSI est", pst#NL))
pst.Dec(_RxValue)
if(stringCompareCS(@_RxData,@mot) == 0)
API_Str(_srcAddr64_upper, _srcAddr64_lower, @Stringptr)
waitcnt(clkfreq+cnt)
API_Rx
else
pst.str(string(pst#NL, "La comparaison n'est pas bonne", pst#NL))
waitcnt(clkfreq+cnt)
Pub API_Query (cmd)| Length, chars, csum
{{
Sends AT command in API mode to query a parameter value.
Should also be used to set network identifier.
Data is returned as an AT response as a string.
XB.API_Query(string("DL")) ' Query
XB.API_Rx ' accept response
myDL := XB.RxValue ' Get returned value
}}
dataSet[0] := $7E
Length := 4 ' API Ident + FrameID + AT cmd
dataSet[1] := Length >> 8 ' MSB
dataSet[2] := Length ' LSB
dataSet[3] := $08 ' API Ident for AT Command (non queue)
dataSet[4] := $01 ' Frame ID
dataSet[5] := byte[cmd]
dataSet[6] := byte[cmd + 1]
csum := $FF ' Calculate checksum
Repeat chars from 3 to 6
csum := csum - dataSet[chars]
dataSet[7] := csum
Repeat chars from 0 to 7 ' Send data
XB.tx(port,dataSet[chars])
pst.Str(pst#NL)
pst.Dec(dataSet[5])
pst.Dec(dataSet[6])
Pub API_Str(addy64_upper, addy64_lower,donnee)| Length, chars, csum,ptr, stptr, i
{{
Transmit a string to a unit using API mode - 16 bit addressing
XB.API_Str(2,string("Hello number 2")) ' Send data to address 2
TX response of acknowledgement will be returned if FrameID not 0
XB.API_RX
If XB.Status == 0 '0 = Acc, 1 = No Ack
}}
' pst.Str(String(pst#NL))
' pst.str(donnee)
' i := 0
' pst.Str(String(pst#NL))
' Repeat (strsize(donnee))
' pst.Hex(donnee[i++],4)
ptr := 0
stptr := 0
dataSet[ptr++] := $7E
Length := strsize(donnee) + 14 ' API Ident + FrameID + API TX cmd +
' AddrHigh + AddrLow + Options
dataSet[ptr++] := Length >> 8 ' Length MSB
dataSet[ptr++] := Length ' Length LSB
dataSet[ptr++] := $10 ' API Ident for 16-bit TX
dataSet[ptr++] := $00 ' Frame ID
dataSet[ptr++] := addy64_upper >>24
dataSet[ptr++] := addy64_upper >>16
dataSet[ptr++] := addy64_upper >>8
dataSet[ptr++] := addy64_upper
dataSet[ptr++] := addy64_lower >>24
dataSet[ptr++] := addy64_lower >>16
dataSet[ptr++] := addy64_lower >>8
dataSet[ptr++] := addy64_lower
dataSet[ptr++] := $FF
dataSet[ptr++] := $FE
dataSet[ptr++] := $00
dataSet[ptr++] := $00 ' Options '$01 = disable ack,
' $04 = Broadcast PAN ID
Repeat strsize(donnee) ' Add string to packet
dataSet[ptr++] := byte[donnee++]
csum := $FF ' Calculate checksum
Repeat chars from 3 to ptr-1
csum := csum - dataSet[chars]
dataSet[ptr] := csum
i := 0
pst.Str(String(pst#NL))
Repeat ptr+1
pst.Hex(dataset[i++],2)
' pst.Str(String(pst#NL))
' pst.Str(String(dataSet[i++],pst#NL))
pst.Str(String(pst#NL))
Repeat chars from 0 to ptr
XB.tx(port,dataSet[chars]) ' Send bytes to XBee
pst.Str(String("message envoy
I try to exchange data between 2 XBees with propeller C3
I wrote a program with the fullDuplexSerial4port library to use RTS and CTS pins, but the receiving function doesn't work.
My program stops after sending and I don't understand why because when I use FullDuplexSerial library, it works well.
If anyone has a hint I would appreciate
[Code]
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
port = 0
XB_Rx = 0
XB_Tx = 1
XB_CTS = 2
XB_RTS = 6
XB_reset = 7
XB_Baud = 9600
TX_PIN = 2
BAUD = 19_200
VAR
Byte dataSet[120],_RxData[105], DigOffset, Inputbyte, Stringptr[200], mot[105]
Long _SrcAddr16, _RxLen, _RxValue, MY_Addr,stack[200], _srcAddr64_upper, _srcAddr64_lower
Byte _RxFlag,_RxIdent, _RSSIDec, _RxOpt, _RxFrameID, _RxCmd[3], _Status, _FrameID, _API_Ready, _RSSI, _RxOptions
Byte dataIn[255], PacketOut[105], PacketPtr
long _RxADC[6], _RxDig, _RxBit[8], _Temp2
Byte srcAddy[8]
''Bytes needed for TxStatus packet
Byte _RxRetries,_RxDeliveryStatus,_RxDiscoveryStatus
''Bytes needed for normal Rx
Byte _RxChkSum
OBJ
XB : "fullDuplexSerial4port"
pst : "Parallax Serial Terminal"
Pub main | ptr,a
pst.Start(115200)
XB.Init
XB.AddPort(port,XB_Rx, XB_Tx,XB_CTS,XB_RTS,XB_reset, 0, XB_Baud)
XB.Start
mot[0]:= "d"
mot[1]:= "a"
mot[2]:= "m"
mot[3]:= "i"
mot[4]:= "e"
mot[5]:= "n"
mot[6]:= 0
Stringptr[0] := "d"
Stringptr[1] := "a"
Stringptr[2] := "m"
Stringptr[3] := "i"
Stringptr[4] := "e"
Stringptr[5] := "n"
Stringptr[6] := 0
repeat
XB.rxflush(port)
API_str($00000000, $0000FFFF, @stringptr)
pst.str(string("String Sent!"))
API_Rx
waitcnt(clkfreq*2+cnt)
API_Query(String("DB"))
API_Rx
pst.Str(String(pst#NL, "RxIdent est:"))
pst.Hex(_RxIdent,2)
pst.Str(String(pst#NL,"le RSSI est", pst#NL))
pst.Dec(_RxValue)
if(stringCompareCS(@_RxData,@mot) == 0)
API_Str(_srcAddr64_upper, _srcAddr64_lower, @Stringptr)
waitcnt(clkfreq+cnt)
API_Rx
else
pst.str(string(pst#NL, "La comparaison n'est pas bonne", pst#NL))
waitcnt(clkfreq+cnt)
Pub API_Query (cmd)| Length, chars, csum
{{
Sends AT command in API mode to query a parameter value.
Should also be used to set network identifier.
Data is returned as an AT response as a string.
XB.API_Query(string("DL")) ' Query
XB.API_Rx ' accept response
myDL := XB.RxValue ' Get returned value
}}
dataSet[0] := $7E
Length := 4 ' API Ident + FrameID + AT cmd
dataSet[1] := Length >> 8 ' MSB
dataSet[2] := Length ' LSB
dataSet[3] := $08 ' API Ident for AT Command (non queue)
dataSet[4] := $01 ' Frame ID
dataSet[5] := byte[cmd]
dataSet[6] := byte[cmd + 1]
csum := $FF ' Calculate checksum
Repeat chars from 3 to 6
csum := csum - dataSet[chars]
dataSet[7] := csum
Repeat chars from 0 to 7 ' Send data
XB.tx(port,dataSet[chars])
pst.Str(pst#NL)
pst.Dec(dataSet[5])
pst.Dec(dataSet[6])
Pub API_Str(addy64_upper, addy64_lower,donnee)| Length, chars, csum,ptr, stptr, i
{{
Transmit a string to a unit using API mode - 16 bit addressing
XB.API_Str(2,string("Hello number 2")) ' Send data to address 2
TX response of acknowledgement will be returned if FrameID not 0
XB.API_RX
If XB.Status == 0 '0 = Acc, 1 = No Ack
}}
' pst.Str(String(pst#NL))
' pst.str(donnee)
' i := 0
' pst.Str(String(pst#NL))
' Repeat (strsize(donnee))
' pst.Hex(donnee[i++],4)
ptr := 0
stptr := 0
dataSet[ptr++] := $7E
Length := strsize(donnee) + 14 ' API Ident + FrameID + API TX cmd +
' AddrHigh + AddrLow + Options
dataSet[ptr++] := Length >> 8 ' Length MSB
dataSet[ptr++] := Length ' Length LSB
dataSet[ptr++] := $10 ' API Ident for 16-bit TX
dataSet[ptr++] := $00 ' Frame ID
dataSet[ptr++] := addy64_upper >>24
dataSet[ptr++] := addy64_upper >>16
dataSet[ptr++] := addy64_upper >>8
dataSet[ptr++] := addy64_upper
dataSet[ptr++] := addy64_lower >>24
dataSet[ptr++] := addy64_lower >>16
dataSet[ptr++] := addy64_lower >>8
dataSet[ptr++] := addy64_lower
dataSet[ptr++] := $FF
dataSet[ptr++] := $FE
dataSet[ptr++] := $00
dataSet[ptr++] := $00 ' Options '$01 = disable ack,
' $04 = Broadcast PAN ID
Repeat strsize(donnee) ' Add string to packet
dataSet[ptr++] := byte[donnee++]
csum := $FF ' Calculate checksum
Repeat chars from 3 to ptr-1
csum := csum - dataSet[chars]
dataSet[ptr] := csum
i := 0
pst.Str(String(pst#NL))
Repeat ptr+1
pst.Hex(dataset[i++],2)
' pst.Str(String(pst#NL))
' pst.Str(String(dataSet[i++],pst#NL))
pst.Str(String(pst#NL))
Repeat chars from 0 to ptr
XB.tx(port,dataSet[chars]) ' Send bytes to XBee
pst.Str(String("message envoy
Comments
ATD6 = 1 for RTS
ATD7 = 1 for CTS
If they are not initialized, RTS ends up as a high output to the XBee and stops its transmission of data back to the Prop.
The way the port is added is a little puzzling. The XBee reset pin number (7) does not really belong there. That position is for the RTSthreshold, and the above instruction tells the driver to set RTS high (stop sending) when there are 7 characters in the Prop receive buffer. That does not explain the problem though.
Why do you need to use flow control?
I know that I am sending only 7 characters, but after I would like to send more data, e.g. an image. In this perspective I wanted to test RTS and CTS functions.
But I don't understand why the receiving function doesn't work.
Furthermore I use the reset pin because when I move one XBee away from the other one, the communication stops. I want the communication to resume when I bring the remote XBee back to its original location (i.e. both xBees close to each other)
I want to say that XBees work fine for me without any flow control, but I often get dropped packets when rapidly sending data that might get dropped because I'm not using flow control. There's a setting on the XBee somewhere that disables the flow control lines.