Menu

Need to send a hex string over rs232

Help
Ryan
2016-02-24
2016-03-09
  • Ryan

    Ryan - 2016-02-24

    Here is what im using at the moment:
    Xmit_rs232 (h'8A')
    Xmit_rs232 (h'A8')
    Xmit_rs232 (h'00')
    Xmit_rs232 (h'01')
    Xmit_rs232 (h'05')
    Xmit_rs232 (h'48')
    Xmit_rs232 (h'65')
    Xmit_rs232 (h'6C')
    Xmit_rs232 (h'6C')
    Xmit_rs232 (h'6F')

    What i need to be able to do is basically send this:
    8A A8 00 01 05 48 65 6C 6C 6F, all together at once rather than as seperate transmisiions, i m using a led display and im over loading the buffer by sending too many seprate messages at once and it is dropping things, so if i could combine them into larger groups it would help, when i try Xmit_rs232 (h'8A A8') i get an error looking for an array?

     
  • mmotte

    mmotte - 2016-02-25

    I am not sure what language you are using? assembler?

    GCBasic has two commands for rs232 sending. For software serial you would use "SerSend 1, 0x8A". For hardware serial using the micro's USART you would use "HSerSend 0x8A".

    rs232 by definition is byte width. So you can't put two bytes into the same command.

    Please help us by providing more information. We need to know the microcontroller, speeds, baud, etc and what serial LED display you are talking to? What indication do you have that the led buffer is overrun?

     
    • Anobium

      Anobium - 2016-02-25

      I was thinking the same. What GCB version etc? Chip? I think a full code post would help understand context.

       
    • Ryan

      Ryan - 2016-02-25

      I was trying to use the Xmit_Print (h'8A A8'), but not much sucess, thats why i went directly to the xmit_rs232, the overrun is my guess because the display is losing characters,heres my program:

      chip 12f683, 8 'mhz

      config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=off

      Ser_Init

      dir gpio.5 out 'tx
      dir gpio.4 in '
      dir gpio.3 in '
      dir gpio.2 in '
      dir gpio.1 in '
      dir gpio.0 in '

      start:
      Xmit_rs232 (h'8A')
      Xmit_rs232 (h'A8')
      Xmit_rs232 (h'00')
      Xmit_rs232 (h'01')
      Xmit_rs232 (h'05')
      Xmit_rs232 (h'47')
      Xmit_rs232 (h'6F')
      Xmit_rs232 (h'6F')
      Xmit_rs232 (h'64')
      Xmit_rs232 (h'62')
      Xmit_rs232 (h'79')
      Xmit_rs232 (h'65')
      wait 5 s
      Xmit_rs232 (h'8A')
      Xmit_rs232 (h'A8')
      Xmit_rs232 (h'00')
      Xmit_rs232 (h'01')
      Xmit_rs232 (h'05')
      Xmit_rs232 (h'48')
      Xmit_rs232 (h'65')
      Xmit_rs232 (h'6C')
      Xmit_rs232 (h'6C')
      Xmit_rs232 (h'6F')
      wait 5 s
      Xmit_rs232 (h'8A') 'clear display
      Xmit_rs232 (h'A8')
      Xmit_rs232 (h'FF')
      Xmit_rs232 (h'FF')
      Wait 5 s
      goto start

      Sub Ser_Init
      ;slight adjustment was required for 9600bps delay value

      define baud 104 ;expressed as frequency in us

      define halfbaud 52 ;place Read of SerRx in middle of bit

      define SerTxHigh Set GPIO.5 On

      define SerTxLow Set GPIO.5 Off

      define SerRx GPIO.3

      dir GPIO.5 out ;Tx
      dir GPIO.3 in ;Rx
      SerTxHigh ;Initial RS232 idle state
      end sub

      sub XMIT_PRINT (PrintData$)
      PrintLen = PrintData(0)
      if PrintLen = 0 then exit sub
      'Write Data
      for SysPrintTemp = 1 to PrintLen
      XMIT_RS232(PrintData(SysPrintTemp))
      next
      end sub

      Sub XMIT_RS232(Xmit_Byte)#NR
      SerTxLow ;Start bit
      wait baud us
      For cntr = 1 to 8
      Rotate Xmit_Byte Right
      If Status.C ON Then SerTxHigh
      If Status.C Off Then SerTxLow
      wait baud us
      Next
      SerTxHigh ;Stop bit
      wait baud us
      end sub

       
  • William Roth

    William Roth - 2016-03-09

    Ryan,

    You have asked several questions here regarding sending/ displaying serial data. However you have not answered some important questions from those trying to help you.

    In order to provide good help we need to know a bit more than you are providing.

    1, What version of Great Cow Basic are you using?
    2, The code you posted above looks old, where did it come from?
    3, Why are you not using the GCB sersend/serprint commands?
    4, What is the actual application?
    5, What do the hex values do?
    6. Do you want to display these values or are they for something else like setting up the display ?

    (the more information you provide the better help ypou will get)

    Note: If you do not have the latest GCB installed then you need to
    upgrade. There is better serial functionality and it is what
    you can expect to get support on.

    Sending/displaying serial data need not be too complicated. However some basic understanding is involved.

    As I said in another post, serial data is NOT sent in hex, or decimal. It is ALWAYS sent as binary data (one byte at a time) where a byte represents 8 bits (binary)

    "Sersend 1, 0xA8" is exactly the same as "Sersend 1, 168"

    A8'h is the hex representation of a byte with a binary value of 10101000
    168 is the dec representation of a byte with a binary value of 10101000

    In you post above you said you wanted to send 10 bytes of data at once. Serial data is always sent one byte at a time using various methods. With GCB we use sersend or Serprint.

    Sersend sends the raw data. This will likely display as nonsense on an ASCII Terminal program or on an LCD display, unless the data is preformatted ascii codes.

    serprint converts the data to several bytes where each byte represents
    an ASCII Character code. There is no "hex" involved per se.

    "Serprint 1, 0xA8" will send three bytes with values that represent the ASCII character codes for "1" , "6" and "8",

    So to send your 10 bytes I would use GCB software serial, rather then try to bit-bang it as in your code above. The code below was tested to work correctly on 12F683 using GCB Ver 95.006

    #chip 12F1283, 8        
    #Config INTRC_OSC_NOCLKOUT, MCLRE=off, WDT=off
    
    '//set up 10 byte array and load values 
    DIM TXbuff(10)
    TXbuff = 0x8A, 0xA8, 0x00, 0x01, 0x05, 0x48, 0x65, 0x6C, 0x6C, 0x6F
    'REM      x     x     x     x     x     "H"   "E"   "L"   "L"  "0"
    
    'Setup serial
    'If using USB/TTL Converter use "normal" instead of "invert"
    #define SendAHigh Set GPIO.5 ON
    #define SendALow Set GPIO.5 OFF
    InitSer 1, r9600, 1+WaitForStart, 8, 1, none, invert
    
    DO
    
      '// Transmit the raw data"
         For ii = 1 to 10
           Sersend 1, Txbuff(ii)
         Next
        wait 1 s 
    LOOP
    
     
  • Ryan

    Ryan - 2016-03-09

    i'm figuring it out with bits and pieces, thanks for the help, yes i need to updte my software its been awhile, i just havent wanted to have to change the programs that i already have that work, is it fully backward compatible? i have given rest to the ideas in the past two questions, from what i have learned i can make it work

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.