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




Bookmarks