UART4 interrupt handler on K24

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

UART4 interrupt handler on K24

跳至解决方案
1,224 次查看
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 项奖励
回复
1 解答
1,061 次查看
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 项奖励
回复
2 回复数
1,062 次查看
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 项奖励
回复
1,061 次查看
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 项奖励
回复