News:

;) This forum is the property of Proton software developers

Main Menu

Re: Issue Sending Raw Hex via RS232 ?

Started by Craig, Today at 12:57 PM

Previous topic - Next topic

Craig

Hi I am having an issue sending a Hex string to a Dwin DMG80480T043_A5WTC. Touch display.
The Header String that the Dwin Display Receives is set and cannot be changed baring the Data Section.
the issue that I am having is to send $5A $A5 $05 $82 $61 $00 $00 $16

I am using a 18F27Q10 Device Running at 64Mhz using HRSOut2 with a Max3232 (Rs232 to TTL) Chip.

Declare HRSOut2_Pin = PORTB.6                ' TX2 to the PC To Read Serial Data
Declare HRSIn2_Pin = PORTB.7                 ' RX2 to the PC To Read Serial Data
Declare Hserial2_Baud = 115200

Dim MyByteArray[8] As Byte = $5A,$A5,$05,$82,$61,$00,$00,$16

HRSOut2 Hex MyByteArray[0], MyByteArray[1], MyByteArray[2], MyByteArray[3], MyByteArray[4], MyByteArray[5], MyByteArray[6], MyByteArray[7]


It sends the following out via the RS3232 Chip: 35 41 $A5 $05 $82 $61 $00 $00 $16
the $5A is being replaced by 35 41 which is (5 = 35 and 41 = A) as can be seen the rest of the string is correct.
The problem is that the Dwin display will only accept the correct header to the string in this exact order and sequence $5A,$A5,$05,$82,$61,$00,$00,$16 everything is working Except the $5A, which is causing all the trouble!

How do i correct this and why is the HRSOut command splitting this back to Ascii?
All Help is Much Appreciated
Regards
Craig

 

RGV250

#1
Hi,
Can you post your config as well as i can sim it in VSM

Bob

Craig

Hi Bob Thanks Very much.

Device = 18F27Q10

Config_Start
  FEXTOSC = OFF   ;Oscillator not enabled
  RSTOSC = HFINTOSC_64MHZ   ;HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
  CLKOUTEN = OFF   ;CLKOUT function is disabled
  CSWEN = OFF   ;The NOSC and NDIV bits cannot be changed by user software
  FCMEN = OFF   ;Fail-Safe Clock Monitor disabled
  MCLRE = EXTMCLR   ;MCLR pin (RE3) is MCLR
  PWRTE = OFF   ;Power up timer disabled
  LPBOREN = OFF   ;Low power BOR is disabled
  BOREN = OFF   ;Brown-out Reset disabled
  BORV = VBOR_190   ;Brown-out Reset Voltage (VBOR) set to 1.90V
  ZCD = OFF   ;ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
  PPS1WAY = OFF   ;PPSLOCK bit can be set and cleared repeatedly (subject to the unlock sequence)
  STVREN = OFF   ;Stack full/underflow will not cause Reset
  XINST = OFF   ;Extended Instruction Set and Indexed Addressing Mode disabled
  WDTCPS = WDTCPS_31   ;Divider ratio 1:65536; software control of WDTPS
  WDTE = OFF   ;WDT Disabled
  WDTCWS = WDTCWS_7   ;window always open (100%); software control; keyed access not required
  WDTCCS = SC   ;Software Control
  WRT0 = OFF   ;Block 0 (000800-003FFFh) not write-protected
  WRT1 = OFF   ;Block 1 (004000-007FFFh) not write-protected
  WRT2 = OFF   ;Block 2 (008000-00BFFFh) not write-protected
  WRT3 = OFF   ;Block 3 (00C000-00FFFFh) not write-protected
  WRT4 = OFF   ;Block 4 (010000-013FFFh) not write-protected
  WRT5 = OFF   ;Block 5 (014000-017FFFh) not write-protected
  WRT6 = OFF   ;Block 6 (018000-01BFFFh) not write-protected
  WRT7 = OFF   ;Block 7 (01C000-01FFFFh) not write-protected
  WRTC = OFF   ;Configuration registers (300000-30000Bh) not write-protected
  WRTB = OFF   ;Boot Block (000000-0007FFh) not write-protected
  WRTD = OFF   ;Data EEPROM not write-protected
  SCANE = OFF   ;Scanner module is NOT available for use, SCANMD bit is ignored
  LVP = On   ;Low voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignored
  Cp = OFF   ;UserNVM code protection disabled
  CPD = OFF   ;DataNVM code protection disabled
  EBTR0 = OFF   ;Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
  EBTR1 = OFF   ;Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
  EBTR2 = OFF   ;Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
  EBTR3 = OFF   ;Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
  EBTR4 = OFF   ;Block 4 (010000-013FFFh) not protected from table reads executed in other blocks
  EBTR5 = OFF   ;Block 5 (014000-017FFFh) not protected from table reads executed in other blocks
  EBTR6 = OFF   ;Block 6 (018000-01BFFFh) not protected from table reads executed in other blocks
  EBTR7 = OFF   ;Block 7 (01C000-01FFFFh) not protected from table reads executed in other blocks
  EBTRB = OFF   ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
