Why isn't my interrupt for UART working?
PIC18F13K22
Code: Select all
PIR1.RCIF = 0 ; // EUSART Receive Interrupt Flag bit
// 1 = The EUSART receive buffer, RCREG, is full (cleared when RCREG is read)
// 0 = The EUSART receive buffer is empty
PIR1.TXIF = 1 ; // EUSART Transmit Interrupt Flag bit
// 1 = The EUSART transmit buffer, TXREG, is empty (cleared when TXREG is written)
// 0 = The EUSART transmit buffer is full
RCSTA.SPEN = 1 ; // 1 = serial port enabled (configures Rx/DT & Tx/CK pins as serial port pins).
RCSTA.RX9 = 0 ; // 0 = Selects 8-bit reception
RCSTA.SREN = 1 ; // 1 = Enables single receive
RCSTA.CREN = 1 ; // enable reception
PIE1.RCIE = 1 ; // enable UART_1 RX interrupt
IPR1.RCIP = 1 ; // EUSART high priority level
RCON.IPEN = 1; /* Enable priority levels on interrupts */
GIEH_bit = 1; /* Enable High Level Interrupts */
GIEL_bit = 1; /* Enable Low Level Interrupts */
UART1_Init(19200) ; // Initialize UART module at 19200
Delay_ms(150) ;
Code: Select all
void Interrupt_High() iv 0x0008 ics ICS_AUTO { /*** High Interrupt ***********/
unsigned char uart_tmp_char ;
//RS_USART_Flag = ON ; THIS FLAG IS NOT SET EVEN HERE, SO THE HIGH INTERRUPT IS NOT TRIGGERED
if(PIR1.RCIF) { // EUSART Receive Interrupt Flag bit
PIE1.RCIE = 0 ; // Disable UART_1 RX interrupt
uart_tmp_char = RCREG ; // read character from Uart1 EUSART Receive Register
// Get the data; PIR1.RC1IF is cleared when RCREG1 is read
RS_UART_Array[rx3i] = uart_tmp_char ;
rx3i++;
if(uart_tmp_char == 0x03) { // 0x03 = ETX = End of Tx
RS_USART_Flag = ON ;
}
//** it is necessary to clear manually the interrupt flag:
PIR1.RCIF = 0 ; // CLEAR UART1 INTERRUPT FLAG PIR1.RC1IF is cleared when RCREG1 is read
PIE1.RCIE = 1 ; // Enable UART_1 RX interrupt
} /*** End of if(PIR1.RC1IF == 1) *******************************************/
}/*** End of High Interrupt ***************************************************/
Code: Select all
void Interrupt(){
RS_USART_Flag = ON ;
}
Tx pin is on RB7
Code: Select all
/* PORTB is 4-bit wide, */
PORTB = 0b1010 ;
TRISB = 0b0010 ; // RB5=In,
LATB = 0b1010 ;
TRISB.TRISB5 = 1; // RX - UART1
TRISB.TRISB7 = 0; // TX - UART1