HSERIN String reading


Closed Thread
Results 1 to 4 of 4
  1. #1

    Default HSERIN String reading

    Hello all,
    I need a little help with HSERIN and STRING reading.
    I try to realise a simple car actual speed reading via OBDII with ELM327 chip.
    The chip communicates via AT commands, and has a serial output. Comm speed is 38400 baud.
    I hooked up 16F690 MCU with 20MHz Xtal, TX and RX pins to UART and try to communicate with HSEROUT and HSERIN.
    My problem is, I cannot get back correct data string.
    For example if sending string "ATI" the answer must be ">ATI ELM327 v1.5"
    This all work fine in serial monitor on PC, but on PIC I don't get back correct data. The data is like: "-_gfh~*1.5u]" or something like this.

    I think I am doing something wrong around HSERIN command. Can me someone explain how to do that on correct way?
    Thanks. Louis.

    Here is my sample code:
    Code:
    #CONFIG
    cfg = _HS_OSC
    cfg&= _WDT_ON
    cfg&= _PWRTE_OFF
    cfg&= _MCLRE_OFF
    cfg&= _CP_OFF
    cfg&= _CPD_OFF
    cfg&= _BOD_ON
    cfg&= _IESO_ON
    cfg&= _FCMEN_ON
     __CONFIG cfg
    #ENDCONFIG
    
    DEFINE OSC 20     ; Use a 20MHz xtal 
    
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_BAUD 38400
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    
    Define LCD_DREG PORTC
    Define LCD_DBIT 0
    Define LCD_RSREG PORTC
    define LCD_RSBIT 4
    define LCD_EREG PORTC 
    define LCD_EBIT 5 
    define LCD_BITS 4
    define LCD_LINES 2
    define LCD_COMMANDUS 2000
    define LCD_DATAUS 50
    
    ANSELH = 0        ; Set RB6 (TX) pin to digital
    ANSEL = 0         ; Set all digital
    TRISA = %011100   ; Set RA5,RA4,RA3 input ; RA2,RA1,RA0 output
    TRISB = %0011     ; Set RB4,RB5 input ; RB6,RB7 output
    TRISC = %00000000 ; Set RC0,RC3,RC4,RC5,RC6, RC1,RC2,RC7 output
    CM1CON0 = 0       ; Disable comparator 1
    CM2CON0 = 0       ; Disable comparator 2
    OPTION_REG.7=1   ; Disable weak pull ups
     
    mai var byte
    Lcdout $fe, 1
    pause 200
    
    main:
    hserout ["ATI",13,10]
    pauseus 300
    HSerin 2000,main,[STR mai\16]  ;>ati ELM327 v1.5
    
    pause 2000
    Lcdout $fe, 1
    lcdout  str mai
    goto main

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: HSERIN String reading

    this will help , but maybe the serial data will need to be inverted
    the pic chip expects the data line to idle " high"

    Code:
    mai var byte[16]
    Lcdout $fe, 1
    pause 200
    
    main:
    hserout ["ATI",13,10]
    pauseus 300
    HSerin 2000,main,[STR mai\16]  ;>ati ELM327 v1.5
    
    pause 2000
    Lcdout $fe, 1
    lcdout  str mai\16
    Warning I'm not a teacher

  3. #3
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: HSERIN String reading

    Looking at the garbled data I would first look at the interface levels and states. When I used one of these OBD interface chips quite a few years ago it was designed to be connected DIRECTLY to the PC. That means the signals are already inverted. To interface it to a PIC you will need to Re-invert the TX and RX signals before connecting it to the PIC. Look at the data sheet. I used an ELM322D OBD(VPW) device.
    Last edited by Dave; - 19th December 2016 at 12:25.
    Dave Purola,
    N8NTA
    EN82fn

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: HSERIN String reading

    Some success comes after applying Richard's changes, thaks. Now I can read strings from ELM chip.

    to: Dave, I don't need to Re-invert the TX and RX signals because the ELM327 is an PIC18F2480 MCU
    and I connected the UART pins directly to PIC16F690 UART pins.
    I think it's OK.

Similar Threads

  1. HSERIN string starting index ?
    By gunayburak in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 4th July 2016, 22:54
  2. Hserin parsing string...again?
    By kevlar129bp in forum Serial
    Replies: 21
    Last Post: - 9th July 2012, 16:35
  3. HSERIN for variable length string
    By Pic2008 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 19th February 2010, 05:58
  4. parsing string from hserin
    By xxxxxx in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 2nd April 2009, 18:42
  5. Reading RS232 String
    By Peter1960 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 6th June 2005, 09:02

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts