I am using PIC32 and I have few inputs. I want a UART Tx Interrupt
to fire whenever any input becomes HIGH. I have somehow manged to write code for UART tx and rx interrupt and its working but I don't have an idea how to implement it for my application.
int main()
{
//configure UART
UARTConfigure(UART1, UART_ENABLE_PINS_TX_RX_ONLY);
UARTSetFifoMode(UART1, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
UARTSetLineControl(UART1, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
UARTSetDataRate(UART1, FPB, 115200);
UARTEnable(UART1, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));
// Configure UART Interrupt
INTEnable(INT_SOURCE_UART_RX(UART1), INT_ENABLED);
INTSetVectorPriority(INT_VECTOR_UART(UART1), INT_PRIORITY_LEVEL_2);
INTSetVectorSubPriority(INT_VECTOR_UART(UART1), INT_SUB_PRIORITY_LEVEL_0);
// Enable multi-vector interrupts
INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
INTEnableInterrupts();
while(1)
{
//main code
}
}
void __ISR(_UART1_VECTOR, ipl2) IntUart1Handler(void)
{
// RX interrupt
if(INTGetFlag(INT_SOURCE_UART_RX(UART1)))
{
// Clear the RX interrupt Flag
INTClearFlag(INT_SOURCE_UART_RX(UART1));
// Echo what we just received.
char RxBuffer[5];
if((U1STAbits.URXDA)!=0)
{
getsUART1(5,RxBuffer , 123);
U1STAbits.URXDA = 0;
U1STAbits.OERR = 0;
putsUART1(RxBuffer);
putsUART1("\n");
memset(RxBuffer,0,5*sizeof(char));
}
}
// TX interrupt
if ( INTGetFlag(INT_SOURCE_UART_TX(UART1)) )
{
INTClearFlag(INT_SOURCE_UART_TX(UART1));
}
}
I don't know what logic should I made so that if any inputs become HIGH, lets say
if(INPUT1 == HIGH)
{
//generate UART tx interrupt
}
Please help. Thanks!
Answer
Use pseudo-code:
if(INPUT1 == HIGH)
{
//fill Tx FIFO buffer with some data, which causes UART Tx interrupt
}
UART TX interrupt is fired, when UART TX FIFO buffer is filled with data.
No comments:
Post a Comment