Xbee communication problem

JaniM

Member
Main control unit sends adc-value to other remotecontrol unit via xbees.
Remote control reads value and then writes to lcd.

And the problem:
When I press button in remote control, I think it sends something.
In main unit rssi-led flash then. But I can't read value.
Debug counter don't go, it's in freeze.

In main code row 47 I marked the problem.

If I put that line in program, the main unit don't send anything, I think it waits data from remote control, show value in lcd don't change.
In main unit should put led on when I press button in remote control.

Here are test codes:

Main unit:
Code:
; =================================================
;   File....... Bag_Control_REV.1.0
;   Purpose.... JMG_AirSuspension_CTRL_Main_Unit
;   Author..... JMGarage www.PorVWoo.fi
;   E-mail.....
;   Started.... 07 02 2010
;   Updated.... DD MMM YYYY
;  ===============================================
; -----[ Program Description ]---------------------------------------------


; -----[ Revision History ]------------------------------------------------


; -----[ I/O Definitions ]-------------------------------------------------
let dirsB = %11111111
let dirsD = %11110111
let adcsetup = %0000000011101111

Symbol LFHSen=A.7	'left front wheel height sensor
Symbol XbeeOut=D.7' to Xbee 
Symbol XbeeIn=D.3 'From Xbee 

; -----[ Constants ]-------------------------------------------------------

   


; -----[ Variables ]-------------------------------------------------------
Symbol LFH=w0	'left front wheel height



; -----[ EEPROM Data ]--------------------------------------------------


; -----[ Initialization ]------------------------------------------------------

Init:
high XbeeOut
pause 100

Main:
readadc 7,LFH		'Reads left front wheel height sensor
debug
serout XbeeOut, T2400, ($55,$44,LFH)
'serin XbeeIn,t2400,($55,$44),b20 'HERE IS PROBLEM LINE!!
if b20=1 then high B.0 '[B]led should turn on when button is pressed in remote control[/B]
endif
goto main
; -----[ Interrupt Routines (if used) ]-------------------------------------
; Interrupt:



;           RETURN


; -----[ Subroutines ]-------------------------------------------------------



;           RETURN
And remote control
Code:
; =================================================
;   File....... Bag_Control_REV.1.0
;   Purpose.... JMG_AirSuspension_CTRL_Remote_Panel
;   Author..... JMGarage www.PorVWoo.fi
;   E-mail.....
;   Started.... 07 02 2010
;   Updated.... DD MMM YYYY
;  ===============================================
; -----[ Program Description ]---------------------------------------------


; -----[ Revision History ]------------------------------------------------


; -----[ I/O Definitions ]-------------------------------------------------
let dirsB = %00000001
let dirsD = %11110111
let adcsetup = 0

Symbol XbeeOut=D.3' to Xbee 
Symbol XbeeIn=D.2 'From Xbee
Symbol LCD=D.4    'to LCD 
symbol B_LRH_UP=b0


; -----[ Constants ]-------------------------------------------------------

   


; -----[ Variables ]-------------------------------------------------------
Symbol LFH=w0	'left front wheel height


; -----[ EEPROM Data ]--------------------------------------------------


; -----[ Initialization ]------------------------------------------------------

Init:
pause 5000				'lets start with a short delay shall we?
high LCD				'sets output high for serial display
pause 5				'just to make sure the output is high
serout LCD,t2400,("?G420")	'configure the display as 4x20
Pause 500
serout LCD,t2400,("?f")	      'clear the lcd and home the cursor
pause 500				'and waits for the display to settle
'high backlight			'switch on lcd backlight
serout LCD,t2400,("?B80")
pause 500


Main:
serout LCD,t2400,("?y0?x00JMG AIR SUSP CTRL")'here's the header
serin XbeeOut,t2400,($55,$44),LFH
serout LCD,t2400,("?y2?x00LFH ",#LFH,"cm")'and here's the status
if pinb.7=1 then
b20=1
serout XbeeIn, T2400, ($55,$44,b20)
b20=0
endif
goto main
; -----[ Interrupt Routines (if used) ]-------------------------------------
; Interrupt:



;           RETURN


; -----[ Subroutines ]-------------------------------------------------------



;           RETURN

Xbees setup is from:
http://www.rev-ed.co.uk/docs/axe210_xbee.pdf

Page 9

So how I can send and receive between two xbees and picaxes?
Picaxes what I use are 40x2 3v.
 

Attachments

Last edited:

hippy

Ex-Staff (retired)
The remote only sends a reply back to the main unit when pinB.7=1, you could try commenting out the "if pinb.7=1 then" and corresponding "endif".

Also where you have a "high XbeeOut" in the main unit, you don't have the same initialisation in your remote code. Adding it and a pause will probaby help.

There's also a potential timing issue - The main unit sends to the remote, but the remote has a quite long initialisation time. When the remote comes to receive data from the XBee, what was sent has long gone, the main unit and remote end up both waiting for data to be received which will never come. This is a classic case of 'deadlock'.
 

JaniM

Member
Added comment.
That should turn led on main unit, when you have pressed button in remote control.

So I have to know everytime when I press button.
I need to do something poll/peek prosedure to read xbees buffer.

I added High to remote code and some time to main.
It don't work.
 

hippy

Ex-Staff (retired)
One option is to use timeouts for the SERIN, a better option may be to move XBee comms to using High-Speed Serial, HSERSETUP with background receive.
 

hippy

Ex-Staff (retired)
It may help but I doubt it. The fundamental issue is that you need to synchronise communications.

You can role play this in reality or on paper. If each role player starts at the same time saying SEROUT's and fingers in ears except when waiting on SERIN and keeps to the timing you'll see where SEROUT happens when the other is not doing a SERIN, and when both end up listing for SERIN and neither are speaking.

The best solution may be an initial synchronisation which uses SERIN timeouts on each, and when either loses synchronisation it re-enters that re-syncronisation.
 

JaniM

Member
That hrsersetup would be better solution.

So I need to use hserin/out pins then, if I understand correct that manual.

So xbees talking and adds values to scratspad. The main program looks values when I want.


If I use serin timeouts, the program allways stops there and continues after time outs.

I'll gonna test that timeout before I modify circuit.
 

hippy

Ex-Staff (retired)
Yes, to use HSERIN and HSEROUT the XBee has to be connected to the specific pins; leg 26 (C.7) for HSERIN from XBee, leg 25 (C.6) for HSEROUT to XBee.

SERIN C.7 and SEROUT C.6 can be used when HSERSETUP has not been used so the same hardware can be used no matter what you ultimately decide to do in your software.
 

JaniM

Member
WOW!
It's alive!
I added timeout to serin.
Now I get led on when I pushed button.

Big thanks of helping.

Now I can move on programming code.
 
Top