PDA

View Full Version : PIC or xbee times out after Tx 504 bytes



archendekta
- 14th November 2009, 06:09
'###############################################
'#
'# program to test Tx & Rx API packets on
'# xb24 series 1 units.
'#
'# host mcu's= pic16f88
'#
'###############################################


'---[set fuses]---------------------------------

'Program Configuration Register 1
@ __CONFIG _CONFIG1, _HS_OSC & _DEBUG_OFF & _WDT_ON & _LVP_OFF & _CP_ALL & _CPD_ON & _BODEN_ON & _MCLR_ON & _PWRTE_ON & _WRT_PROTECT_OFF

;Program Configuration Register 2
@ __CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF



'---[includes----]-------------------------------

INCLUDE "bs2defs.bas"


'---[debug defines]-------------------------------

DEFINE DEBUG_REG PORTA
DEFINE DEBUG_BIT 2
DEFINE DEBUG_BAUD 9600
DEFINE DEBUG_MODE 1

'---[defines]--------------------------------------

DEFINE OSC 8

'DEFINE HSER_RCSTA 90h
DEFINE HSER_RCSTA 92h ' Enable serial ports Tx & Rx, sets SPEN & CREN & OERR
DEFINE HSER_TXSTA 24h ' Enable Tx HS, TXEN=1 & BRGH=1
DEFINE HSER_BAUD 9600 ' set baud and compiler will auto calc HSER_SPBRG
DEFINE HSER_CLROERR 1 ' Clear overflow automatically


ANSEL=0
ADCON0=0
ADCON1=7
CMCON=7

'---[contants]---------------------------------------

LF CON 10
CR CON 13
MAX_DATA_LEN CON 12


'-----------------------------------------------------------------------

BLINK_PA1 VAR portA.1
BLINK_PB1 VAR portB.1 'to show sending serial data

TX_APIPacket VAR byte[14]
Counter VAR byte
Checksum VAR byte
Ndx VAR byte




'-----------------------------------------------------------------------

INIT:
Clear
gosub FILL_API_PACKET



MAIN:
FOR counter=0 to 35
gosub sub_Test_Tx_API_Frame
next counter
goto MAIN



sub_Test_Tx_API_Frame:
gosub sub_CALC_Checksum

'send debug to realterm window
Debug "TX= ",str TX_APIPacket\13," ", hex checksum, " [Cnt: ",dec counter,CR

hserout [str TX_APIPacket\13, checksum]
gosub sub_BLINK_PB1 'show pic is alive
pause 500
RETURN



FILL_API_PACKET:
TX_APIPacket(0)=$7E
TX_APIPacket(1)=$00
TX_APIPacket(2)=$0A
TX_APIPacket(3)=$01
TX_APIPacket(4)=$01 'API frame ID
TX_APIPacket(5)=$50 'DL addr
TX_APIPacket(6)=$01 'DL addr
TX_APIPacket(7)=$00 'option
TX_APIPacket(8)=$48 'H
TX_APIPacket(9)=$65 'E
TX_APIPacket(10)=$6c 'L
TX_APIPacket(11)=$6c 'L
TX_APIPacket(12)=$6f 'O
RETURN


sub_CALC_Checksum:
Checksum = 0
for Ndx = 3 to MAX_DATA_LEN
Checksum = Checksum + TX_APIPacket(Ndx)
next
Checksum = $FF & Checksum 'remove values > 1 byte
Checksum = $FF - Checksum '2's compliment
RETURN


sub_BLINK_PA1:
High BLINK_PA1
pause 200
low BLINK_PA1
PAUSE 200
RETURN


sub_BLINK_PB1:
High BLINK_PB1
pause 200
low BLINK_PB1
PAUSE 200
RETURN


END




mcu=pic16f88
xbee=xb24

i'm sending a string then checksum from the host pic16f88 to a xbee and that xbee sends it to another xbee. somewhere around 34-35 iterations for a total of 504 bytes the xbee's stop sending/recieving.

the pic is still sending the string out as i can see this with a LCD
connected to the Tx pin on the sending host.

Now, i can use two xbib dev boards connected to my computer with one of the xbee's on each and send the same API packet with no issues.

so i'm leaning towards the problem is my pic16f88 or my program/fuses or both.

any thoughts on why this is happening?

thx
archendekta

archendekta
- 19th November 2009, 08:39
finally got the setup to work.

can't say for sure what exactly what was causing the problem. reflashed all the xbee's to their default and reset a few parameters and all is working fine.

code was fine and the pic's were fine.

Ioannis
- 19th November 2009, 11:04
From a very preliminary test I did, the receiver of the XBees is very susceptible to saturation. I had to move the modules 10-15 meters away to work properly. I know this seems irrelevant ot your case but just keep it in mind.

Ioannis

P.S. Are you going to make a ZigBee network?

archendekta
- 20th November 2009, 03:23
the distance factor could have been an issue and one to keep in mind. thanks.

i have the xbp24-zb's for another project for a ZB network.

this current one is using the "802.15.4 series I" xbee's.

i wonder if there is a config parameter that helps with the saturation issue for short distances? would you know?

Ioannis
- 20th November 2009, 07:08
Just drop the RF power to the minimum. But ifdistance is less that 5 meters the receivers are saturated again.

Ioannis

archendekta
- 22nd November 2009, 07:10
0= -10dBm
1= -6dBm
2= -4dBM
3= -2dBm
4= 0dBm

so with these 802.15.4 series I, lowest would be -10dBm, yes?

good to know, thx

Ioannis
- 23rd November 2009, 08:45
Yes, that's right

Ioannis