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.

[参考译文] TM4C123GH6PZ:我是否可以在不使用 UART 的情况下通过 USB 器件虚拟 COM 端口发送传感器数据?

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

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1011646/tm4c123gh6pz-can-i-send-the-sensor-data-over-usb-device-virtual-com-port-without-using-uart

器件型号:TM4C123GH6PZ

我正在设计一个项目、在该项目中、我们将设计一个应用程序、在使用 UART0线路通过 RS232发送数据的同时、通过 USB 器件虚拟 COM 端口发送数据。 例如、在接收到温度数据后、它将通过 USB 器件虚拟 COM 端口转发到主机、也将使用 UART0线路通过 RS232发送。 因此、我最初尝试了 USB_dev_serial.c 示例。

现在、在我的项目中、我从我想要通过 USB 发送到主机的传感器接收到的温度数据。 在此之前、我有几个关于 USB_dev_serial.c 的数字
1)我们是否可以在不使用 UART 的情况下通过 USB 将数据发送到主机? 我之所以提出这个问题、是因为我尝试从代码(USB_dev_serial.c)中删除 UART 初始化、但在这种情况下、PC 未检测到 USB。

2)通过 USB 将传感器数据发送到主机的最佳方法是什么?

我是第一次使用 USB、因此任何帮助都将不胜感激! 谢谢你。

此致

