I've got a MicroChip development board that contains the 18F8720 chip n stuff, and can run the canned demo just fine so I know my hardware is fine. I am having trouble with rx, tx works fabulous. Ive set break points to look at the rx interupt flag but it never seems to get set...thus never get anything on the rx side. I know the code is long, but figured better to include everything. Can anyone see something in my setup that prevents rx from working? thanks guys Jamie ;------------------------------------------------------ LIST P=18F8720 #include ; File contains addresses for register and bit names __CONFIG _CONFIG1H, _OSCS_OFF_1H & _HS_OSC_1H __CONFIG _CONFIG2L, _BOR_ON_2L & _BORV_20_2L & _PWRT_OFF_2L __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H __CONFIG _CONFIG3L, _WAIT_OFF_3L & _MC_MODE_3L __CONFIG _CONFIG3H, _CCP2MX_ON_3H __CONFIG _CONFIG4L, _STVR_ON_4L & _LVP_OFF_4L & _DEBUG_ON_4L __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L & _CP4_OFF_5L & _CP5_OFF_5L & _CP6_OFF_5L & _CP7_OFF_5L __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L & _WRT4_OFF_6L & _WRT5_OFF_6L & _WRT6_OFF_6L & _WRT7_OFF_6L __CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L & _EBTR4_OFF_7L & _EBTR5_OFF_7L & _EBTR6_OFF_7L & _EBTR7_OFF_7L __CONFIG _CONFIG7H, _EBTRB_OFF_7H ERRORLEVEL -302 ; suppress bankselect messages ; base frequency XTAL_FREQ EQU 20000000 ; OSC freq in Hz ; handy ASCII character table STX EQU 0x02 ; stx ETX EQU 0x03 ; etx BEL EQU 0x07 ; bell BS EQU 0x08 ; backspace TAB EQU 0x09 ; horizontal tab LF EQU 0x0A ; line feed FF EQU 0x0C ; form feed CR EQU 0x0D ; carriage return XON EQU 0x11 ; transmit on XOFF EQU 0x13 ; transmit off EOF EQU 0x1A ; end of file ESC EQU 0x1B ; escape SP EQU 0x20 ; space cblock 0x0020 RXinOffset RXoutOffset RX_count RX_status RXtemp TXinOffset TXoutOffset TX_count TX_temp TX_str_count TX_str_size TX_status ;Status/Control for transmit FIFO ;Bit 7; 0= Call to put failled becouse put FIFO is full. 1= Call to put exicquted ok. FSRH_temp FSRL_temp delay_hi delay_low ISR_blink WREG_TEMP ;variable used for context saving STATUS_TEMP ;variable used for context saving BSR_TEMP ;variable used for context saving tempvalue,LD1,LD2,safe_w,safe_s,cmd_compare,Temp1,CmdRetry,COMMAND ENDC ;****************************************************************************** BRGH_value equ .1 SPBRG_value equ .64 ; 20MHz, 9600 baud RX_BUFFER_START equ 0x100 ; first byte of transmit buffer RX_BUFFER_END equ 0x1FF ; last byte of transmit buffer TX_BUFFER_START equ 0x200 ; first byte of transmit buffer TX_BUFFER_END equ 0x2FF ; last byte of transmit buffer RX_CTS_DEPTH equ 0x0F TX_RTS_DEPTH equ 0x0F RX_DATA_DEPTH equ RX_BUFFER_END-RX_BUFFER_START-RX_CTS_DEPTH TX_DATA_DEPTH equ TX_BUFFER_END-TX_BUFFER_START-TX_RTS_DEPTH #define RTS_PIN RB2 #define RTS_PORT PORTB #define CTS_PIN RB4 #define CTS_PORT LATB ;****************************************************************************** ;Variable definitions ;****************************************************************************** ;Reset vector ORG 0x0000 nop goto Main ;go to start of main code ;****************************************************************************** ; High priority interrupt vector ORG 0x0008 bra HighInt ;go to high priority interrupt routine ;****************************************************************************** ; Low priority interrupt vector and routine ORG 0x0018 movff STATUS, STATUS_TEMP ;save STATUS register movff WREG, WREG_TEMP ;save working register movff BSR, BSR_TEMP ;save BSR register TIMER2_ISR btfss PIR1, TMR2IF, ACCESS ;Test TIMER #2 interupt flag. goto TIMER2_end incf ISR_blink, f, ACCESS movff ISR_blink, LATD bcf PIR1, TMR2IF, ACCESS ;Reset TIMER #2 interupt flag. TIMER2_end ;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------ Rx_ISR btfss PIR1, RCIF, ACCESS ;USART Rx ISR? bra Rx_ISR_end movff FSR2L, FSRL_temp ;Save FSR2 movff FSR2H, FSRH_temp lfsr FSR2, RX_BUFFER_START ;Set FSR2 for start of get FIFO. movff RXinOffset, FSR2L movff RCREG1, INDF2 ; move byte from USART to receive buffer movlw low RX_BUFFER_END ; Is RXinOffset = buffer end? cpfseq RXinOffset, ACCESS bra _Rx_ISR_0 clrf RXinOffset, ACCESS ; Yes, so reset RXinOffset pointer to begining of buffer. bra _Rx_ISR_1 _Rx_ISR_0 incf RXinOffset, f, ACCESS ; No, so incrment RXinOffset. _Rx_ISR_1 incf RX_count, f, ACCESS ; Incrment RX_count. movf RX_count, w, ACCESS ; and test buffer free space. sublw RX_DATA_DEPTH ; against depth of the buffer bn _Rx_ISR_full ; and if full, exit out ; bcf CTS_PORT, CTS_PIN, ACCESS ; No, so clear CTS pin. (ok to Rx from DTE) bra _Rx_ISR_3 _Rx_ISR_full bsf CTS_PORT, CTS_PIN, ACCESS ; Yes, so set CTS pin. (Stop DTE from sending more data.) _Rx_ISR_3 movff FSRL_temp, FSR2L ; Restore registers back movff FSRH_temp, FSR2H Rx_ISR_end ;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------ btfss INTCON3, INT2IF, ACCESS ;Is INT2 interupt flag set? bra Tx_ISR ; No, so test Tx ISR. bcf INTCON3, INT2IF, ACCESS ; Yes, so clear INT2 flag, and... bsf PIE1, TXIE, ACCESS ; skip testing for Tx ISR bit enabled. bra _Tx_ISR_do Tx_ISR btfss PIE1, TXIE, ACCESS ;Skip if Tx interupts not enabled. bra Tx_ISR_end btfss PIR1, TXIF, ACCESS ;USART Tx ISR? bra Tx_ISR_end _Tx_ISR_do movf TXoutOffset, w, ACCESS ;Is TXoutOffset==TXinOffset? cpfseq TXinOffset, ACCESS bra _Tx_ISR_0 bcf PIE1, TXIE, ACCESS ; Yes, so disable Tx interupts bra Tx_ISR_end ; return _Tx_ISR_0 movff FSR2L, FSRL_temp ; first save FSR2 movff FSR2H, FSRH_temp lfsr FSR2,TX_BUFFER_START ; set FSR2 for start of Tx buffer movff TXoutOffset, FSR2L bcf TXSTA, TX9D, ACCESS ; %selects 8 bits if cleared movff INDF2, TXREG1 ; get a byte off the FIFO and load it to TXREG. (Transmition will start now.) movlw low TX_BUFFER_END cpfseq TXoutOffset, ACCESS ; Is TXoutOffset equal to buffer end bra _Tx_ISR_1 clrf TXoutOffset, ACCESS ; reset TXoutOffset pointer to begining of FIFO. decf TX_count, f, ACCESS ; Decrment TX_count. bra _Tx_ISR_2 _Tx_ISR_1 incf TXoutOffset, f, ACCESS ; incrment TXoutOffset. decf TX_count, f, ACCESS ; and Decrment TX_count. _Tx_ISR_2 movff FSRL_temp, FSR2L ;Restore FSR2 movff FSRH_temp, FSR2H Tx_ISR_end ;------------------------------------------------------------------------------ movff BSR_TEMP, BSR ;restore BSR register movff WREG_TEMP, WREG ;restore working register movff STATUS_TEMP, STATUS ;restore STATUS register retfie ;****************************************************************************** ;High priority interrupt routine HighInt: retfie FAST ;****************************************************************************** ;Start of main program Main: clrf TRISD, ACCESS bsf PORTD,0 bcf PORTD,1 ;**** RS232 setup **** clrf RX_status clrf RXinOffset, ACCESS ;Clear pointer for recieve buffer write clrf RXoutOffset, ACCESS ;Clear pointer for recieve buffer read clrf RX_count, ACCESS clrf TX_status ; clear status register clrf TXinOffset, ACCESS ;Clear pointer for transmit buffer write clrf TXoutOffset, ACCESS ;Clear pointer for transmit buffer read clrf TX_count, ACCESS bcf INTCON3, INT2IP, ACCESS ;INT2 is low priority interupt for CTS pin. bcf INTCON3, INT2IF, ACCESS ;Clear INT2 flag incase it's set. bsf INTCON3, INT2IE, ACCESS ;Enable INT2 interupts. bcf TRISC, .6, ACCESS ;Setup USART bsf TRISC, .7, ACCESS movlw SPBRG_value movwf SPBRG1, ACCESS movf RCREG1, w, ACCESS ;Flush Rx buffer. movf RCREG1, w, ACCESS movf RCREG1, w, ACCESS bcf IPR1, RCIP, ACCESS ;Low Rx interupt priority. bsf PIE1, RCIE, ACCESS ;Enable Rx interupts. bcf IPR1, TXIP, ACCESS ;Low Tx interupt priority. ; movlw b'01100100' ;Setup transmit control register. movlw b'00100100' ;Setup transmit control register 8bits,async,BRH=high speed movwf TXSTA1, ACCESS ; movlw b'11010000' ;Setup recive control register. movlw b'10010000' ;%Setup RX reg [en,8bits,x,en rx,] movwf RCSTA1, ACCESS ;*** Setup Timer2 for .5mS *** movlw .125 movwf PR2, ACCESS bcf IPR1, TMR2IP, ACCESS ;Timer #2 is a low priority interupt. bsf PIE1, TMR2IE, ACCESS ;Enable Timer #2 interupts. movlw b'01010111' movwf T2CON, ACCESS clrf ISR_blink, ACCESS ; bsf RCON, IPEN, ACCESS ; reset register, enable priority levels on interupt bsf INTCON, GIEH, ACCESS bsf INTCON, GIEL, ACCESS movlw low DISP_HELLO ; send a string movwf TBLPTRL, ACCESS movlw high DISP_HELLO movwf TBLPTRH, ACCESS movlw HELLO_SIZE movwf TX_str_size, ACCESS call WriteString call SetOne nop Loop Delay_Loop Delay_Loop_Hi Delay_Loop_Low nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop Delay_End call Get_Char btfss RX_status, .7, ACCESS bra Loop call WriteCharacter goto Loop ;====================================================================================================================== ; Write a character in the transmit buffer ;====================================================================================================================== WriteCharacter movwf TX_temp, ACCESS ; save Wreg to the temp reg movlw TX_DATA_DEPTH ; cpfsgt TX_count, ACCESS ; Check for space in the transmit buffer bra _WriteChar ; yes, so write to buffer bcf TX_status, .7, ACCESS ; No, so clear status bit indicating write failed return ; then exit out _WriteChar lfsr FSR2,TX_BUFFER_START ;Load FSR2 with the start of the write register, then... movff TXinOffset, FSR2L ; load TXinOffset into FSR2 low byte to point to the next free location movff TX_temp, INDF2 ; and store to write buffer movlw low TX_BUFFER_END cpfseq TXinOffset, ACCESS ; Is TXinOffset==buffer end? bra _WriteChar0 ; no, so write character clrf TXinOffset, ACCESS ; Yes, so reset TXinOffset pointer to begining of buffer incf TX_count, f, ACCESS ; and incrment TX_count. bsf TX_status, .7, ACCESS ; and set status ok. bsf PIE1, TXIE, ACCESS ; and enable Tx interupts. return _WriteChar0 incf TXinOffset, f, ACCESS ; incrment TXoutOffset incf TX_count, f, ACCESS ; and incrment TX_count bsf TX_status, .7, ACCESS ; and set status ok. bsf PIE1, TXIE, ACCESS ; and enable Tx interupts. return ;====================================================================================================================== ; Write a string in the transmit buffer ;====================================================================================================================== WriteString ;Put_Str movf TX_count, w, ACCESS ; check for a full transmit buffer addwf TX_str_count, w, ACCESS bc _ExitWriteString ; if string length longer than free buffer, exit sublw TX_DATA_DEPTH bn _WriteString ; string fits in buffer, so write _ExitWriteString bcf TX_status, .7, ACCESS ; write failed, clearing the status bit return ; and exit out _WriteString clrf TX_str_count ; Counts the string charicters sent to the buffer. lfsr FSR2, TX_BUFFER_START ; Load FSR2 with the start of the transmit register. _WriteString0 movf TX_str_size, w, ACCESS ; Is string size_size equal to the count? cpfseq TX_str_count, ACCESS bra _WriteString1 bsf TX_status, .7, ACCESS ; Write was successful, set bit return ; and exit _WriteString1 movff TXinOffset, FSR2L ; No, get next character from the string tblrd *+ movff TABLAT, INDF2 ; and write to the buffer. movf TXinOffset, w, ACCESS ; Was this the last byte of the buffer sublw low TX_BUFFER_END bz _WriteString2 incf TXinOffset, f, ACCESS ; No, so incrment TXinOffset pointer. incf TX_count, f, ACCESS ; Incrment TX_count. incf TX_str_count, f, ACCESS ; Incrment string counter, then... bra _WriteString0 ; get next character from the string. _WriteString2 clrf TXinOffset, ACCESS ; Yes, so restart TXinOffset pointer. incf TX_count, f, ACCESS ; Incrment TX_count. incf TX_str_count, f, ACCESS ; Incrment string counter bra _WriteString0 ; get next charicter from the string. ;====================================================================================================================== SetOne movlw 'H' call WriteCharacter movlw 'E' call WriteCharacter movlw 'L' call WriteCharacter movlw 'L' call WriteCharacter movlw 'O' call WriteCharacter movlw ' ' call WriteCharacter movlw 'W' call WriteCharacter movlw 'O' call WriteCharacter movlw 'R' call WriteCharacter movlw 'L' call WriteCharacter movlw 'D' call WriteCharacter movlw ' ' call WriteCharacter movlw 'I' call WriteCharacter movlw 't' call WriteCharacter movlw 's' call WriteCharacter movlw ' ' call WriteCharacter return ;====================================================================================================================== DISP_TABLES DISP_HELLO db "Hello World " HELLO_SIZE equ $-DISP_HELLO ;====================================================================================================================== ;RX_status; bit 7, 0=Ttelling calling program that WREG does not contain valid data. ;====================================================================================================================== Get_Char movf RX_count, w, ACCESS ;Are their any bytes in the "get" FIFO? (RX_count!=0) bnz _Get_a_byte ; bcf RX_status, .7, ACCESS ; No, so clear "data avalible" bit 0 in RX_status, and... ; bcf LATB, CTS_PIN, ACCESS ; clear CTS pin (in case it was cleared). return _Get_a_byte lfsr FSR2, RX_BUFFER_START ;Load FSR2 with the start of the GET register, and... movff RXoutOffset, FSR2L ; load the offset. movff INDF2, RXtemp ; get a byte from the FIFO. movlw low RX_BUFFER_END ;Is RXoutOffset==GET_END? cpfseq RXoutOffset, ACCESS bra _Get_Char_1 clrf RXoutOffset, ACCESS ; Yes, so reset RXoutOffset pointer to begining of FIFO. bra _Get_Char_2 _Get_Char_1 incf RXoutOffset, f, ACCESS ; No, so incrment RXoutOffset. _Get_Char_2 decf RX_count, f, ACCESS ;Decrment RX_count. movf RX_count, w, ACCESS ;Now test FIFO free space. Is RX_count>GET_DATA_SPACE? sublw RX_DATA_DEPTH bn _Get_FIFO_full bcf LATB, CTS_PIN, ACCESS ; No, so clear CTS pin. (ok to Rx from DTE) bra _Get_Char_3 _Get_FIFO_full bsf CTS_PORT, CTS_PIN, ACCESS ; Yes, so set CTS pin. (Stop DTE from sending more data.) _Get_Char_3 movf RXtemp, w, ACCESS ;Load the data byte to Working register. bsf RX_status, .7, ACCESS ;Tell calling program that there is data in WREG. return END __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist