Shop OBEX P1 Docs P2 Docs Learn Events
Trouble passing variables to FullDuplexSerial.spin — Parallax Forums

Trouble passing variables to FullDuplexSerial.spin

I am a first time to user. I have downloaded a SPIN file FullDuplexSerial.spin from the library , onto my Parallax propeller prototype board. I have loaded the code into Propeller IDE, it compiles and loads into board, but when I provide input for “PUB Start(rxPin, txPin, mode, baudrate) : okay “ the compile fails. I did try to add this line before the PUB line above “Start (31, 30, 0, 9_600)“ what am I doing wrong, any suggestions.
'Pub main
' Serial.Start(31, 30, 0, 9_600)
'Start(31, 30, 0, 9_600) : okay
'PUB Start(31, 30, 0, 9_600) : okay
PUB Start(rxPin, txPin, mode, baudrate) : okay

Regards

Comments

  • Look in the Library Demos folder and there is example code for using FullDuplexSerial.spin
    OBJ
    
      'in leiu of Parallax Serial Terminal, FullDuplexSerial is being used to communicate with the terminal
      serial        : "FullDuplexSerial"
    
      
    PUB Main
    {{
      Starts execution of FullDuplexSerialTest1.spin
    
      This is a very simple test.  It starts the object, waits 1 second, prints two
      lines to the terminal, waits 1 more second, then shuts down.  Set your terminal
      to a baud rate of 9600 baud to see the output.
      
      parameters:    none
      return:        none
      
      example usage: N/A - executes on startup
    
    }}
    
      'start the FullDuplexSerial object
      serial.Start(31, 30, %0000, 9_600)                    'requires 1 cog for operation
    
      waitcnt(cnt + (1 * clkfreq))                          'wait 1 second for the serial object to start
      
      serial.Str(STRING("Testing the FullDuplexSerial object."))     'print a test string
      serial.Tx($0D)                                                 'print a new line
      
      serial.Str(STRING("All Done!"))
    
      waitcnt(cnt + (1 * clkfreq))                          'wait 1 second for the serial object to finish printing
      
      serial.Stop                                           'Stop the object
    
  • You're not showing your code, so the question becomes... did you declare a serial object? Here's the object declaration section from my standard template.
    obj
    
    ' main                                                          ' * master Spin cog
      time : "jm_time_80"                                           '   timing and delays (80MHz)
      prng : "jm_prng"                                              '   pseudo-random number generator
      io   : "jm_io_basic"                                          '   essential io
      term : "jm_fullduplexserial"                                  ' * serial IO for terminal
                                                                     
    ' * uses cog when loaded
    
    I have a separate method called setup that handles the initialzing of these objects.
    pub setup                                                        
                                                                     
    '' Setup IO and objects for application                          
                                                                     
      time.start                                                    ' setup timing & delays
                                                                     
      prng.seed(-cnt, -cnt ~> 2, $EA7_BEEF, cnt <- 2, cnt)          ' seed randomizer                                                                           
    
      io.start(0, 0)                                                ' clear all pins (master cog)
                                                                     
      term.start(RX1, TX1, %0000, BR_TERM)                          ' start serial for terminal *
    
    After calling setup my program is free to fly.

    I have attached an archive of my standard template as this may help you get up and running. Note that I use a personal derivative of FullDuplexSerial -- the interface is the same, it just has a few more methods.
  • Thanks Antediluvian,

    You are the best, thank you very much for your help.
    I did download FullDuplexSerial_Test1.spin with no problem into the board but I did not get anything back while I had the terminal up.
    Then I saw FullDuplexSerial_Test2.Spin and load\compile\Download to board\Came up nicely and print text on terminal and ask me to type and echo back.
    I am very happy. Now I need to look why test1 did not work.
    Then continue with looking at the RX buffer content. and process the data I receive.
    Again thank you and have a great day

    Regards
    Akbar
  • Akbar,

    It seems the Test1 example waits 1 second and then prints something and that's it. It may be that you're missing what is sent by the time you get the terminal open?
  • may be that you're missing what is sent by the time you get the terminal open?
    Yep, common error. In my template main method I wait for a keypress before sending a message to PST.
    pub main                                                         
                                                                     
      setup                                                          
                                                                     
      term.rxflush                                                  ' wait open terminal & keypress
      term.rx                                                        
                                                                     
      term.tx(term#CLS)                                              
      term.str(string("Hello, World!", 13, 13))            
                                                                     
      repeat                                                         
        waitcnt(0)
    
    By doing this I can download to RAM (F10) and not miss anything sent to the terminal.
Sign In or Register to comment.