Picaxe & Xbee

mandsanda

New Member
Hi,

I am trying to enter command mode on a XBee module using the hserout command - with no success.

I am using the following code:

Code:
hSerSetup B2400_4, %00	'foreground receive
pause 5000

'put dummy data into scratchpad
put 0, "#","#","#","#"

ptr = 0
hserptr = 0
b0 = 0

get_RF_id:
	
	inc b0
	hserout 0, ("try no.:",#b0,CR,LF)
	
        pause 10000                               'allow plenty of quiet time
	hserout 0,("+++")				'send cmd characters
	hserin [10000, get_RF_id], 0,2	'should get an "OK" response
	pause 10000						'allow plenty of time to exit cmd mode
	
	ptr = 0
	hserout 0, (@ptrinc,@ptrinc,@ptrinc,@ptr,CR,LF)	'send what should be "OK##"
	
	goto get_RF_id
I have tried foreground & background receive modes. I have varied the pause times and I have run simple test programs that send and receive data perfectly OK.

But I want to remotely get the Xbee serial number and I need to get into command mode to retreive it - which I cannot seem to do.

Previously, on another board, I was not using hardware serial and with the serout and serin commands it worked OK. Now that I have migrated to hardware serial in an attempt to get a higher baud rate, I can't seem to enter command mode.

Has anyone else achieved this or is there some issue I am not aware of?

Any help appreciated.

Cheers
 

Dippy

Moderator
I haven't inspected your code in great detail and I've just had a quick look at some non-PICAXE code for XBee (series1) ...

You should send +++ and wait for "OK"
Then send your AT command.

In your code you seem to do the +++ and wait for Serin with timeout and then a 10 second pause.
This could mean that XBee pops out of AT mode. I can't remember exact timeout figure.

And you are set up for default XBee serial speed aren't you?
There's no point me posting my code as it isn't rel here.
 

mandsanda

New Member
Picaxe -Xbee

Yes that is correct. All I am trying to do right now is get the '+++' accepted by the Xbee, the Xbee to enter command mode and reply with 'OK'. The hserin command should capture the 'OK' and then due to the long pause time, automatically come out of command mode and transmit the reply.

But I never seem to get into command mode.
 

Dippy

Moderator
I should be a diplomat...so just in case...

"And you are set up for default XBee serial speed aren't you?".....

Have you changed from the default 9600 somwhere?
 

mandsanda

New Member
Picaxe-Xbee

The Xbee interface data rate is set for 2400.

I can enter command mode when attached to the PC no problems. I can send and receive no problems. I just can't seem to get into command mode from the Picaxe.
 

Dippy

Moderator
How have you set it to 2400? Has that baud rate been 'saved' in XBee?

What is your electrical connection between PICAXE an Xbee?
How are they powered?
Have you done anything odd to upset the serial polarity?

Post an EXACT schematic.
I'll leave it to others as the Grand Prix is on.
 

hippy

Ex-Staff (retired)
Which PICAXE ? If an X1 then B2400_4 is correct, but if an X2 then default operating speed is 8MHz so that should be B2400_8.

I would personally try background receive; send the "+++" and simply capture all data the data which comes back from the XBee and report that to the PC via SERTXD. Perhaps send the "+++" on a button push or interrupt.
 

Grogster

Senior Member
Which PICAXE ? If an X1 then B2400_4 is correct, but if an X2 then default operating speed is 8MHz so that should be B2400_8.

I would personally try background receive; send the "+++" and simply capture all data the data which comes back from the XBee and report that to the PC via SERTXD. Perhaps send the "+++" on a button push or interrupt.
I agree 100% - this is the first thing I do, if I can't get a response from some serial device correctly.

Essentially, hook up your hserout line to the Xbee(remember to use the potential divider if you are using 5v PICAXE voltage, so you don't cook the 3v CMOS input pins on the Xbee which are NOT 5v tolerant...), and the serial out from the Xbee via a MAX232 or MAX202 level-corrector/inverter to the PC or laptop, issue the commands via the PICAXE, and look at the response on the PC/Laptop.

If there is no response, either the 232/202 corrector is wired incorrectly, or the Xbee does not like the taste of the commands from the PICAXE.

After a lot of mucking around, I built a 232/TTL corrector as a seperate PCB, and it has been invaluable for testing things like this.

Once you can be sure that you are getting some kind of response on the PC/Laptop, then you can at least know for sure that the expected data is forthcoming from the Xbee.

If me, I would hserout 0,("+++"), hserin 0,3 this will get you to the first "OK" from the Xbee, then hserout 0,("ATSN"), hserin 0,10, get 0,b1,b2,b3,b4,b5,b6 - however many bytes the serial number is.

I will try this on the bench later and post back.
 

mandsanda

New Member
Picaxe - Xbee

Thanks

I am using a 28x1.

The TX line is divided to 3.3 volts.

I have tried similar code with background receive & still get nothing.

I know the tx/rx is working as I am sending/receiving normal data OK both in foreground and background modes.

When the Xbee is placed in a commercial USB board, the "+++" works fine (@2400) from the PC. The board I am trying to get working only has serial out via the Xbee.

I may have to get the breadboard out & try the sertxd route.
 

Dippy

Moderator
Got a 'scope? Check i/o.
(Could also be done with care with LEd+res)

Have you calculated your divider correctly?

Have you got Tx and Rx lines back to front?
(THis is why a schematic is so handy).

I have used XBees with PICs USART a lot and have had no probs, so electrically it should work.
 

hippy

Ex-Staff (retired)
Finally found time to get the XBee's out and everything wired up. This works for me ...

Code:
#Picaxe 20X2
#No_Data
#No_Table
#Terminal 9600

HSerSetup B9600_8, %001

Pause 5000

SerTxd( "Send +++",CR, LF )
HSerOut 0,( "+++" )

Do
  If hSerPtr <> ptr Then
    SerTxd( #@ptr, " ", @ptr, CR, LF )
    If @ptr = CR Then
      SerTxd( "Send ATVR",CR, LF )
      HSerOut 0,( "ATVR", CR )
    End If
    ptr = ptr+1
  End If
Loop
Sends +++ to enter command mode, receives OK<CR> back. When the <CR> is received an ATVR<CR> is sent to request firmware version, which for me returns "800", no <CR> so nothing more sent. Change ATVR<CR> to just AT<CR> to get a continuous OK<CR> coming back.
 

Attachments

Top