Shop OBEX P1 Docs P2 Docs Learn Events
Extended Full Duplex serial w/ multiple instances (array of objects) — Parallax Forums

Extended Full Duplex serial w/ multiple instances (array of objects)

Chicago MikeChicago Mike Posts: 88
edited 2008-01-27 21:11 in Propeller 1
I'm trying to run two serial ports independently, both however using extended_full duplex serial. So I'm trying to have multiple instances of this object.... After reviewing the prop manual, I noticed that you can call build an array of the same object, so I gave that a shot (As shown below). (Please ignore the "//" below. I can't seem to display array references in this forum text editor without it, they are not there in real code).

OBJ
  serial[noparse][[/noparse]//1]  : "Extended_FDserial"

PUB Main | input1, input2
  serial[noparse][[/noparse]//0].start(1,2,%0000,9600)  
  serial[noparse][[/noparse]//1].start(3,4,%0000,9600)

  input1:=serial[noparse][[/noparse]//0].rxcheck 
  input2:=serial[noparse][[/noparse]//1].rxcheck 




Now, my understanding of the above code would be that I would be running two instances of the Extended_FDserial object (Yes, DAT sections are shared, but the variables, including the rxbuffer are separate), which would give me two exclusive and different receive buffers. This does not seem to be the case. If I send in a string such as "hello" on the first serial line, and run the above code input1 will be "h", and input 2 will be "e". My goal is to have input1=="h" and input2==-1 (Because there was no input on the second port, to the second instance of the object). Perhaps my understanding of an array of objects is wrong. I also tried just duplicating the object reference such as below
OBJ
  serial1  : "Extended_FDserial"
  serial2  : "Extended_FDserial"



This did not work so well, when I attempted to do a serial2.rxcheck, it would consistently reboot the prop.

I'm sure someone has done this before? Any tips? To add to this I would also like to use the fullduplex object for RX and TX on the same pin. After I figured out the above, I wanted to to tie the RX,TX together and the DERE lines together. (I'm talking to 75176 RS485 transceiver). I want to keep the DERE line low normally to receive on the data line. Then when I needed to transmit, I would set the DERE line high and transmit on the dataline. Has anyone used the Extended_FullDuplex object this way?

Any help would be great! Thanks again!

Post Edited (Chicago Mike) : 1/26/2008 3:27:10 PM GMT

Comments

  • deSilvadeSilva Posts: 2,967
    edited 2008-01-26 15:42
    Mike:
    (a) Blanks will do rather than //
    (b) In your first example you have NOT created 2 instances; that would need:
    serial[noparse][[/noparse] 2]
    


    (c) Is this the complete code? If you use RCFAST rather than 80 MHz it might not work.

    There should be no propeller reset!
    And it should work in general...

    Edit:
    Just made some tests... It seems the access to an object is clipped to the last one. THis explanes the "e" (= second letter) Mike has seen...

    Post Edited (deSilva) : 1/26/2008 4:10:28 PM GMT
  • Chicago MikeChicago Mike Posts: 88
    edited 2008-01-27 21:06
    Ahhh The count starts from 1 not 0. Anyway, I changed the program to the following:
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    ' Pin Identifiers 
      rxData        =                2                      
      txData        =                3                     
      b485txrx      =               27                    
    
    OBJ
      serial : "Extended_FDserial"                       
      debug     : "vga_text"
    
    VAR
      byte rfserial_in[noparse][[/noparse] 16 ]                                    
      byte lineserial_in[noparse][[/noparse] 16 ]                                 
    
    Pub Init
      serial[noparse][[/noparse] 1 ].start(rxData,txData,%0000,baud)              
      serial[noparse][[/noparse] 2 ].start(b485txrx,b485txrx,%0000,baud)        
      Main
    
    Pub Main
      repeat    
          rfinput:=serial[noparse][[/noparse] 1 ].rxcheck                                                
          lineinput:=serial[noparse][[/noparse] 2 ].rxcheck                                             
          debug.dec(rfinput)
          debug.dec(lineinput)  
          waitcnt(5_000_000+cnt)                   
    
    



    Now at this point I have nothing wired to pin b485txrx, so serial[noparse][[/noparse] 2 ], has no input, hence I should get a return of -1. My results of this without ANY input to either serial device is rfinput == -1 (as expected), however lineinput == 0 (which, I think should be -1 as there is no input). Any idea why?

    I went back to the multiple instance method as listed above instead of calling the same object twice and assigning it to a different name, as I still was having the reboot problem when I would attempt to rx.check from the second device.

    Thanks!
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-27 21:11
    Mike, you misunderstood! It is as with ALL vectors:

    (1) You define serial[noparse][[/noparse] 2]: ....
    (2) You use serial[noparse][[/noparse] 0] and serial[noparse][[/noparse] 1]

    You did it vice versa...
Sign In or Register to comment.