Shop OBEX P1 Docs P2 Docs Learn Events
FourSerial in Two Cogs at Once? — Parallax Forums

FourSerial in Two Cogs at Once?

I am trying to use the FourSerial module by Tim Moore (2008) to run 8 serial ports on my Propeller 1 chip. When I activate the second FourSerial cog, the whole system "freezes":
* No serial output
* No OUT10 toggle (see the code)
* The crystal clock is still running

I also have a Host PC serial connection on a Big Buffer mod of Full Duplex Serial, which I have been using for at least 5 years. All are 38400 baud. The map is:

Cog 2: FDS: Host
Cog 3: FourSerial1: four serial connected RFID readers
Cog 4: FourSerial2: Barcode, Printer, Debug port, Unused

I don't know how to tell anything else about the internal state of the chip, that is, what might be happening in this state. The chip does not feel hot.

Any ideas? Full code is in the ZIP below. Here is the important part AFAIK:
OBJ
  ' Note - do not set debug signals like OUTA[11] in code modules 
  '   that run in more than one cog.  The signals will interfere.
  Host : "BB_FullDuplexSerial"
  FourRdrs : "FourSerial"
  AuxSerial : "FourSerial"

PUB _Entry
  MAIN

PUB Main | hscog, llcog, ascog, r4cog
  hscog := Host.start(pLLIOHostRx, pLLIOHostTx, 0, 38400)
  AuxSerial.AddPort(kAuxSpDebugUsb, pLLIODebugUsbRx, pLLIODebugUsbTx, -1, -1, -1, 0, kTargetBaud)
  AuxSerial.AddPort(kAuxSpBarcode, pLLIONewBarcodeRx, pLLIONewBarcodeTx, -1, -1, -1, 0, kTargetBaud)
  AuxSerial.AddPort(kAuxSpPrint, pLLIOVprnRx, pLLIOVprnTx, -1, -1, -1, 0, kTargetBaud)
  ascog := AuxSerial.AddPort(3, 24, 25, -1, -1, -1, 0, kTargetBaud) 'Do we need all 4 ports running?
  'Comment this line and the software runs ok 5x5
  'Uncomment this line and the software fails every time:
  ' * no serial output
  ' * no OUT10 toggle
  'AuxSerial.Start
  FourRdrs.AddPort(k4RdrDb9, pLLIODb9Rx, pLLIODb9Tx, -1, -1, -1, 0, kTargetBaud)
  FourRdrs.AddPort(k4RdrConn12a, pLLIOConn12aRx, pLLIOConn12aTx, -1, -1, -1, 0, kTargetBaud)
  FourRdrs.AddPort(k4RdrConn12b, pLLIOConn12bRx, pLLIOConn12bTx, -1, -1, -1, 0, kTargetBaud)
  FourRdrs.AddPort(3, 24, 25, -1, -1, -1, 0, kTargetBaud) 'Do we need all 4 ports running?
  r4cog := FourRdrs.Start
  ...
    'Send Version Banner
  Host.str(@_hello)
  'Main Loop
  repeat 'always
    OUTA[10] ~~
    TimerMain
    OUTA[10] ~
    Host.str(@_hello)
    'end repeat always

Comments

  • Found a workaround: activate both cogs AFTER all the setup is done. If someone could explain to me why that made a difference, I'd be grateful. New code:
      AuxSerial.AddPort(kAuxSpDebugUsb, pLLIODebugUsbRx, pLLIODebugUsbTx, -1, -1, -1, 0, kTargetBaud)
      AuxSerial.AddPort(kAuxSpBarcode, pLLIONewBarcodeRx, pLLIONewBarcodeTx, -1, -1, -1, 0, kTargetBaud)
      AuxSerial.AddPort(kAuxSpPrint, pLLIOVprnRx, pLLIOVprnTx, -1, -1, -1, 0, kTargetBaud)
      AuxSerial.AddPort(3, 24, 25, -1, -1, -1, 0, kTargetBaud) 'Do we need all 4 ports running?
      FourRdrs.AddPort(k4RdrDb9, pLLIODb9Rx, pLLIODb9Tx, -1, -1, -1, 0, kTargetBaud)
      FourRdrs.AddPort(k4RdrConn12a, pLLIOConn12aRx, pLLIOConn12aTx, -1, -1, -1, 0, kTargetBaud)
      FourRdrs.AddPort(k4RdrConn12b, pLLIOConn12bRx, pLLIOConn12bTx, -1, -1, -1, 0, kTargetBaud)
      FourRdrs.AddPort(3, 24, 25, -1, -1, -1, 0, kTargetBaud) 'Do we need all 4 ports running?
      ascog := AuxSerial.Start
      r4cog := FourRdrs.Start
    

    works ok in either order:
      r4cog := FourRdrs.Start
      ascog := AuxSerial.Start
    

    And yes, I did spot that I was using out PIO 24,25 in both places. It's fixed in the real code already, but I left to bad here to show it's not the root of the whole problem.
    Thanks,
    Larry
  • Larry,
    Have you checked Tracy Allen's version of four port serial plus?
    Jim
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2016-10-03 16:00
    Larry,

    The four-port object has its variables in DATa space. As a result, those variables are shared between each instance of the object, so I'm surprised you got it to work as you say. You'd normally have to make a new version of the object and make a minor change to the program code so that the IDE will then recognize it as a different object and compile it with its own set of variables. You will probably find a line at the end of the code, just above the MIT license,
    'If you want multiple copys of this driver in a project, then copy the file to multiple files and change
    'version in each to be unique
      version               long      1
    
    Just change the "1" to "2" and give the file a new name.

    The down side is that it duplicates all of the code and fattens up your whole program.

    There are other tricks. By the way, I see you are not using the flow control pins. I have a tighter version of the object that foregoes the flow control option. You asked in the code if you need to start all 4 ports. No you don't, you can start them in any combination. However, there is a bit of a bug in Tim's original code that gives it quite a bit of jitter if less than 4 are active.
  • @Tracy: I have a project that could benefit from you multi-port serial without flow control.
  • Cluso99Cluso99 Posts: 18,069
    I see Tracy has answered the problem.

    BTW In both 4th ports, you have used the same serial pins 24 & 25 !!
  • My workhorse 4-port object w/o flow control is attached. Also a passthru-terminal program that illustrates the syntax.

    Larry, this one too has a DAT variable "version" that can be used to create a second instance of 4 ports under a new object file name. (Just changing the name isn't enough, the IDE checks the actual code, and if the version variable needs to be different as well as the file name.)

  • Thank you all for your contributions. I apologize for letting them go stale for a month, but once I found my workaround I was on to other things. I will try the workhorse no-handshake code today or Monday.
    Larry
Sign In or Register to comment.