I am very new to PIC32 chips (or any PIC chips) and I am trying to create an interrupts handler for the UART to be called when the UART receive a byte. I am using the PIC32MX695F512L PIC32 processor with C32 2.00 compiler on a development board.
I found this example code in another project online. The comments led me to belive that this interrupt would be called whenever the UART receives a byte. I added a break point to this function and a static counter to count how many times this function has been run.
In other parts of the source code I can send BYTES out of the UART and are being revived by my PC. I have tried sending BYTES to the UART from my PC but this function is never triggered and the function counter (UART1Info_count
) never increases.
Source code
static BYTE UART1Info_LastByteRXed ;
static UINT32 UART1Info_count ; // Init elsewhere
BOOL Uart_Connect ( ) {
UART1Info_count = 0 ;
UART1Init();
UARTConfigure (UART1, UART_ENABLE_PINS_TX_RX_ONLY);
UARTSetFifoMode (UART1, UART_INTERRUPT_ON_RX_NOT_EMPTY);
UARTSetLineControl (UART1, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1 );
UARTSetDataRate (UART1, GetPeripheralClock(), 9600) ;
UARTEnable (UART1, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));
INTEnable (INT_SOURCE_UART_RX(UART1), INT_ENABLED);
INTEnable (INT_SOURCE_UART_TX(UART1), INT_ENABLED);
// Set Interrupt priorities
INTSetVectorPriority (INT_VECTOR_UART(UART1), INT_PRIORITY_LEVEL_2);
INTSetVectorSubPriority (INT_VECTOR_UART(UART1), INT_SUB_PRIORITY_LEVEL_0);
// configure for multi-vectored mode
INTConfigureSystem (INT_SYSTEM_CONFIG_MULT_VECTOR);
INTEnableInterrupts ();
Rs485RxLineConfig();
Rs485TxLineConfig();
Rs485TxDisable();
Rs485RxEnable();
return TRUE ;
}
#define __UART_1_ISR __ISR(_UART_1_VECTOR, ipl4)
void __UART_1_ISR UART_1_InterruptRoutine(void)
{
UART1Info_count++ ;
IFS0CLR = _IFS0_U1RXIF_MASK;
UART1Info_LastByteRXed = UART1ReceivedValue();
UART1TransmitTestASCIICharacters( (UART1Info_LastByteRXed+1), 1); //reflect back character, incremented by 1
}
Other information
- Processor: PIC32MX695F512L
- Compiler: C32 v2.00
- IDE: MPLAB X IDE
My question
How to I create a interrupt handler on receive BYTE via UART on PIC32 with C32 v2.00 compiler?
Note: Updated source code example with UART init()