Hi everyone.
I am having problems sending and receiving data through the second serial port of the 18F8722 PIC.
My Fuses and declares are as follows:
Code:
XTAL 10
'Fuse Configuration
CONFIG_START
OSC = HSPLL ;High Speed with PLL
FCMEN = OFF ;Fail-Safe Clock Monitor disabled
IESO = OFF ;Two-Speed Start-up disabled
PWRT = On ;PWRT disabled
BOREN = SBORDIS ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
BORV = 0 ;Minimum setting
WDT = Off ;WDT enabled
WDTPS = 1024 ;1:1,024
MODE = MC ;Microcontroller mode
ADDRBW = ADDR16BIT ;20-bit Address Bus
DATABW = DATA16BIT ;16-bit External Bus mode
Wait = OFF ;Wait selections are unavailable for table reads and table writes
CCP2MX = PORTC ;ECCP2 input/output is multiplexed with RC1
ECCPMX = PORTE ;ECCP1/3 (P1B/P1C/P3B/P3C) are multiplexed onto RE6, RE5, RE4 and RE3 respectively
LPT1OSC = OFF ;Timer1 configured for higher power operation
MCLRE = OFF ;RG5 input pin enabled; MCLR disabled
STVREN = OFF ;Stack full/underflow will not cause Reset
LVP = Off ;Single-Supply ICSP enabled
BBSIZ = BB2K ;1K word (2 Kbytes) Boot Block size
XINST = OFF ;Instruction set extension and Indexed Addressing mode enabled
Debug = OFF ;Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
CP0 = OFF ;Block 0 (000800, 001000 or 002000-003FFFh) not code-protected
CP1 = OFF ;Block 1 (004000-007FFFh) not code-protected
CP2 = OFF ;Block 2 (008000-00BFFFh) not code-protected
CP3 = OFF ;Block 3 (00C000-00FFFFh) not code-protected
CP4 = OFF ;Block 4 (010000-013FFFh) not code-protected
CP5 = OFF ;Block 5 (014000-017FFFh) not code-protected
CP6 = OFF ;Block 6 (01BFFF-018000h) not code-protected
CP7 = OFF ;Block 7 (01C000-01FFFFh) not code-protected
CPB = OFF ;Boot Block (000000-0007FFh) not code-protected
CPD = OFF ;Data EEPROM not code-protected
WRT0 = OFF ;Block 0 (000800, 001000 or 002000-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 (01BFFF-018000h) not write-protected
WRT7 = OFF ;Block 7 (01C000-01FFFFh) not write-protected
WRTC = OFF ;Configuration registers (300000-3000FFh) not write-protected
WRTB = OFF ;Boot Block (000000-007FFF, 000FFF or 001FFFh) not write-protected
WRTD = OFF ;Data EEPROM not write-protected
EBTR0 = OFF ;Block 0 (000800, 001000 or 002000-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-007FFF, 000FFF or 001FFFh) not protected from table reads executed in other blocks
CONFIG_END
PLL_REQ = On 'PLL Devider by 4 so we run at 40MHz
INTCON2.7 = 1 'Disable Pullup Resistors on Port B
ALL_DIGITAL = On 'Set All pins to Digital
'Setup Hardware Serial 1
HSERIAL_BAUD = 38400 'Set baud rate to 38400
HSERIAL_RCSTA = %10010000 'Enable serial port and continuous receive
HSERIAL_TXSTA = $24 'Enable transmit and asynchronous mode
HSERIAL_CLEAR = On 'Enable Error clearing on received characters
'Setup Hardware Serial 2
HSERIAL2_BAUD = 38400 'Set baud rate to 38400
HSERIAL2_RCSTA = %10010000 'Enable serial port and continuous receive
HSERIAL2_TXSTA = $24 'Enable transmit and asynchronous mode
HSERIAL2_CLEAR = On 'Enable Error clearing on received characters
'General Switches
ADCON0.0 = 0 'Disable A/D converter
MEMCON.7 = 1 'Disable External Memory Bus controller on PORT D
CMCON.0 = 1 'Comparators OFF
CMCON.1 = 1
CMCON.2 = 1
For some reason the declares:
Code:
HSERIAL2_BAUD = 38400
HSERIAL2_CLEAR = On
are not being highlighted as the rest of the declares but it compiles fine.
I have managed to go around the serial send/receive problem by doing the following for the receive:
|
Hi, its great to see you
visiting our forum. Why not try Proton Compiler for FREE?
Download the FREE version
of Proton Compiler, Its called Amicus18
and its available from HERE
|
Code:
RCSTA2 = %10010000 'Enable serial port and continuous receive
TXSTA2 = $24 'Enable transmit and asynchronous mode
RCSTA2.7 = 1 'Enable Serial port
RCSTA2.4 = 0 'Continuous Receive Disabled
RCSTA2.4 = 1 'Continuous Receive Enabled
HSerIn2 [Wait("D"),SW_Main_Val[9],SW_Main_Val[10],SW_Main_Val[11]]
RCSTA2.7 = 0 'Disable Serial port
And for the transmit:
Code:
'Our Serial Configs
RCSTA2 = %10010000 'Enable serial port and continuous receive
TXSTA2 = $24 'Enable transmit and asynchronous mode
HSerOut2 ["C","M",UI_Cur_Selection,UI_EEAddress.LowByte,UI_EEAddress.HighByte,1,3,"sss00"] 'Send the command
The problem is that this is unstable and sometimes works and other times i have to reset the IC a couple of times to make it work.
My question is: Is there some bug in the compiler and i get this problem? Also why doesn't the command just work on it's own as the First serial port does and i have to manually reset the port each time?
It doesn't matter if i use HSerout or Hrsout, the problem is the same.
I am using the compiler version: 3.5.2.7
Any help about this would be appreciated.