Shop OBEX P1 Docs P2 Docs Learn Events
Can someone help me? Serial Communications — Parallax Forums

Can someone help me? Serial Communications

FurballFurball Posts: 4
edited 2009-08-19 22:37 in Propeller 1
Im kind of new to the .spin language and im in need of some help, i have been doing a little homework on the propeller chip but now im in need of some help, im needing a program that when a switch is closed it will output via RS232, a hex statemet of FE 1E, for some reason i think im making this harder than it needs to be. Can someone help me learn what im going wrong?

Comments

  • billiam2536billiam2536 Posts: 28
    edited 2009-08-19 16:19
    To know what your doing wrong, people have to know what your doing Period. I suggest you upload your current code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Working on getting money for autopilot project. Come check out my site if your interested in the project. Maybe go to the bottom of the page wink.gif
  • CarnibusCarnibus Posts: 4
    edited 2009-08-19 16:33
    I've never used it but the fullduplexserial object has a trasmit hex method you could probably use.
  • JonnyMacJonnyMac Posts: 9,198
    edited 2009-08-19 17:02
    Maybe... depends on the device. I'm guessing it's a Scott Edwards display as they use a $FE header followed by the instruction byte. If one had a serial object called display then the .tx method is all that's required:

    display.tx($FE)
    display.tx($1E)
    
  • FurballFurball Posts: 4
    edited 2009-08-19 17:12
    Actually its a R4x/R8x Pro
    RS-232 E3C Networkable Relay Controllers that needs FE 1E to turn on all the relays, its 9600 baud
  • blackmesa82blackmesa82 Posts: 4
    edited 2009-08-19 18:37
    The following routine works well up to at least 38,400 baud.

    You could send fe 1e with

    
    CommTX(@relay)
    
    
    



    Simply add the constants to your CON section, setting TX to your transmit pin. Messages are defined in the DAT section and must be terminated with 0.



    Here is the code:

    
    con
    
    BAUD = 9600
    TX = 6                          ' RS-232 transmit pin
    
    dat
    
    sorry   byte  "I'm sorry, Dave. I'm afraid I can't do that.",13,10,0
    relay   byte  $fe,$1e,0
    
    
    
    
    pub CommTX(message) | data,mark,clks,i
    
    clks := clkfreq / BAUD
    i~
    
    repeat while byte[noparse][[/noparse]message][i]
      data := byte[noparse][[/noparse]message][i]
              
      data := data <<1
      data := data | %1_00000000_0                          ' add start and stop bits
      mark := cnt + clks
    
      repeat 10
        outa[noparse][[/noparse]TX] := data & %0000000001                     ' send data packet
        data := data >>1
        waitcnt(mark)
        mark += clks
    
      i++
    
    [/i][/i]
    



    (edit: sorry, I missed the @ in the CommTX call.)

    - eeo

    Post Edited (blackmesa82) : 8/19/2009 6:55:04 PM GMT
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-08-19 18:37
    Hello Furbal,

    as you seem to ´be a newbee I would like to state some additional things

    the FullDUplexSerial-objects sends data at the specified baudrate in 8N1-format which is very common
    8N1 8 databits no parity 1 stopbit
    but there are also others like 7E2 7 databits equal parity 2 stopbits or 8N2, 8E1, or 8O1, etc. etc.

    the parameter mode specifies details about the electronical circuit of the Rx and the Tx-line
    mode 0 is common

    I guess the Relay-control expects real RS232 voltage-levels which is +12V/-12V.
    The propeller-IO-pins deliver 0V/3.3V so you need a voltage-levelshifter chip like the MAX2323

    you should use a current-limiting resistor of 150 Ohms to avoid damaging an IO-pin if the IO-PIN is accidently configured wrong
    the IO-PIN connected to the switch

    you should use a PULL-down-resistor of 10kOhm to get a clear defined state of the IO-PIN while the switch is open
    the Pull-down-resistor as its name says pulls down the IO-PIN to low=0V.
    Without a Pull-down-resistor the state of the IO-PIN is free floating and the state will change between low and high
    in an unpredictable way

    below is a demoprogram that shows one of 2 dozens of solutions to what you have described above
    download the program to the EEPROM
    then start the PST.EXE (Parallax Serial Terminal) adjust baudrate to 115200
    reset the prop while PST is connected to the prop and watch the debug-output

    depending on what you want to do in the end another solution might be more suitable

    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
      c_RxPin = 20 'you have to adjust this number to YOUR IO-PIN-number
      c_TxPin = 21 'you have to adjust this number to YOUR IO-PIN-number
      c_mode  = 0
      c_baud  = 9600
    
      'you have to adjust this number to YOUR IO-PIN-number
      'where the button is connected to
      c_IO_Pin_Button = 0 
    
    OBJ
      debug          : "FullDuplexSerial" 'use programming connection for debugging
      RS232RelayCont : "FullDuplexSerial" 'serial connection to RS232Relay-control
    
        
    PUB Demo_Send_Char_on_buttonpress
    
      debug.start(31,30,0,115200)
      RS232RelayCont.Start(c_RxPin, c_TxPin,c_mode, c_baud)
      debug.str(string("Serial-driver cogs started ",13,13))
    
      DIRA[noparse][[/noparse] c_IO_Pin_Button] := 0 'define IO-PIN as input
      
      debug.str(string("wait for IO-PIN No "))
      debug.dec(c_IO_Pin_Button)
      debug.str(string(" to be high = 3.3V",13))
    
      'stay inside this repeatloop until IO-Pin is high
      'works if IO-PIN has a Pull-down-resistor
      repeat until INA[noparse][[/noparse] c_IO_Pin_Button] == 1 
    
      debug.str(string("IO-PIN No "))
      debug.dec(c_IO_Pin_Button)
      debug.str(string(" detected as high = 3.3V",13,13))
    
      debug.str(string("wait for IO-PIN No "))
      debug.dec(c_IO_Pin_Button)
      debug.str(string(" to be low = 0V",13))
    
      'stay inside this repeatloop until IO-Pin is low
      'works if IO-PIN has a Pull-UP-resistor
      repeat until INA[noparse][[/noparse] c_IO_Pin_Button] == 0 
    
      debug.str(string("IO-PIN No "))
      debug.dec(c_IO_Pin_Button)
      debug.str(string(" detected as low = 0V",13,13))
    
      RS232RelayCont.tx($FE)
      RS232RelayCont.tx($1E)
    
      debug.str(string("$FE $1E was send to IO-PIN No "))
      debug.dec(c_TxPin)
      debug.str(string(13,"at "))
      debug.dec(c_baud)
      debug.str(string(" baud  (8N1 = 8 databits no parity 1 stopbit)",13))
    
      debug.str(string("program is running commmand beyond this line of code",13))
    
      repeat
    
    



    best regards

    Stefan
  • Cluso99Cluso99 Posts: 18,069
    edited 2009-08-19 22:37
    Welcome to the forum. As you have seen, if you have any questions just ask and enjoy the prop·roll.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBladeProp, RamBlade, TwinBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: Micros eg Altair, and Terminals eg VT100 (Index) ZiCog (Z80) , MoCog (6809)
    · Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
Sign In or Register to comment.