Blazemaguire
Senior Member
Yes.. back again! - Now i've figured out the XRF module problems (see recent post, and thanks BTW) i'm trying to get communication both ways (the final step in my master plan)
My intention for the code below is:
(as per my previous post) - Transmit an incrementing variable from chip 1 to chip 2 and display it on the OLED LCD screen
When the number received is between 125 and 255, send a signal back to chip 1 that is recognized and will light 1 LED and then turn off another LED on the chip 1 circuit.
When the number received at chip 2 is between 0 and 124, send a different signal to chip 1 that will make the LEDs flip back the other way - I've got two 'indicator' LEDs also on chip 2 that do the same thing for chip 2 (just to show me that part of the code is working really...)
My problem is that the serrin command on chip 1's code appears to 'hang' the program. and it just stops all transmission either in or out. - If I delete the 'serin' line of code (Line 15) on chip 1, then I get one way comms back again and the LCD updates with the incrementing variables.
Am I doing something obviously wrong? - chip 2 doesn't seem to get 'hung' going between serin and serout... why does chip 1? - Do I need some kind of 'handshake' ... remember, i'm a noob at all this serial lark!
Using a 20x2
Chip 1 code
'this programme is 'chip 1'
init:
setfreq m16 ' configure chip to 16mhz mode
pause 1000
b1=1 ' Declare starting point of count
main:
inc B1
high b.5 'Set transmission pin high (improve data tranfer)
serin b.6,T9600_16,b5 'read in value to b2
if b5=2 then 'if a '2' is recieved then...
high C.0 'Light LED indicator 1
low C.1 'Turn off LED indicator 2
else if b5=1 then 'if a '1' is recieved then...
high C.1 'Light LED indicator 2
Low C.0 'Turn off LED Idicator 1
else
pause 100 'time between sending output pulses to Chip 2
serout b.5,T9600_16,(b1) 'transmit variable through XRF to chip 2
goto main
endif
Chip 2 Code
'this programme is 'chip 2'
init:
setfreq m16 'config chip to 16mhz mode
serout b.7,N2400_16,(254,1) ;clear LCD
main:
high b.6
serin b.6,T9600_16,b1 ; Read in wireless serial into b1
serout b.7,N2400_16,(254,128) ;Goto line 1, pos 1 of LCD
serout b.7,N2400_16,(#b1) ; write variable B1
if b1=255 or b1=0 or b1=1 then
serout b.7,N2400_16,(254,1) ;clear LCD
pause 100
else if b1>125 and b1<255 then
serout b.5,T9600_16,(1) 'send code to chip 1 to light LED1 and turn off LED2
high c.0 low c.1
else
serout b.5,T9600_16,(2) 'send code to chip 1 light LED2 and turn off LED 1
endif
goto main
My intention for the code below is:
(as per my previous post) - Transmit an incrementing variable from chip 1 to chip 2 and display it on the OLED LCD screen
When the number received is between 125 and 255, send a signal back to chip 1 that is recognized and will light 1 LED and then turn off another LED on the chip 1 circuit.
When the number received at chip 2 is between 0 and 124, send a different signal to chip 1 that will make the LEDs flip back the other way - I've got two 'indicator' LEDs also on chip 2 that do the same thing for chip 2 (just to show me that part of the code is working really...)
My problem is that the serrin command on chip 1's code appears to 'hang' the program. and it just stops all transmission either in or out. - If I delete the 'serin' line of code (Line 15) on chip 1, then I get one way comms back again and the LCD updates with the incrementing variables.
Am I doing something obviously wrong? - chip 2 doesn't seem to get 'hung' going between serin and serout... why does chip 1? - Do I need some kind of 'handshake' ... remember, i'm a noob at all this serial lark!
Using a 20x2
Chip 1 code
'this programme is 'chip 1'
init:
setfreq m16 ' configure chip to 16mhz mode
pause 1000
b1=1 ' Declare starting point of count
main:
inc B1
high b.5 'Set transmission pin high (improve data tranfer)
serin b.6,T9600_16,b5 'read in value to b2
if b5=2 then 'if a '2' is recieved then...
high C.0 'Light LED indicator 1
low C.1 'Turn off LED indicator 2
else if b5=1 then 'if a '1' is recieved then...
high C.1 'Light LED indicator 2
Low C.0 'Turn off LED Idicator 1
else
pause 100 'time between sending output pulses to Chip 2
serout b.5,T9600_16,(b1) 'transmit variable through XRF to chip 2
goto main
endif
Chip 2 Code
'this programme is 'chip 2'
init:
setfreq m16 'config chip to 16mhz mode
serout b.7,N2400_16,(254,1) ;clear LCD
main:
high b.6
serin b.6,T9600_16,b1 ; Read in wireless serial into b1
serout b.7,N2400_16,(254,128) ;Goto line 1, pos 1 of LCD
serout b.7,N2400_16,(#b1) ; write variable B1
if b1=255 or b1=0 or b1=1 then
serout b.7,N2400_16,(254,1) ;clear LCD
pause 100
else if b1>125 and b1<255 then
serout b.5,T9600_16,(1) 'send code to chip 1 to light LED1 and turn off LED2
high c.0 low c.1
else
serout b.5,T9600_16,(2) 'send code to chip 1 light LED2 and turn off LED 1
endif
goto main
Code: