UART4 interrupt handler on K24

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

UART4 interrupt handler on K24

Jump to solution
1,212 Views
ryanlush
Contributor IV

I've setup my UART like so. Notice most of the interrupts are commented out.

   // Configure the UART
    UART_GetDefaultConfig(&config);
    config.baudRate_Bps = 9600;
    config.enableTx = true;
    config.enableRx = true;
    UART_Init(UART4, &config, 120000000);

    // Enable RX interrupt.
    UART_EnableInterrupts(UART4, kUART_RxDataRegFullInterruptEnable /* |
                                    kUART_NoiseErrorInterruptEnable |
                                  kUART_FramingErrorInterruptEnable |
                                   kUART_ParityErrorInterruptEnable */ );
    EnableIRQ(UART4_RX_TX_IRQn);

and here is my handler

static void GPS_UART_ISR(void)
{
    uint8_t statReg = UART_GetStatusFlags(UART4); /* Read status register */
    uint8_t data; /* Temporary variable for data */

    /* Is any error flag set? */
    if(statReg & (kUART_NoiseErrorFlag | kUART_RxOverrunFlag | kUART_FramingErrorFlag | kUART_ParityErrorFlag))
    {
        data = UART_ReadByte(UART4);
    }
    else if(statReg & kUART_RxDataRegFullFlag)
    {
        data = UART_ReadByte(UART4);
        if (gpsMode == 0)
            HandleBootData(data);
        else
            HandleNMEAData(data);
    }
}

I'm feeding it a near perfect (104.4us bit width) 9600 baud signal yet all I catch is errors. Every error flag is set when I enter the handler. Am I doing something wrong? I've been using this handler for a couple years now with no issue.

0 Kudos
Reply
1 Solution
1,049 Views
ryanlush
Contributor IV

I had forgotten that UART1 & UART2 are the only ones that run off the system clock. UART4 runs off the bus clock so it should have been

UART_Init(UART4, &config, 60000000);

rather than

UART_Init(UART4, &config, 120000000);

View solution in original post

0 Kudos
Reply
2 Replies
1,050 Views
ryanlush
Contributor IV

I had forgotten that UART1 & UART2 are the only ones that run off the system clock. UART4 runs off the bus clock so it should have been

UART_Init(UART4, &config, 60000000);

rather than

UART_Init(UART4, &config, 120000000);

0 Kudos
Reply
1,049 Views
ryanlush
Contributor IV

I have a break point on the first line of the handler, before reading the S1 status register and can see the value is 0xF4. I'm not sure why the noise flag is set, things look really crisp on my scope which is on a test pad right next to the chip.

But anyways, the value stored in statReg is 0xC0. I didn't think the value of S1 was supposed to change until I read the data register. I've attached the assembly code for someone smarter than me to explain (please?).

Untitled.jpg

0 Kudos
Reply