Shop OBEX P1 Docs P2 Docs Learn Events
FullduplexSerial Object — Parallax Forums

FullduplexSerial Object

Computer Geek 101Computer Geek 101 Posts: 179
edited 2008-07-18 19:14 in Propeller 1
I am working on a fire alarm system.· Each module will talk to the next one to find the status, therefore each module needs two serial ports.· One to respond the the module "upstream" and one to talk to the next module.· What are the different modes in the FullDuplexSerial object do?· I need to wire the RX of one to the TX of the other.· So far I dont seem to get it right.

CON
  _clkmode      =               xtal1 + pll16x
  _xinfreq      =               5_000_000
  Buzzer        =               0
  AlarmSwitch   =               9
  MasterRst     =               10
  ID_Bit1       =               16
  ID_Bit2       =               17
  ID_Bit3       =               18
  ID_Bit4       =               19
  RX_1          =               20
  TX_1          =               21
  RX_2          =               22
  TX_2          =               23
  
OBJ
  SerialComm_1  : "FullDuplexSerial"
  SerialComm_2  : "FullDuplexSerial"
        
VAR
  LONG  Unit_ID
  LONG  Alarm
  LONG  Comm1_Cog, Comm2_Cog, Alarm_Cog
  LONG  stack[noparse][[/noparse]120]
  LONG  Command[noparse][[/noparse]20]
  
PUB Main
  System_INI
  Comm1_Cog := cognew(Serial1, @stack[noparse][[/noparse]0])  + 1
  Comm2_Cog := cognew(Serial2, @stack[noparse][[/noparse]40]) + 1
  Alarm_Cog := cognew(SetAlarm, @stack[noparse][[/noparse]80]) + 1
  ScanSwitch
  
PRI System_INI
  dira[noparse][[/noparse]ID_Bit1] := 0
  dira[noparse][[/noparse]ID_Bit2] := 0
  dira[noparse][[/noparse]ID_Bit3] := 0
  dira[noparse][[/noparse]ID_Bit4] := 0
  Unit_ID := 0
  if ina[noparse][[/noparse]ID_Bit1] == 0
    Unit_ID += 1
  if ina[noparse][[/noparse]ID_Bit2] == 0
    Unit_ID += 2
  if ina[noparse][[/noparse]ID_Bit3] == 0
    Unit_ID += 4
  if ina[noparse][[/noparse]ID_Bit4] == 0
    Unit_ID += 8
  bytefill(@Command, 0, 40)
  Alarm := 0
  
PRI Serial1 | Buffer_1[noparse][[/noparse]10], Index, count
  SerialComm_1.start(RX_1, TX_1, 0, 9600)
  repeat
    bytefill(@Buffer_1, 0, 20)
    repeat Index from 0 to 20
      Buffer_1.byte[noparse][[/noparse]Index] := SerialComm_1.rx
      if Buffer_1.byte[noparse][[/noparse]Index] == 0
        quit
    if Buffer_1.byte[noparse][[/noparse]0] == "<" and Buffer_1.byte[noparse][[/noparse]1] == "S" and Buffer_1.byte[noparse][[/noparse]2] == ">"
      SerialComm_1.str(@RequestRcv)
    if Buffer_1.byte[noparse][[/noparse]0] == "<" and Buffer_1.byte[noparse][[/noparse]1] == "F"
      repeat count from 0 to 40
        Command.byte[noparse][[/noparse]count] := Buffer_1.byte[noparse][[/noparse]count]
      Alarm := 1
    if Buffer_1.byte[noparse][[/noparse]0] == "<" and Buffer_1.byte[noparse][[/noparse]1] == "T" and Buffer_1.byte[noparse][[/noparse]2] == ">"
      repeat count from 0 to 40
        Command.byte[noparse][[/noparse]count] := Buffer_1.byte[noparse][[/noparse]count]
      Alarm := 2
              
PRI Serial2 | Buffer_2[noparse][[/noparse]10], MyCount, Index, FlagCount
  SerialComm_2.start(RX_2, TX_2, 0, 9600)
  MyCount := cnt
  FlagCount := 0
  repeat
    bytefill(@Buffer_2, 0, 20)
    if Alarm == 1 or Alarm == 2
      SerialComm_2.str(Command)
    if (cnt - MyCount) / clkfreq > 4
      SerialComm_2.str(@SendRequest)
      repeat Index from 0 to 20
        Buffer_2.byte[noparse][[/noparse]Index] := SerialComm_2.rxtime(20)
        if Buffer_2.byte[noparse][[/noparse]Index] == 0
          quit
      if Buffer_2.byte[noparse][[/noparse]0] == "<" and Buffer_2.byte[noparse][[/noparse]2] == "R" and Buffer_2.byte[noparse][[/noparse]3] == ">"
        FlagCount := 0
      else
        FlagCount ++
    if FlagCount > 3
      Alarm := 3
            
PRI ScanSwitch
  dira[noparse][[/noparse]AlarmSwitch] := 0
  dira[noparse][[/noparse]MasterRst] := 0
  repeat
    if ina[noparse][[/noparse]AlarmSwitch] == 0
      Command.byte[noparse][[/noparse]0] := "<"
      Command.byte[noparse][[/noparse]1] := "F"
      Command.byte[noparse][[/noparse]2] := (Unit_ID / 10 ) + 48
      Command.byte[noparse][[/noparse]3] := (Unit_ID // 10 ) + 48 
      command.byte[noparse][[/noparse]4] := ">"
      Alarm := 1
    if ina[noparse][[/noparse]MasterRst] == 0
      Alarm := 0
          
PRI SetAlarm
  dira[noparse][[/noparse]Buzzer] := 1
  repeat
    if Alarm == 0
      outa[noparse][[/noparse]Buzzer] := 0
    if Alarm == 1
      outa[noparse][[/noparse]Buzzer] := 1
    if Alarm == 2
      !outa[noparse][[/noparse]Buzzer]
      waitcnt(clkfreq / 2 + cnt)
    if Alarm == 3
        outa[noparse][[/noparse]Buzzer] := 1
        waitcnt(clkfreq / 4 + cnt)
        outa[noparse][[/noparse]Buzzer] := 0
        waitcnt(clkfreq * 2 + cnt)   
DAT
        SendRequest     byte   "<S>", 0
        RequestRcv      byte   "<R>", 0
        Tornado         byte   "<T>", 0
                  

Thanks for the help

Comments

  • Erik FriesenErik Friesen Posts: 1,071
    edited 2008-07-18 18:59
    I would suggest starting in sections to make sure your communications are doing what you think they are. They may be working, but your conditional jumps may be skewing the results. For example you could start some debug program like tv_text within your serial cog, then text.out(buffer1.byte[noparse][[/noparse]index) within the repeat loop to see if you are actually getting something in the buffer.

    As long as you have the third and fourth 0 and 9600 the same it should work. Look at simple_serial. For some reason it has the modes explained in the notes better than the fullduplexserial does.
  • Computer Geek 101Computer Geek 101 Posts: 179
    edited 2008-07-18 19:14
    Erik, thanks. I have used the simple serial. I may have found an error in my code that could mess up the works. Ill connect it to a monitor and check it out
Sign In or Register to comment.