Omkar

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

    您好、Omkar、

    [引用 userid="457192" URL"~/support/microcontrollers/other-microcontrollers-group/other/f/other-microcontrollers-forum/1011646/tm4c123gh6pz-can-i-send-the-sensor-data-over-usb-device-virtual-com-port-without-using-uart ]1)我们是否可以通过 USB 将数据发送到主机而不使用 UART? 我之所以提出这个问题、是因为我尝试从代码(USB_dev_serial.c)中删除 UART 初始化、但在这种情况下、PC 未检测到 USB。

    您是否连接了两根 USB 电缆?

    该示例的工作方式是、一个端口通过 UART 连接到 ICDI、另一个端口通过 USB 正常连接。  然后、您可以在 PC 上打开两个终端窗口、来回 ping 数据。

    您肯定不需要 UART 设置即可使用 USB 进行发送。 如果您连接了两根电缆、也许您删除了与 USB 接口相关的内容。

    [引用 userid="457192" URL"~/support/microcontrollers/other-microcontrollers-group/other/f/other-microcontrollers-forum/1011646/tm4c123gh6pz-can-i-send-the-sensor-data-over-usb-device-virtual-com-port-without-using-uart ]2)通过 USB 将传感器数据发送到主机的最佳方法是什么?

    USB_DEV_serial 是我开始的地方、只需根据您的需求清除一点点。 查看修整 UART 内容后的内容与原始示例中的内容、如果看不到意外删除的内容、明天我可以看一下、如果您发布代码。

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

    非常感谢您的回复。

    [引用 userid="189615" URL"~/support/microcontrollers/other-microcontrollers-group/other/f/other-microcontrollers-forum/1011646/tm4c123gh6pz-can-i-send-the-sensor-data-over-usb-device-virtual-com-port-without-using-uart/3738349 #3738349"]是否已连接两根 USB 电缆?

    不可以、我们只使用一根 USB 电缆、该电缆也只用于向主机传输数据。

    [引用 userid="189615" URL"~/support/microcontrollers/other-microcontrollers-group/other/f/other-microcontrollers-forum/1011646/tm4c123gh6pz-can-i-send-the-sensor-data-over-usb-device-virtual-com-port-without-using-uart/3738349 #3738349"]示例的工作方式是一个端口通过 UART 连接到 ICDI、另一个端口通过 USB 正常连接。  然后、您可以使用 PC 上打开的两个终端窗口来回 ping 数据。

    我在使用 USB_dev_serial.c 时观察到这一点

    [引用 userid="189615" URL"~/support/microcontrollers/other-microcontrollers-group/other/f/other-microcontrollers-forum/1011646/tm4c123gh6pz-can-i-send-the-sensor-data-over-usb-device-virtual-com-port-without-using-uart/3738349 #3738349"]只需根据您的需求清除一点即可。

    因此、基本而言、我们仅使用一根 USB 电缆。 我删除了下面的部分代码。

    //*****************************************************************************
    //
    // This is the main application entry function.
    //
    //*****************************************************************************
    int
    main(void)
    {
        uint32_t ui32TxCount;
        uint32_t ui32RxCount;
    		
        //
        // Enable lazy stacking for interrupt handlers.  This allows floating-point
        // instructions to be used within interrupt handlers, but at the expense of
        // extra stack usage.
        //
        FPULazyStackingEnable();
    
        //
        // Set the clocking to run from the PLL at 50MHz
        //
        SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_12MHZ | SYSCTL_OSC_MAIN);
    		//SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_12MHZ | SYSCTL_OSC_MAIN
    	
    
    		system_clock_check = SysCtlClockGet();
        //
        // Configure the required pins for USB operation.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
        GPIOPinTypeUSBAnalog(GPIO_PORTJ_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
    
        g_bUSBConfigured = false;
    
        //
        // Enable the UART that we will be redirecting.
        //
        SysCtlPeripheralEnable(USB_UART_PERIPH);
    
        //
        // Enable and configure the UART RX and TX pins
        //
        SysCtlPeripheralEnable(TX_GPIO_PERIPH);
        SysCtlPeripheralEnable(RX_GPIO_PERIPH);
        GPIOPinTypeUART(TX_GPIO_BASE, TX_GPIO_PIN);
        GPIOPinTypeUART(RX_GPIO_BASE, RX_GPIO_PIN);
    
        UARTFIFOLevelSet(USB_UART_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8);
    
        USBBufferInit(&g_sTxBuffer);
        USBBufferInit(&g_sRxBuffer);
    
        //
        // Set the USB stack mode to Device mode with VBUS monitoring.
        //
        USBStackModeSet(0, eUSBModeForceDevice, 0);
    
        //
        // Pass our device information to the USB library and place the device
        // on the bus.
        //
        USBDCDCInit(0, &g_sCDCDevice);
    		
        //
        // Main application loop.
        //
        while(1)
        {
    
        }

    我只在主函数(USB_DEV_serial.c)中进行了更改。

    我观察到、如果我在我们的定制板 PC 上刷写上述代码、就会检测到这里的 USB 端口、我将附加一张图片。

    但是现在、如果我刷写以下代码(我删除了这里的 UART0初始化、因为在主应用程序中调用 USB init 函数之前、我已经初始化了 UART0)

    //*****************************************************************************
    //
    // This is the main application entry function.
    //
    //*****************************************************************************
    int
    main(void)
    {
        uint32_t ui32TxCount;
        uint32_t ui32RxCount;
    		
        //
        // Enable lazy stacking for interrupt handlers.  This allows floating-point
        // instructions to be used within interrupt handlers, but at the expense of
        // extra stack usage.
        //
        FPULazyStackingEnable();
    
        //
        // Set the clocking to run from the PLL at 50MHz
        //
        SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_12MHZ | SYSCTL_OSC_MAIN);
    		//SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_12MHZ | SYSCTL_OSC_MAIN
    	
    
    		system_clock_check = SysCtlClockGet();
        //
        // Configure the required pins for USB operation.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
        GPIOPinTypeUSBAnalog(GPIO_PORTJ_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
        g_bUSBConfigured = false;
    
        UARTFIFOLevelSet(USB_UART_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8);
    
        USBBufferInit(&g_sTxBuffer);
        USBBufferInit(&g_sRxBuffer);
    
        //
        // Set the USB stack mode to Device mode with VBUS monitoring.
        //
        USBStackModeSet(0, eUSBModeForceDevice, 0);
    
        //
        // Pass our device information to the USB library and place the device
        // on the bus.
        //
        USBDCDCInit(0, &g_sCDCDevice);
    		
    }

    刷写上述代码后、我收到以下错误

    您能帮我解决这个问题吗?

    此致

    Omkar

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

    此问题已得到解决。 基本上、我将我的应用程序集成到了 USB_dev_serial.c 中、因此现在我能够将数据发送到主机。 感谢 的支持。

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

    您好、Omkar、

    哦、听得非常好! 很抱歉我还没有回来。 我很高兴听到您能够解决问题、并且您的计划正在按预期工作。

    此致、

    Ralph