Hi,
I'm wondering what I'm doing wrong in my programs.
Each time I use SERIN2/SEROUT2 commands, the very first data received on the other end is garbage. The correct data will appear only after I've sent the data from the second time and on. I can see this on my serial LCD, on any serial com software or even in the PICKit2's UART tool.
I found out that if I do not to declare the receiving port (here PORTB.5) as an Input in the TRIS register, the garbage is gone.
Any idea what I'm doing wrong? Am I missing some init stuff or any DEFINE?
Code:
' Serial Comm test
' ====== FUSES =====================================================================================
' PIC 16F690
@ __Config _FCMEN_OFF &_IESO_OFF &_CPD_OFF &_WDT_OFF &_HS_OSC &_BOR_OFF &_CP_OFF &_PWRTE_OFF &_MCLRE_OFF
' ====== REGISTERS =================================================================================
' 76543210
OPTION_REG = %10000000 ' PORT A&B Pull-Ups disabled (look WPUA & WPUB) INTEDG rising edge on A2
ANSEL = %00000000 ' Analog inputs Channels 0 to 7
ANSELH = %00000000 ' Analog inputs Channels 8 to 11
ADCON0 = %00000000 ' A/D Module is OFF
CM1CON0 = %00000000 ' Comparator1 Module is OFF
CM2CON0 = %00000000 ' Comparator2 Module is OFF
INTCON = %00000000 ' INTerrupts CONtrol
TRISA = %00000100 ' Set Input/Output (0 to 5)
PORTA = %00000000 ' Ports High/Low (0 to 5)
'''
TRISB = %00010000 ' Set Input/Output (4 to 7)
'''
PORTB = %00000000 ' Ports High/Low (4 to 7)
TRISC = %00000000 ' Set Input/Output (0 to 7)
PORTC = %00000000 ' Ports High/Low (0 to 7)
' ====== DEFINES ===================================================================================
DEFINE OSC 4
' ====== VARIABLES =================================================================================
Serial_In VAR PORTB.5 ' serial data in
Serial_Out VAR PORTB.7 ' serial data out
PollFlag VAR BIT ' if POLLING is requested, set flag
PollFlag = 0
'Serial_Bps CON 84 'For PICKit2 (9600 Driven True None)
Serial_Bps CON 32852 'For FTDI cable (9600 Open True None)
'Serial_Bps CON 16468 'For PC, HyperTerminal, MCS Terminal, LCD Display (9600 Driven Inverted None)
'======= PROGRAM ===================================================================================
MAIN:
SERIN2 Serial_In, Serial_Bps, [WAIT ("POLL"),DEC PollFlag]
IF PollFlag = 1 THEN
SEROUT2 Serial_Out, Serial_Bps, ["Hello",13,10]
ENDIF
GOTO MAIN:
END
Bookmarks