Proto board Serial Communications
rporter
Posts: 3
I'm new to spin so this may be a very simple question - can you designate two pins (tx, rx) on two seperate protoboards and have them pass information using FullDuplexSerial?· I've tried to send a character (7) to another board with no success.· I'm not trying anything complicated, I just want to pass info between the two boards.· Printing to the LCD works fine but no matter what I do I can't recieve the data I'm transmitting.· I've posted my test code below:
Board 1 - transmitting board:
OBJ
· Link········· : "FullDuplexSerial"
···
PUB Main
'
' Main
'
· ' Start the serial communications to·board 2
· Link.Start(9, 8, 0, 9600)
· ' Blink LED
·· Blink
·· Repeat
······ ProcessCommand
PRI ProcessCommand
· Link.tx(7)···
PRI Pause_ms(msDelay)
· waitcnt(cnt + ((clkfreq / 1000) * msDelay))
PRI Blink
· dira[noparse][[/noparse]Pin_Led]~~···
· outa[noparse][[/noparse]Pin_Led]~~
· Pause_ms(100)
· outa[noparse][[/noparse]Pin_Led]~
Board 2 - Receiving board:
PUB Init
'
' Initialize
'
· ' Initialize the LCD
· Lcd.start(Pin_Lcd, 19200, 2)························· ' start lcd
· Lcd.cursor(2)········································ ' cursor off
· Lcd.cls
· Lcd.home
· Lcd.backLight(true)·································· ' backlight on (if available)
' Start the serial communications to the board 1
· Link.Start(8, 9, 0, 9600)
·
· ' Initialize speaker
· Speaker.Init(Pin_Speaker)
· Speaker.Beep(500,500)
·· ' Initialize and blink LED
· Blink
· Pause_ms(1000)
· Lcd.str(string("Testing"))
· Repeat
···· Ready
PRI Ready | char, pid, b
··· Link.rxflush
··· pid := 0
··· if (char := Link.rxcheck) => 0
····· if char == 19
······· b := Link.rxtime(100)
······· repeat while b > 0
········· pid := Link.rxtime(100)
········· b--
· Lcd.clrln(0)
· Lcd.gotoxy(0,0)
· Lcd.dec(char)
· Lcd.clrln(1)
· Lcd.gotoxy(0,1)
· Lcd.dec(pid)
· Pause_ms(200)
PRI Pause_ms(msDelay)
· waitcnt(cnt + ((clkfreq / 1000) * msDelay))
PRI Blink
· dira[noparse][[/noparse]Pin_Led]~~···
· outa[noparse][[/noparse]Pin_Led]~~
· Pause_ms(100)
· outa[noparse][[/noparse]Pin_Led]~
·······
Board 1 - transmitting board:
OBJ
· Link········· : "FullDuplexSerial"
···
PUB Main
'
' Main
'
· ' Start the serial communications to·board 2
· Link.Start(9, 8, 0, 9600)
· ' Blink LED
·· Blink
·· Repeat
······ ProcessCommand
PRI ProcessCommand
· Link.tx(7)···
PRI Pause_ms(msDelay)
· waitcnt(cnt + ((clkfreq / 1000) * msDelay))
PRI Blink
· dira[noparse][[/noparse]Pin_Led]~~···
· outa[noparse][[/noparse]Pin_Led]~~
· Pause_ms(100)
· outa[noparse][[/noparse]Pin_Led]~
Board 2 - Receiving board:
PUB Init
'
' Initialize
'
· ' Initialize the LCD
· Lcd.start(Pin_Lcd, 19200, 2)························· ' start lcd
· Lcd.cursor(2)········································ ' cursor off
· Lcd.cls
· Lcd.home
· Lcd.backLight(true)·································· ' backlight on (if available)
' Start the serial communications to the board 1
· Link.Start(8, 9, 0, 9600)
·
· ' Initialize speaker
· Speaker.Init(Pin_Speaker)
· Speaker.Beep(500,500)
·· ' Initialize and blink LED
· Blink
· Pause_ms(1000)
· Lcd.str(string("Testing"))
· Repeat
···· Ready
PRI Ready | char, pid, b
··· Link.rxflush
··· pid := 0
··· if (char := Link.rxcheck) => 0
····· if char == 19
······· b := Link.rxtime(100)
······· repeat while b > 0
········· pid := Link.rxtime(100)
········· b--
· Lcd.clrln(0)
· Lcd.gotoxy(0,0)
· Lcd.dec(char)
· Lcd.clrln(1)
· Lcd.gotoxy(0,1)
· Lcd.dec(pid)
· Pause_ms(200)
PRI Pause_ms(msDelay)
· waitcnt(cnt + ((clkfreq / 1000) * msDelay))
PRI Blink
· dira[noparse][[/noparse]Pin_Led]~~···
· outa[noparse][[/noparse]Pin_Led]~~
· Pause_ms(100)
· outa[noparse][[/noparse]Pin_Led]~
·······
Comments
(b) You configured to 80 MHz, didn't you?
(c) It is difficult upto impossible to sync to a continuesly transmitting source using an asynchronious protocol - make pauses from time ti time when transmitting
I removed the buffer flush as you suggested.
Both boards are configured to 80MHz
I added a 100ms delay on the tx
SUCCESS!! I can't thank you enough, this problem was driving me crazy and your suggestions did the trick.