Shop OBEX P1 Docs P2 Docs Learn Events
Calling FullDuplexSerial with different parameters. — Parallax Forums

Calling FullDuplexSerial with different parameters.

JMLStamp2pJMLStamp2p Posts: 259
edited 2008-02-11 15:49 in Propeller 1
Hello all, The Code below is working but wanted advise on calling FullDuplexSerial. I am calling it initially with data.start(1,0,2,9600)·
and then later in PUB LCD_Recieve with parameters as data.start(3,2,0,19200). Is this going to cause problems somewhere else later on as
I learn more and my code gets more complicated ? I am communicating between two Propellers via trancievers on each. The transmitting end sends a "1" and the recieving end replys back with a "1" which jumps to LCD_Recieve. LCD_Recieve·then calls FullDuplexSerial with a different Baud rate·and different parameters.
........................................
My Code below:
........................................
CON
·_CLKMODE = XTAL1 + PLL8X···
·_XINFREQ = 5_000_000········

VAR
·long Stack[noparse][[/noparse]9]
·byte Temp
·
OBJ
·DELAY: "Clock"
·DATA: "FullDuplexSerial"
...........................................................................................
PUB Main

·dira[noparse][[/noparse]16]~~
·dira[noparse][[/noparse]23]~~

·data.Stop················· · 'Stop any outside call to the OBJ data

·data.start(1,0,2,9600)·· 'Set-up Serial Protocall
············································ 'to handle tranciever communication on

·········································· · 'pins 0 & 1 @ 9600 Baud

·Power_up_Reset········· · · 'Power-on reset transmission via Cog-0
·Recieve······················· ·'Cog-0 jumps to handle the Recieve Method
·...........................................................................................

PUB Power_up_Reset
· waitcnt(160_000_000 + cnt)·· 'Wait 2-Sec's after power-on to ...
· !outa[noparse][[/noparse]16]························· ·· 'Togle LED-16
· waitcnt(30_000_000 + cnt)
· !outa[noparse][[/noparse]16]
· waitcnt(30_000_000 + cnt)
· data.tx(1)···························'(1) is the reset code sent out the tranciever

..........................................................................................
PUB Recieve | rxbyte

· repeat
······················
··· rxbyte := data.rx
··· if rxbyte == 1
····· LCD_Recieve
··
·················
··· if rxbyte == 2······················································
····· Data_Recieved_2
····
··· if rxbyte == 4············
····· Data_Recieved_4
..................................................
·
PUB LCD_Recieve | rxbyte
·dira[noparse][[/noparse]3]~····························
·dira[noparse][[/noparse]2]~~
·················
· data.start(3,2,0,19200)············'Call to FullDuplexSerial but with
·························································'different parameters & Baud rate

· data.tx(254)········································ · ' Command prefix
· data.tx(88)·········································· · ' Command to clear screen
· data.str(string(" Sloss Industries", 13, 10))
· data.str(string("Quenching Station", 13, 10))
· data.str(string("Instrument Shop", 13, 10))

.................................................................................................
···············
·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-08 17:26
    When you call FullDuplexSerial's start routine, it internally calls the stop routine. The main thing to be concerned about is that the transmit routine is buffered and may not have finished transmitting the contents of the transmit buffer. You could add a routine to FullDuplexSerial to wait until the transmit buffer is empty and call that before calling the start routine or you could just add a WAITCNT with a sufficient delay to ensure that all has been sent.

    If you really want to have two serial ports, you can declare two objects, both "FullDuplexSerial". The compiler will include only one copy of the object code and will create two data areas, each around 70 bytes. When running, each object will use a cog for the assembly routine to run and they'll function completely independently.

    Post Edited (Mike Green) : 2/8/2008 5:33:04 PM GMT
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2008-02-08 17:51
    Mike, Do you mean to literally do a copy of FullDuplexSerial and paste it in my application as FullDuplexSerial again ?
    JMLStamp2p
    John.
  • HarleyHarley Posts: 997
    edited 2008-02-08 18:17
    JMLStamp2p said...
    Mike, Do you mean to literally do a copy of FullDuplexSerial and paste it in my application as FullDuplexSerial again ?

    How about something like this in the OBJ section:

    OBJ
      FDS1     : "FullDuplexSerial"
      FDS2     : "FullDuplexSerial"
    
      FDSn     : "FullDuplexSerial"
    
    PUB Main
    ' your program follows.....
    
    


    Ya, too simple?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Harley Shanko
  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-08 18:20
    You can also have an array of objects like:
    OBJ
       fds[noparse][[/noparse] 3 ] : "FullDuplexSerial"
    
    PUB Main
       fds[noparse][[/noparse] 0 ].start( .... )
       fds[noparse][[/noparse] 1 ].start( .... )
    
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2008-02-11 15:49
    Thanks guys, that helps.
    JMLStamp2p
Sign In or Register to comment.