This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] TM4C123GH6PM:TM4C123GH6PM 上的串行事件处理

Guru**** 2451970 points
Other Parts Discussed in Thread: EK-TM4C123GXL

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1493978/tm4c123gh6pm-serial-event-handling-on-the-tm4c123gh6pm

器件型号:TM4C123GH6PM
Thread 中讨论的其他器件:EK-TM4C123GXL

工具/软件:

您好:

我按如下方式初始化串行端口:

void init_serial (void){                     
   MAP_GPIOPinConfigure (GPIO_PA0_U0RX);
   MAP_GPIOPinConfigure (GPIO_PA1_U0TX);
   MAP_SysCtlPeripheralEnable (SYSCTL_PERIPH_UART0);
   MAP_UARTClockSourceSet (UART0_BASE、UART_CLOCK_PIOSC);  // UART_CLOCK_PIOSC 或 UART_CLOCK_SYSTEM
   MAP_GPIOPinTypeUART (GPIO_PORTA_BASE、GPIO_PIN_0 | GPIO_PIN_1);
   UARTStdioConfig (0230230400,16000000);
}

我想处理来自 GPS 的 NMEA 数据。 是否有一个关于在数据传入时进行串行处理的示例? 等效于:

while (Series.Available()){

C=Serial.read();

//用 c 做一些事情

}

此致、

c.

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 CAN、

     下面是一个从 UART 读取并在同一个 UART 上回显它的代码片段。

        //
        // Enter a loop to read characters from the UART, and write them back
        // (echo).  When a line end is received, the loop terminates.
        //
        do
        {
            //
            // Read a character using the blocking read function.  This function
            // will not return until a character is available.
            //
            cThisChar = UARTCharGet(UART0_BASE);
    
            //
            // Write the same character using the blocking write function.  This
            // function will not return until there was space in the FIFO and
            // the character is written.
            //
            UARTCharPut(UART0_BASE, cThisChar);
        }

    您可以在以下位置找到 UART 示例:

    C:\ti\TivaWare_C_Series-2.2.0.295\examples\peripherals\uart  

    C:\ti\TivaWare_C_Series-2.2.0.295\examples\boards\ek-tm4c123gxl\uart_echo

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Charles:

    我当时使用的是 USB-CDC 以及 ControlHandler、TxHandler 和 RxHandler。 是否可以这样使用常规 UART、我实际上只需要 Rx 处理程序、因此我猜可以修改 uart_echo 处的示例以满足我的需求。

    另一件我很好奇的事情是如何使用圆环之后  

    cThisChar = UARTCharGet (UART0_BASE);

    此致、

    c.

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    I 使用的是 USB-CDC 以及 ControlHandler、TxHandler 和 RxHandler。 是否有这样的方式使用常规 UART、我实际上只需要 Rx 处理程序、因此我想可以修改 uart_echo 处的示例以满足我的需求。

    您好 CAN、

     我在这里不是很关注你。 下面是 USB-CDC 的 RXHandler。 您希望以这种方式使用常规 UART 是什么意思? 传递给 RXHandler 的消息事件类型(例如 USB_EVENT_RX_AVAILABLE、USB_EVENT_DATA_RELEASED)特定于 USB CDC 类。 没有要传递给 UART ISR 的参数。 可以使用 UARTSpaceAvail ()来模拟  USB_EVENT_DATA_RELEASED 和 UARTCharGet ()来模拟 USB_EVENT_RX_AVAILABLE。   

    uint32_t
    RxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue,
              void *pvMsgData)
    {
        uint32_t ui32Count;
    
        //
        // Which event are we being sent?
        //
        switch(ui32Event)
        {
            //
            // A new packet has been received.
            //
            case USB_EVENT_RX_AVAILABLE:
            {
                //
                // Feed some characters into the UART TX FIFO and enable the
                // interrupt so we are told when there is more space.
                //
                USBUARTPrimeTransmit(USB_UART_BASE);
                MAP_UARTIntEnable(USB_UART_BASE, UART_INT_TX);
                break;
            }
    
            //
            // We are being asked how much unprocessed data we have still to
            // process. We return 0 if the UART is currently idle or 1 if it is
            // in the process of transmitting something. The actual number of
            // bytes in the UART FIFO is not important here, merely whether or
            // not everything previously sent to us has been transmitted.
            //
            case USB_EVENT_DATA_REMAINING:
            {
                //
                // Get the number of bytes in the buffer and add 1 if some data
                // still has to clear the transmitter.
                //
                ui32Count = MAP_UARTBusy(USB_UART_BASE) ? 1 : 0;
                return(ui32Count);
            }
    
            //
            // We are being asked to provide a buffer into which the next packet
            // can be read. We do not support this mode of receiving data so let
            // the driver know by returning 0. The CDC driver should not be sending
            // this message but this is included just for illustration and
            // completeness.
            //
            case USB_EVENT_REQUEST_BUFFER:
            {
                return(0);
            }
    
            //
            // We don't expect to receive any other events.  Ignore any that show
            // up in a release build or hang in a debug build.
            //
            default:
    #ifdef DEBUG
                while(1);
    #else
                break;
    #endif
        }
    
        return(0);
    }

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Charles、

    我的意思是:USB-CDC 示例以及许多其他数据结构使用中断处理程序、因此在接收到数据包时调用 RxHandler。 非 CDC UART 示例通过在循环中轮询来检测传入的数据来工作。 我错了吗? 还是在代码 USB-CDC 示例后面使用轮询还是可以?

    此致、

    CAN

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 CAN、

     对于 UART、还可以使用中断模式。 查看 C:\ti\TivaWare_C_Series-2.2.0.295\examples\boards\ek-tm4c123gxl\uart_echo 示例、其中使用中断接收 UART 流并处理 ISR 内的数据。 对于 USB、使用回调(例如 RxHandler)、不使用轮询。