Help with XB and the FullDuplexSerial4 object
Im experimenting with my XB modules and have come across an inconsistency that has me puzzled.
If I use the DIO and FDS4 objects through a wired port the method SimpleDecimalReceiveFDS4_PST below works just fine even with multiple digit entries.
If, however, I try and take the same approach with the XB using SimpleDecimalReceiveFDS4_XB the program hangs waiting for the first entry?
Any ideas?
Thank You,
Steve
If I use the DIO and FDS4 objects through a wired port the method SimpleDecimalReceiveFDS4_PST below works just fine even with multiple digit entries.
If, however, I try and take the same approach with the XB using SimpleDecimalReceiveFDS4_XB the program hangs waiting for the first entry?
Any ideas?
Thank You,
Steve
CON
_clkmode = xtal1 + pll16x
'_clkfreq = 80_000_000
_xinfreq = 5_000_000
PST = 0 ' Port for Communication to PST
' LCD = 1 ' Port for Communication to LCD Tx only
GPSPort = 2 ' Port for Communication to GPS Rx only
XB1 = 3 ' Port for Xbee1
XB2 = 0
PST_BAUD = 9_600 ' PST baud rates, debug to terminal
LCD_BAUD = 19_200 ' LCD baud rate
GPS_BAUD = 9_600 ' GPS baud rate
XB1_BAUD = 9_600 ' XB Baud Rate
XB2_BAUD = 9_600 ' XB Baud Rate
' BT_BAUD = 115_200 ' BT baud rate
'Pin Assignements:
' BTTx = 0 'Tx Pin for Blue Tooth Module run in View Port
' BTRx = 1 'Rx Pin for Blue Tooth Module run in View Port
XB1Tx = 0 'XB DOut
XB1Rx = 1 'XB DIN Pin
XB2Tx = 6 'XB DOut
XB2Rx = 7 'XB DIN Pin
ServoPinX = 4
ServoPinY = 2
LCD_TXPIN = 4 ' LCD Tx pin
LCD_RXPIN = -1 ' LCD Rx pin THERE IS NONE
GPS_TXPIN = 14 ' GPS Tx
GPS_RXPIN = 15 ' GPS Rx pin
PST_TXPIN = 30 ' PST Tx Pin
PST_RXPIN = 31 ' PST Rx Pin
CR = 13
VAR
Long X, Y, Z
word Stack[50]
OBJ
servo: "servo32v7"
FDS4: "FullDuplexSerial4port"
dio : "dataIO4port"
FDS: "FullDuplexSerialPlus"
XB: "XBee_Object"
Pub Initialization |index
servo.start 'Start Servo Object
Start_Uarts 'Starts FDS4port Object in its own cog.
pause(1000)
SimpleDecimalReceiveFDS4_XB
Pub SimpleDecimalReceiveFDS4_XB | Value
Pause (3000)
FDS4.str(XB1,string("Awaiting Data...")) 'Notify base
FDS4.tx(XB1,CR)
Repeat
FDS4.str(XB1,string(13,"Enter First Value: ")) '
Value:=dio.DecIn(XB1) 'Wait for and accept decimal value
FDS4.str(XB1,string(13,"Value entered: "))
Dio.dec(XB1,Value)
FDS4.str(XB1,string(13,"Enter Second Value: "))
Value:= Value + dio.DecIn(XB1)
FDS4.str(XB1,string(13,"Total Entered: "))
dio.dec(XB1,Value)
FDS4.tx(XB1,CR) 'Send CR to Base
Pub SimpleDecimalReceiveFDS4_PST | Value
Pause (3000)
FDS4.str(pst,string("Awaiting Data...")) 'Notify base
FDS4.tx(pst,CR)
Repeat
FDS4.str(pst,string(13,"Enter First Value: "))
Value:=dio.DecIn(PST) 'Wait for and accept decimal value
FDS4.str(pst,string(13,"Value entered: "))
Dio.dec(pst,Value)
FDS4.str(pst,string(13,"Enter Second Value: "))
Value:=Value + dio.DecIn(PST) 'Wait for and accept decimal value
FDS4.str(pst,string(13,"Total Entered: "))
Dio.dec(pst,Value)
FDS4.tx(PST,CR) 'Send CR to Base
PUB start_uarts
'' port 0-3 port index of which serial port
'' rx/tx/cts/rtspin pin number #PINNOTUSED = -1 if not used
'' prop debug port rx on p31, tx on p30
'' cts is prop input associated with tx output flow control
'' rts is prop output associated with rx input flow control
'' rtsthreshold - buffer threshold before rts is used #DEFAULTTHRSHOLD = 0 means use default=buffer 3/4 full
'' note rtsthreshold has no effect unless RTS pin is enabled
'' mode bit 0 = invert rx #INVERTRX bit mask
'' mode bit 1 = invert tx #INVERTTX bit mask
'' mode bit 2 = open-drain/source tx #OCTX bit mask
'' mode bit 3 = ignore tx echo on rx #NOECHO bit mask
'' mode bit 4 = invert cts #INVERTCTS bit mask
'' mode bit 5 = invert rts #INVERTRTS bit mask
'' baudrate desired baud rate, e.g. 9600
fds4.init ' sets up and clears the buffers and pointers, returns a pointer to the internal fds4 data structure
' always call init before adding or starting ports.
'****IMPORTANT NOTE: TURN OFF PST PORT IF YOU PLAN TO USE VIEW PORT.****
fds4.AddPort(XB1,XB1Tx,XB1Rx,-1,-1,0,0,XB1_BAUD)
fds4.AddPort(XB2,XB2Tx,XB2Rx,-1,-1,0,0,XB2_BAUD)
fds4.AddPort(PST, PST_RXPIN, PST_TXPIN,-1,-1,0,0,PST_BAUD) ' debug to the terminal screen, without flow control, normal non-inverted mode
' fds4.AddPort(LCD, LCD_RxPIN, LCD_TXPIN,-1,-1,0,0,LCD_BAUD) ' Sends data to LCD screen
' fds4.AddPort(GPSPort, GPS_RxPIN, GPS_TXPIN,-1,-1,0,0,GPS_BAUD) ' Receive data from GPS
' port 1, 2, 3 are not used. The order that you define ports does not matter. You don't have to do anything to set up unused ports
fds4.Start
pause(1000) ' delay to get going before sending or receiving any data
PUB PAUSE(Duration) | cntS 'Liberated from BSLite
cntS:=cnt
repeat ||Duration
waitcnt(cntS+=clkfreq/1000)

Comments
Look within the method "StrInMax". If it says uarts.rx(0), BUG alert!, change it to uarts.rx(port) as highlighted.
[SIZE=1][COLOR=#020FC0][FONT=courier new]PUB StrInMax(port, stringptr, maxcount) | char, ticks {{from PST, modified Receive a string of characters (either carriage return terminated or maxcount in length) and stores it (zero terminated)starting at stringptr. Waits until either full string received or maxcount characters received.}} maxcount <#= MAXSTR_LENGTH repeat maxcount if (byte[stringptr++] := [B]uarts.rx([/B][/FONT][B][FONT=courier new]port[/FONT][/B][FONT=courier new][B])[/B]) == NL quit [/FONT][/COLOR][/SIZE][SIZE=1][COLOR=#020FC0][FONT=courier new]byte[stringptr+(byte[stringptr-1] == NL)]~ [/FONT][/COLOR][/SIZE]Regards
Steve