FullDuplexSerial Rx coding question and the uOLED-96
JMLStamp2p
Posts: 259
Good Evening,
I was having problems monitoring Tx outgoing serial data on my scope untill I changed to PLL8X and everything started reading fine. I need a little help using the Rx method, I would like to recieve a byte of· data, store it in·the varible Byte_Recieved and then jump to a paticular OBJ based on the byte recieved. I am using pin 21 as my recieve line and 20 for Tx. How is the best way to represent data coming into the OLED-96 ? And is all data in ASCI until interpeted differently ?
Regards,
JMLStamp2p
John.
'...........................................................................................
My code so far:
'...........................................................................................
{{OLED_Transmit_Test.spin}}
CON
· _CLKMODE····· = XTAL1 + PLL8X·······················
· _XINFREQ····· = 8_000_000
· dSlow········ = 50
· dFast········ = 20
OBJ
· OLED· : "uOLED-96-Prop_V4"
· DELAY : "Clock"
· DATA : "FullDuplexSerial"
VAR
· long Stack [noparse][[/noparse]9]
· byte Byte_Recieved
·
PUB MAIN
· DELAY.Init(8_000_000)
· OLED.InitOLED
· OLED.CLS
· REPEAT
··· Transmit
··· Recieve
······
PUB Transmit
· data.start(21,20,%1000,9600)················ 'rx pin = 21 : tx pin = 20 : mode : baud rate
· data.tx(1)
· delay.PauseSec(2)
· data.tx(2)
· delay.PauseSec(2)
· data.tx(4)
· delay.PauseSec(2)
· data.tx(8)
· delay.PauseSec(2)
· OLED.PutPixel(46,30, 0,255,0)····················· ' Put a GREEN pixel at x:0, y:63
· DELAY.PauseSec(1)
· OLED.CLS
· DELAY.PauseSec(1)
'............................................................................................................
'Need help here.
'............................................................................................................
PUB Recieve
·REPEAT
· data.start(21,20,%0001,9600)··············· 'Check mode bit(4), echo off on Tx
· data.rx·························································· ' ???
· If Byte_Recieved := (01)
·· Pixels·····························································' Jump to OBJ Pixels if data recieved was (01)
· If Byte_Recieved := (02)
·· Rectangles
··
··
I was having problems monitoring Tx outgoing serial data on my scope untill I changed to PLL8X and everything started reading fine. I need a little help using the Rx method, I would like to recieve a byte of· data, store it in·the varible Byte_Recieved and then jump to a paticular OBJ based on the byte recieved. I am using pin 21 as my recieve line and 20 for Tx. How is the best way to represent data coming into the OLED-96 ? And is all data in ASCI until interpeted differently ?
Regards,
JMLStamp2p
John.
'...........................................................................................
My code so far:
'...........................................................................................
{{OLED_Transmit_Test.spin}}
CON
· _CLKMODE····· = XTAL1 + PLL8X·······················
· _XINFREQ····· = 8_000_000
· dSlow········ = 50
· dFast········ = 20
OBJ
· OLED· : "uOLED-96-Prop_V4"
· DELAY : "Clock"
· DATA : "FullDuplexSerial"
VAR
· long Stack [noparse][[/noparse]9]
· byte Byte_Recieved
·
PUB MAIN
· DELAY.Init(8_000_000)
· OLED.InitOLED
· OLED.CLS
· REPEAT
··· Transmit
··· Recieve
······
PUB Transmit
· data.start(21,20,%1000,9600)················ 'rx pin = 21 : tx pin = 20 : mode : baud rate
· data.tx(1)
· delay.PauseSec(2)
· data.tx(2)
· delay.PauseSec(2)
· data.tx(4)
· delay.PauseSec(2)
· data.tx(8)
· delay.PauseSec(2)
· OLED.PutPixel(46,30, 0,255,0)····················· ' Put a GREEN pixel at x:0, y:63
· DELAY.PauseSec(1)
· OLED.CLS
· DELAY.PauseSec(1)
'............................................................................................................
'Need help here.
'............................................................................................................
PUB Recieve
·REPEAT
· data.start(21,20,%0001,9600)··············· 'Check mode bit(4), echo off on Tx
· data.rx·························································· ' ???
· If Byte_Recieved := (01)
·· Pixels·····························································' Jump to OBJ Pixels if data recieved was (01)
· If Byte_Recieved := (02)
·· Rectangles
··
··
Comments
Data is received (as it is transmitted) as a sequence of byte values. If you want them to be readable ASCII characters, you have to provide for that. For transmitting, you can use the dec / hex / bin / str methods. For receiving, you can use the Extended FullDuplexSerial object to process the received data for you (somewhat).
The uOLED-96-Prop requires PLL8X for proper operation and a crystal frequency (_XINFREQ) of 8MHz.
I just need help with the Spin coding for the Rx method as far as saving the incoming byte in the varible (Byte_Recieved). If you would please look at the PUB Recieve method below, I want to compare the incoming Recieved Byte and Jump to the method Pixels if I have recieved a (1) or Jump to method Rectangles if I have recieved a (2). I used the Tx method just to monitor the transmission to make sure that _CLKMODE = XTAL1 + PLL8X was going to work for me. All I want is to run PUB Recieve in a loop, test the incoming Byte and jump to a paticular method based on the Byte recieved.
Thanks again for your advise,
JMLStamp2p
CON
_CLKMODE = XTAL1 + PLL8X
_XINFREQ = 8_000_000
dSlow = 50
dFast = 20
OBJ
OLED : "uOLED-96-Prop_V4"
DELAY : "Clock"
DATA : "FullDuplexSerial"
VAR
byte Byte_Recieved
PUB MAIN
DELAY.Init(8_000_000)
OLED.InitOLED
OLED.CLS
PUB Recieve
data.start(21,20,%1000,9600)
REPEAT
data.rx
Byte_Recieved := data.rx 'Please adjust this code if not correct ...
If Byte_Recieved := (1)
Pixels
If Byte_Recieved := (2)
Rectangles
If (Byte_Recieved == 1)
Pixels
If (Byte_Recieved == 2)
Rectangles
You have to use "==" for compare, ":=" to set/equate. Takes some getting used to.
Adoy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
One's true identity can only be learned through reflection.
You do need to use the code brackets so that the message editor doesn't adjust the spacing: