How to find the interrupt values of different interrupts like Transmission interrupt,receive interrupt in UART for KEA 128 in code warrior v10.6.4 IDE?, Finding different interrupt values in UART peripheral of KEA128
Hi,
It need to check the UART status Register1 (UARTx_S1), which includes Transmission Complete Flag, Receive Data Register Full Flag and etc.
Using this flag in UART related interrupt service routine to check if it need transfer or receive the data.
Below is a general UART interrupt service routine for your reference:
/********************************************************************/
/* Generic UART status interrupt handler.
* This function is called by the specific UART interupt handler routines,
* so it isn't technically an interrupt handler. The individual interrupt
* handlers will call this function immediately, so this function contains
* most of the code. This function will check all possible interrupt sources,
* so if there are multiple interrupt flags they will all be handled.
*
* NOTE: Since the handler doesn't have access to any transmit or recieve
* buffers from an application layer, the transmit and receive interrupts
* are not really serviced by this routine (don't know what data the application
* would want to transmit and don't know where the application wants receive
* data to be stored).
*
* Parameters:
* channel UART channel that triggered the interrupt
*
*/
void uart_status_handler(UART_MemMapPtr channel)
{
uint8 status, temp;
/* Since the flag clearing mechanism will clear any flags in S1
* that are set, we have to save off the value of the status register
* and then check against the saved value to be able to detect all of
* the flags that were set (if you read the status register over and
* over again, then you'll only capture the first one that was set.
*/
/* Read and save the S1 value */
status = UART_S1_REG(channel);
printf("\nS1= 0x%02x",status);
/* Determine the source of the interrupt */
/* Check to see if the transmit data register empty flag is set */
if (status & UART_S1_TDRE_MASK)
{
printf("\nUART transmit data register empty.\n");
num_tdre_int++;
/* Disable the tx interrupt in the module */
/* Without having data to load in the buffer, this is the only way
* to prevent the interrupt from occurring continuously.
*/
UART_C2_REG(channel) &= ~UART_C2_TIE_MASK;
}
/* Check to see if the transmit complete flag is set */
if (status & UART_S1_TC_MASK)
{
printf("\nUART transmit complete.\n");
num_tc_int++;
/* Disable the tx complete interrupt in the module */
/* Without having data to load in the buffer, this is the only way
* to prevent the interrupt from occurring continuously.
*/
UART_C2_REG(channel) &= ~UART_C2_TCIE_MASK;
}
/* Check to see if the rx full flag is set */
if (status & UART_S1_RDRF_MASK)
{
printf("\nUART receive data register full.\n");
num_rdrf_int++;
/* Read data register to clear the flag */
temp = UART_D_REG(channel);
/* Print out the character received (useful for low power mode tests) */
out_char(temp);
}
/* Check to see if the idle line flag is set */
if (status & UART_S1_IDLE_MASK)
{
printf("\nUART idle line detected.\n");
num_idle_int++;
/* Read data register to clear the flag */
temp = UART_D_REG(channel);
}
}
Wish it helps.
Have a great day,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------