Shop OBEX P1 Docs P2 Docs Learn Events
P1 FullDuplexSerial.spin — Parallax Forums

P1 FullDuplexSerial.spin

pic18f2550pic18f2550 Posts: 400
edited 2022-02-22 11:02 in Propeller 1

Hello,
how can I tell that there is no PC connected to the propeller?

because the PC is not connected there is a buffer overflow and the application hangs.

Modified FullDuplexSerial.spin attached.
Renamed from FullDuplexSerial.spin to pic_FullDuplexSerial.spin.

Comments

  • Seems like a simple handshake sequence would help out. Ping the PC with the Propeller and look for a specific response within a given time window. There is an rxtime() method that will return -1 if there is no response.

  • I have examined this hanging a little closer.
    The cause is in the initialization, here it hangs.
    It does not even come to the output routine.
    Therefore a check with timeout is not possible.

  • I think you can check if RX is high because when connected it goes low (or the other way around?)

    I used this because older Parallax boards where resetting when sending out w/o USB connected

    Mike

  • In short, when the FTDI chip is not connected to the cable it pulls juice from pin 30 (tx, idle) which in turn triggers a reset for the prop.

    Better would have been to supply the operating voltage of the FTDI chip with 2 diodes from the internal 5v and the USB voltage.

    So I have to live with that on the starter kit, unfortunately there are no resistors on RX and TX to fix the problem.

  • richtig.

    on never boards they corrected it, but pe-starterkit and other older boards have the issue not fixed.

    The solution was to check if USB is there or not and then NOT send any data, it is TX from the prop feeding the FTDI and then it does a reset.

    As long as you not send anything, things are fine. And you need to check RX (Pin 31) to find out IF something is connected to the FTDI Usb. Because if then it is on the Idle state else floating

    That is how to check for.

    Mike

  • pic18f2550pic18f2550 Posts: 400
    edited 2022-02-03 10:51

    Why doesn't anyone adjust the code on the GIT so that this doesn't happen?

    PUB start(rxpin, txpin, mode, baudrate) : okay
    
    '' Start serial driver - starts a cog
    '' returns false if no cog available
    ''
    '' mode bit 0 = invert rx
    '' mode bit 1 = invert tx
    '' mode bit 2 = open-drain/source tx
    '' mode bit 3 = ignore tx echo on rx
      stop
      longfill(@rx_head, 0, 4)
      longmove(@rx_pin, @rxpin, 3)
      bit_ticks := clkfreq / baudrate
      buffer_ptr := @rx_buffer
    
      okay:=0
      if ina[rxpin]
        okay := cog := cognew(@entry, @rx_head) + 1
    
    PUB tx(txbyte)
    
    '' Send byte (may wait for room in buffer)
      if cog
        repeat until (tx_tail <> (tx_head + 1) & $F)
        tx_buffer[tx_head] := txbyte
        tx_head := (tx_head + 1) & $F
    
        if rxtx_mode & %1000
          rx
    
  • I have attached the modified "FullDuplexSerial.spin" in #1.

    May it find its way to Git. :)

  • It seems like the calling app should stop of throw an error if FDS cannot be started. Why burden every method in FDS with a condition that almost never happens.

  • I don't know how many demo boards of this type of Parallax are in circulation but they all have the same problem. You can not solder resistors afterwards.
    To be more precise, it also affects all prop sticks with FDI chip when the resistors are missing in the circuit.
    I noticed the problem earlier at the HIVE project, so several custom builds could have the same problem.

    I have changed so far that the feedback is 0 just as if the application can not start because no COG is free.

    But you could also return -1 and specify the error.

    Why should errors be ignored? It is not a C.

    Well, the change is not so extensive that there would not be a bit of space, or even eat gigantic resources.

    Not everyone is so deep in the matter that he can solve it easily, you should pay attention to the beginners, after all, it's about business, every resigned customer is a lost customer.

    I do not want to force anyone to take over something, but if someone wants ... here you go.

    For me, the problem is solved and secured in the library for further projects.

  • pic18f2550pic18f2550 Posts: 400
    edited 2022-02-16 11:02

    I have also tested the changes on other pins.
    unfortunately it is not always successful.
    The change only applies when a FDI is connected.

    I decided to change the start routine a little bit.
    I simply pass a 5th parrameter.
    This is the most memory saving.

    PUB Start(rxPin, txPin, mode, baudrate, fdi) : okay
    {{
       Start serial driver - starts a cog
    
    
       Parameters: rxPin    = Propeller pin to set up as RX-ing pin.  Range = 0 - 31
                   txPin    = Propeller pin to set up as TX-ing pin.  Range = 0 - 31
                   mode     = bitwise mode configuration variable, see mode bit description below.
                   baudrate = baud rate to transmit bits at.
    
       mode bit 0 = invert rx
       mode bit 1 = invert tx
       mode bit 2 = open-drain/source tx
       mode bit 3 = ignore tx echo on rx
    
       return: Numeric value of the cog(1-8) that was started, false(0) if no cog is available.
    
       example usage: serial.start(31, 30, %0000, 9_600)
    
       expected outcome of example usage call: Starts a serial port on Propller pins 30 and 31.
                                               The serial port does not invert the RX and TX data,
                                               no open-drain/source on the TX pin, does not ignore
                                               data echoed on RX pin, at 9,600 baud.
    }}
    
      Stop                                                  'make sure the driver isnt already running
      longfill(@rx_head, 0, 4)                              'zero out the buffer pointers
      longmove(@rx_pin, @rxpin, 3)                          'copy the start parameters to this objects pin variables
      bit_ticks := clkfreq / baudrate                       'number of clock ticks per bit for the desired baudrate
      buffer_ptr := @rx_buffer                              'save the address of the receive buffer
      if fdi
        if ina[rxpin]                                       'check FDI present.
          okay := cog := cognew(@entry, @rx_head) + 1       'start the new cog now, assembly cog at "entry" label.
      else
        okay := cog := cognew(@entry, @rx_head) + 1         'start the new cog now, assembly cog at "entry" label.
    
  • JonnyMacJonnyMac Posts: 9,102
    edited 2022-02-16 21:37

    I suggest you identify your version as I do with mine -- all of my programs are prepended with "Jm_" The reason for this suggestion is that adding another parameter to the start() method means this version is not compatible with 100s of programs already written that use the old fullduplexserial.spin or even my jm_fullduplexserial.spin.

  • Ok, I will do it tomorrow and change it to #1.

Sign In or Register to comment.