简体   繁体   中英

Cannot Read UART data

What I'm trying to do is simple enough, read ASCII data from UART. I'm using an NXP kl27 and am using Kinetis 1.2.0. I have a GPS (tx pin) wired to pin PTD2, and have that pin configured to be UART2_Rx.

PORT_HAL_SetMuxMode(PORTD,2u,kPortMuxAlt3); //UART2_Rx
PORT_HAL_SetMuxMode(PORTE,22u,kPortMuxAlt4); //UART2_Tx (unused)

The configuration for the UART object is as follows:

uart_user_config_t g_uartConfig= {
    .baudRate = 9600u,
    .parityMode = kUartParityDisabled,
    .stopBitCount = kUartOneStopBit,
    .bitCountPerChar = kUart8BitsPerChar,
};

Finally, here is the code I'm using to try and recieive UART data:

uart_state_t g_uartState;
UART_DRV_Init(2u, &g_uartState, &g_uartConfig);

uint8_t rxChar
// Uart #, return data, data count, timeout in miliseconds
UART_DRV_ReceiveDataBlocking(2u, &rxChar, 1u,1000u);

The problem is UART_DRV_RecieveDataBlocking never returns.

Here is the relevant parts of the schematic if that helps: 图

What I've Tried

  1. I have confirmed that the GPS is outputting data
  2. I have confirmed that pin PTD2 is in fact connected and receiving data (thanks to an oscilloscope)
  3. Sending UART data with pin PTE22 to see if the fault lied with the UART object. The data sent successfully.
  4. Debugging with GDB. This quickly turned into a rabbit hole and I just gave up after a while. What I did find out is that the code waits forever in the debugger after calling UART_SET_C3 in fsl_uart_hal.c ( line 325 )
  5. Altering the config object (changing parityMode).

Far as I can tell I'm following every example/demo I've seen with reading UART data. If anyone has any ideas about what is going on I'd love to hear it.

The problem was indeed software. My cmakeLists file was missing this:

"${ProjDirPath}/KSDK_1.2.0/platform/drivers/src/uart/fsl_uart_irq.c"

This file properly sets up the UART interrupts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM