I'm having difficulties making my PIC's HSEROUT working at all. I need to get 115200bps.
I can reach 38400bps with the SEROUT2 command without any trouble.
For 115200bps, I go with HSEROUT. I use the MCS Serial Communicator and the PIC has a 20MHz crystal.
SEROUT2 is okay, HSEROUT is not working at all (not even @1200bps).
I've been trying to make it work for hours and hours, redoing the cabling (see picture) different ways as suggested in other threads, modifying the code also many times but no success until now. I just always get garbage on the serial terminal's screen.
Code:
' SEROUT2
' PIC 16F690 Fuses
@ __Config _FCMEN_OFF &_IESO_OFF &_BOR_OFF &_CPD_OFF &_CP_OFF &_MCLRE_OFF &_PWRTE_OFF &_WDT_OFF &_HS_OSC
OPTION_REG = 000000 'PORT A&B Pull-Ups (look WPUA & WPUB)
ADCON0 = 000000 'A/D Module
ANSEL = 000000 'Select analog inputs Channels 0 to 7
ANSELH = 000000 'Select analog inputs Channels 8 to 11
INTCON = 000000 'INTERRUPT Control
'WPUA = 000000 'Select PORTA weak pull-ups
'IOCA = 000000 'Interrupt On Change selection
CM1CON0 = 000000 'Comparator1 Module
CM2CON0 = 000000 'Comparator2 Module
TRISA = 000000 'Set Input/Output (0 to 5)
PORTA = 000000 'Ports High/Low (0 to 5)
TRISB = 000000 'Set Input/Output (4 to 7)
PORTB = 000000 'Ports High/Low (4 to 7)
TRISC = 000000 'Set Input/Output (0 to 7)
PORTC = 000000 'Ports High/Low (0 to 7)
'-------------------------------------------------------------------------------
' DEFINEs
DEFINE OSC 20
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
'-------------------------------------------------------------------------------
LED1 VAR PORTA.2
Counter VAR WORD
Counter = 0
TEST:
TOGGLE LED1
'serout2 PORTB.7,16416,[dec counter,13,10]'19200 DIN with MAX232
SEROUT2 PORTB.7,16390,[DEC Counter,13,10]'38400 DIN with MAX232
PAUSE 500
Counter = Counter + 1
GOTO TEST
END
Code:
' HSEROUT
' PIC 16F690 Fuses
@ __Config _FCMEN_OFF &_IESO_OFF &_BOR_OFF &_CPD_OFF &_CP_OFF &_MCLRE_OFF &_PWRTE_OFF &_WDT_OFF &_HS_OSC
OPTION_REG = 000000 'PORT A&B Pull-Ups (look WPUA & WPUB)
ADCON0 = 000000 'A/D Module
ANSEL = 000000 'Select analog inputs Channels 0 to 7
ANSELH = 000000 'Select analog inputs Channels 8 to 11
INTCON = 000000 'INTERRUPT Control
'WPUA = 000000 'Select PORTA weak pull-ups
'IOCA = 000000 'Interrupt On Change selection
CM1CON0 = 000000 'Comparator1 Module
CM2CON0 = 000000 'Comparator2 Module
TRISA = 000000 'Set Input/Output (0 to 5)
PORTA = 000000 'Ports High/Low (0 to 5)
TRISB = 000000 'Set Input/Output (4 to 7)
PORTB = 000000 'Ports High/Low (4 to 7)
TRISC = 000000 'Set Input/Output (0 to 7)
PORTC = 000000 'Ports High/Low (0 to 7)
'-------------------------------------------------------------------------------
' DEFINEs
DEFINE OSC 20
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_BAUD 19200
'DEFINE HSER_SPBRG 64
DEFINE HSER_CLOERR 1
'-------------------------------------------------------------------------------
LED1 VAR PORTA.2
Counter VAR WORD
Counter = 0
TEST:
TOGGLE LED1
HSEROUT [DEC Counter,13,10]
PAUSE 500
Counter = Counter + 1
GOTO TEST
END
There's a MAX232 close to the PIC making me think the lines are as short as possible. But is it enough on the hw side?
Bookmarks