BS2 to Prop RF communications
I am trying to establish communications between a BS2px and the Prop using·a Parallax 433 MHz RF receiver and matching transmitter but I·am having a little difficulty with the coding on the Prop side of things.·
I have communications working between·2·BS2 stamps from an earlier weather station project so I am pretty sure the·pbasic code is ok.· It is·provided below.
I·am also using my SPIN gps code that is·modified to match the transmitted data, or so I think I do.··The code works·fine with a GPS but not with the RF receiver.· The program does not see the starting delimiter "$" and continues to display·a·series of 12 periods then pauses for ~2.5 seconds then·repeats the cycle.· I do have a 1K resister on the data pin 16 to protect the Prop.· Here is my code
I have changed bit modes in the command RFReceiver.start(16, 17, 0, 9600) to see if that made any difference and when I change it to a 1 or 3 I get continous periods without any pauses.·
Can someone tell me what I am doing wrong between the 2 devices?·
Thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
WWW.HAPB.NET
"Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman
I have communications working between·2·BS2 stamps from an earlier weather station project so I am pretty sure the·pbasic code is ok.· It is·provided below.
Main:
GOSUB Compass_Get_Axes ' Get x, and y values
angle = x ATN -y ' Convert x and y to brads
angle = angle */ 361 ' Convert brads to degrees
COUNT 2, 8710, Counts ' Count cycles on pin 2 for 2.5 seconds
' Counts = MPH
'Scale of vortex is 2.5 mph per revolution per second
PULSOUT 1, 1200 'Sync pulse for the receiver
SEROUT 1, 396, [noparse][[/noparse] "$HAPB", Counts.HIGHBYTE, Counts.LOWBYTE, angle.HIGHBYTE, angle.LOWBYTE, "^"]
GOTO main
I·am also using my SPIN gps code that is·modified to match the transmitted data, or so I think I do.··The code works·fine with a GPS but not with the RF receiver.· The program does not see the starting delimiter "$" and continues to display·a·series of 12 periods then pauses for ~2.5 seconds then·repeats the cycle.· I do have a 1K resister on the data pin 16 to protect the Prop.· Here is my code
CON
_clkmode = xtal1 + pll16x ' use crystal x 16
_xinfreq = 5_000_000 ' 5 MHz cyrstal (sys clock = 80 MHz)
var
byte holder[noparse][[/noparse]8], RFR[noparse][[/noparse]8], index, found
word wSpeed, wDirection
obj
debug: "fullduplexserial" 'Parallax object
RFReceiver: "fullduplexserial"
PUB main
debug.start(31, 30, 0, 9600)
RFReceiver.start(16, 17, 0, 9600) 'Have tried different bit modes
debug.str(string(13,"Starting Program", 13))
repeat
get_RF
debug.str(string(13,"Windspeed..."))
debug.dec(wSpeed)
debug.str(string(13,"Direction..."))
debug.dec(wDirection)
pub get_RF
{{
Procedure captures specific RF signals.
}}
bytefill(@holder, 0, 8)
found := wSpeed := wDirection:= 0
repeat until found == 1
index := 0
repeat while RFReceiver.rx <> "$" 'Wait for the start of the string
debug.tx(46) 'display periods until found
repeat while index < 9
holder[noparse][[/noparse]index++] := RFReceiver.rx 'store the bytes
if holder[noparse][[/noparse]0] == "H" 'check to make sure it is from the correct source
if holder[noparse][[/noparse]1] == "A"
if holder[noparse][[/noparse]2] == "P"
if holder[noparse][[/noparse]3] == "B"
index := 0
repeat until RFR[noparse][[/noparse]index] == "^" 'copy the data
RFR[noparse][[/noparse]index] := holder[noparse][[/noparse]index]
index++
found := 1
repeat index from 4 to 5
wSpeed := wSpeed * 10 + (RFR[noparse][[/noparse]index] - "0") 'Store wind speed
repeat index from 6 to 7
wDirection := wDirection * 10 + (RFR[noparse][[/noparse]index] - "0") 'Store wind direction
I have changed bit modes in the command RFReceiver.start(16, 17, 0, 9600) to see if that made any difference and when I change it to a 1 or 3 I get continous periods without any pauses.·
Can someone tell me what I am doing wrong between the 2 devices?·
Thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
WWW.HAPB.NET
"Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman

Comments
your receiver method is quite complex in that way that many conditions have to be true until everything works
for debugging I would simplify the conditions as much as possible.
This means
first test:
simply receive bytes regardless of their value and echo EVERY byte received on your debug-connection
if this works properly add debugoutput to EVERY stage of your conditions
found := wSpeed := wDirection:= 0 debug.str(string("found := wSpeed := wDirection:= 0")) repeat until found == 1 debug.str(string("repeat until found == 1 is TRUE")) index := 0 repeat while RFReceiver.rx <> "$" 'Wait for the start of the string debug.tx(46) 'display periods until found repeat while index < 9 holder[noparse][[/noparse]index++] := RFReceiver.rx 'store the bytes debug.str(string("holder[noparse][[/noparse]index++] := RFReceiver.rx")) debug.str(string("holder[noparse][[/noparse]")) debug.dec(index - 1) debug.str(string("] =")) debug.tx(holder[noparse][[/noparse]index - 1]) debug.tx(13) if holder[noparse][[/noparse]0] == "H" 'check to make sure it is from the correct source debug.str(string("if holder[noparse][[/noparse]0] == H is TRUE")) if holder == "A" debug.str(string("if holder == A is TRUE")) if holder == "P" 'etc etc. if holder == "B" index := 0 repeat until RFR[noparse][[/noparse]index] == "^" 'copy the data RFR[noparse][[/noparse]index] := holder[noparse][[/noparse]index] index++to see what's happening in detail
best regards
Stefan
con _clkmode = xtal1 + pll16x 'must be used for the Spin stamp pll8x _xinfreq = 5_000_000 'must be used with the Spin stamp 10,000,000 obj debug[noparse][[/noparse]2]: "FullDuplexSerialPlus" 'Debug object pub main Debug[noparse][[/noparse]0].start(31, 30, 0, 9600) 'Start the debug terminal debug[noparse][[/noparse]0].str(string("Starting")) waitcnt(clkfreq + cnt) debug[noparse][[/noparse]1].start(16,17,0,9600) 'Start comm to gps 'I have tried all bit modes repeat debug[noparse][[/noparse]0].tx(debug[noparse][[/noparse]1].rx) 'Receive btye and display 'waitcnt(clkfreq + cnt)and I simplified my BS2 code to send out a simple string
but still it is not working properly.· The prop displays the same garbage·every 2.5 seconds so it seems to be receiving the information.
I wonder if I need to hook up the RF differently with the prop.· Currently I have the data connection going through a 1k resistor connected to pin 16.· The RF unit requires +5v.· I will continue to play.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
WWW.HAPB.NET
"Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman
The object code is so very different that I can not even begin to understand why one works and the other does not.· I am just glad that it is working now.
Thanks and now I can continue with my new project ...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
WWW.HAPB.NET
"Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman