Exchanging data between two props
As the topic says, I'm currently trying to exchange some data from a master prop to a slave prop (ran out of cogs). I've downloaded the inter-prop communication object and the modified serial object from the forums and am having no luck with them whatsoever. I'm definitely not grasping some concept here. If I put some dummy data in say...
shouldnt it send it out? I'm getting nothing at the receiving side. I'm not worried about speed, and my main loop is updating every second, so is there an easier way to send a set of numbers, say the time in military (HHMMSS-> 171832) from one prop to the other? Can I just initialize full duplex serial on both cogs and push data through somehow that way? Below is the code I've altered slightly. Thanks in advance.
Full Code Master
Full Code slave
Post Edited (teddyp) : 4/9/2010 12:39:35 PM GMT
DataOut:=$55 TX(@DataOut) 'Transmit Data Packet
shouldnt it send it out? I'm getting nothing at the receiving side. I'm not worried about speed, and my main loop is updating every second, so is there an easier way to send a set of numbers, say the time in military (HHMMSS-> 171832) from one prop to the other? Can I just initialize full duplex serial on both cogs and push data through somehow that way? Below is the code I've altered slightly. Thanks in advance.
Full Code Master
CON 'Constant definition block
_clkmode = xtal1 + pll16x 'Using PLL, set frequency to 80MHz
_xinfreq = 5_000_000 'Input Crystal frequency. Dev board is 5MHz
TX_Pin = 11
PacketSize = 1024 '<- Number of Packet Longs to transmit ; 1 Long = 32 data Bits
OBJ 'Object definition block
display : "TV_Text" 'Reference TV_Text object
VAR
long DataOut[noparse][[/noparse]PacketSize] 'Variable definition block
PUB Main
display.start(12) 'Start display on pin 12
display.out(CLS) 'Clear screen
display.str(string("Serial test")) 'test
WaitCnt(cnt + clkfreq*2) 'delay
display.out(CLS) 'Clearscreen
repeat 'Repeat forever
DataOut:=$5555_5555
TX(@DataOut) 'Transmit Data Packet
waitcnt(cnt + clkfreq) 'Wait one clock cycle and repeat
' waitcnt(cnt + clkfreq * 2) 'Wait 2 clock cycles and repeat
PUB TX(_DataOut)
cognew(@TX_Propeller_COM,_DataOut) 'Send Data
DAT
TX_Propeller_COM org
mov TX_PinMask, #1 'Create Pin Mask for Input/Output pin
shl TX_PinMask, #TX_Pin
andn outa, TX_PinMask 'Preset Pin LOW
or dira, TX_PinMask 'Make Pin an Output LOW
mov DataIndex, par 'Read Data Location into DataIndex
LoadData rdlong Buff, DataIndex 'Read Data Value from Indexed location
add DataIndex, #4 'Increment Index value
nop
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
or outa, TX_PinMask 'Make Pin HIGH (50nS) SYNC
andn outa, TX_PinMask 'Make Pin LOW (50nS) SYNC
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
rol Buff, #1 wc 'Read Buff Bit31 into "C" ; Rotate Buff left by 1
muxc outa, TX_PinMask 'Make Pin HIGH or LOW (100nS) DATA
nop
andn outa, TX_PinMask 'Make Pin LOW (750nS)
djnz DataSamples, #LoadData 'Check to see if there are more data samples
andn dira, TX_PinMask 'Make Pin an Input
cogid temp 'Get this COG ID
cogstop temp 'STOP this COG
'initialized variables
DataSamples long PacketSize
'un-initialized variables
DataIndex long 0
Buff long 0
'aliased variables
temp
TX_PinMask long 0
Full Code slave
CON 'Constant definition block
_clkmode = xtal1 + pll16x 'Using PLL, set frequency to 80MHz
_xinfreq = 5_000_000 'Input Crystal frequency. Dev board is 5MHz
CLS = $0 'Clear screen
RX_Pin = 3
PacketSize = 1024 '<- Number of Packet Longs to receive ; 1 Long = 32 data Bits
OBJ 'Object definition block
display : "TV_Text" 'Reference TV_Text object
VAR 'Variable definition block
long rcvddata
long DataIn[noparse][[/noparse]PacketSize],ReadyFlag '<-ReadyFlag must follow immediately after the Data
PUB Main | rx_buff, i, seed, v
display.start(12) 'Start display on pin 12
display.out(CLS) 'Clear screen
displayString(1,3, string("serial comm test"))
WaitCnt(cnt + clkfreq) 'delay some
display.out(CLS)
rcvddata := RX(@DataIn)
repeat 'Repeat forever
display.str(string("testdata: "))
display.str(rcvddata)
waitcnt(cnt + clkfreq) 'Wait one clock cycle and repeat
rcvddata := RX(@DataIn)
' waitcnt(cnt + clkfreq * 2) 'Wait 2 clock cycles and repeat
PUB RX(_DataIn)
ReadyFlag := 1 'Read Data
cognew(@RX_Propeller_COM,_DataIn)
repeat while ReadyFlag == 1 'Wait here until data is ready
DAT
RX_Propeller_COM org
mov DataIndex, par 'Read Data Location into DataIndex
mov RX_PinMask, #1 'Create Pin Mask for Input/Output pin
shl RX_PinMask, #RX_Pin
SYNC_Start waitpeq RX_PinMask, RX_PinMask 'Wait for SYNC - HIGH
waitpne RX_PinMask, RX_PinMask 'Wait for SYNC - LOW
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
test RX_PinMask, ina wc 'Read RX pin into "C"
rcl Buff,#1 'Rotate Buff left and place "C" in Bit0
wrlong Buff, DataIndex 'Write Data Value to Indexed location
add DataIndex, #4 'Increment Index value
djnz DataSamples, #SYNC_Start'Check to see if there are more data samples
mov temp, #0 'Clear the Ready Flag
wrlong temp, DataIndex
cogid temp 'Get this COG ID
cogstop temp 'STOP this COG
'initialized variables
DataSamples long PacketSize
'uninitialized variables
DataIndex long 0
Buff long 0
'aliased variables
temp
RX_PinMask long 0
Post Edited (teddyp) : 4/9/2010 12:39:35 PM GMT

Comments
Hi, welcome to the forum!
just a few things in the code...
For both: - the TX(master) and RX(slave), the number of packets you are sending I reduced to 1 since the test data that you are sending is only the length of a LONG. - for the attached code I moved the RX and TX pins to pin 7 ... this just works better with my setup on this end. You should be able to use whatever pins you want. The TX(master): - is fine, the way it is, no big changes... The RX(slave): - the received data is automatically placed into [b]DataIn[/b] so there is no need to define a second variable [b]rcvddata[/b] - instead of trying to display the data with [b]display.str(rcvddata)[/b], use [b]display.str(@DataIn)[/b] instead▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 4/9/2010 4:47:36 AM GMT
Incidentally, do you mind adjusting the comment for long DataOut[noparse][[/noparse]PacketSize] in your original post, ATM it's hard to read your post when you have to scroll horizontally.
Post Edited (kuroneko) : 4/9/2010 1:12:09 PM GMT
Thank you so much for the reply. I will be implementing your recommendations very shortly. I have been playing with the code you wrote for this and the object for inter-prop communication and was wondering if I was even sending the data right. The seed was throwing me off, but I believe I understand that concept now. Just generating the "random" string to send data for testing.
@kuroneko,
Thanks for the info too. It does seem to be my receive system. Also, thanks for pointing out that comment. I was wondering why it was 80 screens wide and was checking, but I missed that comment somehow. Fixed now... I hope.
Thanks again you two. I love these parallax forums, you guys are really helpful here and quick with responses.
-ted