Config_End

;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------

Declare Xtal 64
DelayMS 150

TRISB   = %10110010
WPUB    = %00000000                       
ANSELB  = %00000000 

RGV250

Hi,
Remove the HEX and just use this as you are already defining it as hex with the $.
HRSOut2 MyByteArray[0], MyByteArray[1], MyByteArray[2], MyByteArray[3], MyByteArray[4], MyByteArray[5], MyByteArray[6], MyByteArray[7]

Bob

top204

#4
Hello Craig

The raw data transmissions coming from the HRSout2 command are integer values, not Hexadecimal or Decimal.

For ASCII representations of the value in hexadecimal format, the Hex modifier must be used, or use IHex, to also add the preceding "$" character. The same for decimal and binary. i.e. Dec, or Bin or IBin.

For a particular string format to be transmitted, use the amount of characters required in the ASCII value. i.e. IHex2, IHEX3, IHex4 etc...

Or if a particular set is always required, use a String that holds the data to be sent.

The code listing below shows what I mean:

If the "$" character is not required in the values being transmitted, use the Hex2 modifier, instead of IHex2, and also remove them from the ASCII array if not required:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Code listing template to transmit hexadecimal values, on a PIC18F27Q10 device operating at 64MHz.
'
' Written by Les Johnson for the Positron8 BASIC compiler.
' https://sites.google.com/view/rosetta-tech/positron-compilers-experimenters-notebook
'
    Device = 18F27Q10                                               ' Tell the compiler what device to compile for
    Declare Xtal = 64                                               ' Tell the compiler what frequency the device is operating at (in MHz)
    Declare Create_Coff = True                                      ' Tell the compiler to create a COF file for simulation (remove if not simulating)
    Declare Auto_Heap_Arrays = On                                   ' Make all arrays "Heap" types, so they always get placed after standard variables
    Declare Auto_Heap_Strings = On                                  ' Make all Strings "Heap" types, so they always get placed after standard variables
    Declare Auto_Variable_Bank_Cross = On                           ' Make sure all multi-byte variables remain within a single RAM bank
'
' Setup USART2
'
    Declare Hserial2_Baud = 115200                                  ' Set the Baud rate for USART2
    Declare HSerout2_Pin = PORTC.6                                  ' Tell the compiler to setup pin PORTC.6 for USART2 Tx
    Declare HSerin2_Pin  = PORTC.7                                  ' Tell the compiler to setup pin PORTC.7 for USART2 Rx
'
' Create any global variables, constants and aliases here
'
    Dim MyByteArray[8]    As Byte = $5A, $A5, $05, $82, $61, $00, $00, $16  ' Holds hexadecimal integer values
    Dim MyASCII_Array[32] As Byte = "$5A,$A5,$05,$82,$61,$00,$00,$16"       ' Holds ASCII hexadecimal characters
    Dim bIndex            As Byte                                   ' Holds the index to the arrays

'---------------------------------------------------------------------------
' The main program starts here
' Transmit hexadecimal ASCII values from USART2
'
Main:
    Setup()                                                         ' Setup the program and any peripherals
'
' Transmit hexadecimal integer values (with the preceding $ character)
'
    For bIndex = 0 To Bound(MyByteArray)                            ' Create a loop for the amount of elements in the array
        HRSout2 IHex2 MyByteArray[bIndex]                           ' Transmit the hex value, with a preceding "$" character
        If bIndex < Bound(MyByteArray) Then                         ' Is the array finished yet?
            HRSout2 ","                                             ' No. So transmit a comma seperator
        EndIf
    Next                                                            ' Close the loop
    HRsout2 13                                                      ' Transmit a Carriage Return to terminal the transmission
'
' Transmit hexadecimal ASCII characters
'
    For bIndex = 0 To Bound(MyASCII_Array)                          ' Create a loop for the amount of elements in the array
        HRSout2 MyASCII_Array[bIndex]                               ' Transmit the ASCII characters from the array: MyASCII_Array
    Next                                                            ' Close the loop
    HRsout2 13                                                      ' Transmit a Carriage Return to terminal the transmission

'---------------------------------------------------------------------------
' Setup the program and any peripherals
' Input     : None
' Output    : None
' Notes     : None
'
Proc Setup()
'
' Any required setups in here
'
EndProc

'------------------------------------------------------------------------------------------------
' Setup the config fuses to use the internal oscillator to operate at 64MHz on a PIC18FxxQ10 device.
' With RA6 and RA7 as I/O lines.
'
Config_Start
    FEXTOSC = Off                                                   ' External Oscillator not enabled
    RSTOSC = HFINTOSC_64MHZ                                         ' HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
    WDTE = Off                                                      ' Watchdog Timer disabled
    CLKOUTEN = Off                                                  ' CLKOUT function is disabled
    CSWEN = On                                                      ' Writing to NOSC and NDIV is allowed
    FCMEN = Off                                                     ' Fail-Safe Clock Monitor disabled
    MCLRE = EXTMCLR                                                 ' MCLR pin (RE3) is MCLR
    PWRTE = On                                                      ' Power up timer enabled
    LPBOREN = Off                                                   ' Low power BOR is disabled
    BOREN = On                                                      ' Brown-out turned on
    BORV = VBOR_245                                                 ' Brown-out Reset Voltage (VBOR) set to 2.45V
    ZCD = Off                                                       ' ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
    PPS1WAY = Off                                                   ' PPSLOCK bit can be cleared and set multiple times
    STVREN = Off                                                    ' Stack full/underflow will not cause reset
    XINST = Off                                                     ' Extended Instruction Set disabled
    WDTCPS = WDTCPS_14                                              ' Watchdog Timer Divider ratio 1:524299 (16 seconds)
    WDTCWS = WDTCWS_7                                               ' Watchdog Timer Window always open (100%)
    WDTCCS = LFINTOSC                                               ' Watchdog Timer reference clock is the 31.2kHz HFINTOSC output
    WRT0 = Off                                                      ' Block 0 (000800-001FFF) not write-protected
    WRT1 = Off                                                      ' Block 1 (002000-003FFF) not write-protected
    WRT2 = Off                                                      ' Block 2 (004000-005FFF) not write-protected
    WRT3 = Off                                                      ' Block 3 (006000-007FFF) not write-protected
    WRTC = Off                                                      ' Configuration registers (300000-30000B) not write-protected
    WRTB = Off                                                      ' Boot Block (000000-0007FF) not write-protected
    WRTD = Off                                                      ' Data EEPROM not write-protected
    SCANE = Off                                                     ' Scanner module is not available for use, SCANMD bit can control the module
    LVP = On                                                        ' Can use a Low Voltage for programming
    Cp = Off                                                        ' User NVM code protection disabled
    CPD = Off                                                       ' Data NVM code protection disabled
    EBTR0 = Off                                                     ' Block 0 (000800-001FFF) not protected from table reads executed in other blocks
    EBTR1 = Off                                                     ' Block 1 (002000-003FFF) not protected from table reads executed in other blocks
    EBTR2 = Off                                                     ' Block 2 (004000-005FFF) not protected from table reads executed in other blocks
    EBTR3 = Off                                                     ' Block 3 (006000-007FFF) not protected from table reads executed in other blocks
    EBTRB = Off                                                     ' Boot Block (000000-0007FF) not protected from table reads executed in other blocks
Config_End

On a serial terminal, the above program transmits:

$5A,$A5,$05,$82,$61,$00,$00,$16
$5A,$A5,$05,$82,$61,$00,$00,$16



Regards
Les


Craig

Hi Bob
Thanks Very much that has sorted it, It now reads correctly on my serial Terminal. I will now reconnect to Dwin and test that link.
Kind Regards
Craig

Craig

Hi Les

Thanks Very much for such a beautiful example, I will set up and test as this gives me many options.
Kind regards
Craig