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: Can I send the sensor data over USB Device Virtual COM Port without using UART?

Part Number: TM4C123GH6PZ

I was working on a project where we are designing the application in which the data will be sent over USB Device Virtual Com Port at the same time we are using UART0 lines to send data over RS232. For example, after receiving the temperature data it will forward to the host via USB Device Virtual Com Port also will be sent over RS232 using UART0 lines. So initially I tried the usb_dev_serial.c example.

Now in my project the temperature data I'm receiving from the sensor I wanted send over the USB to the host. Before that, I have few doughts regarding  usb_dev_serial.c.
1)Can we send the data to the host via USB without using UART? I'm asking this question because I tried to remove the UART initialization from the code(usb_dev_serial.c) but in that case, USB was not detected by the PC.

2)What will be the best way to just send the sensor data to the HOST via USB?

I'm working on USB first ever so any help will be really appreciated!. Thank you.

Regards

Omkar

  • Hello Omkar,

    1)Can we send the data to the host via USB without using UART? I'm asking this question because I tried to remove the UART initialization from the code(usb_dev_serial.c) but in that case, USB was not detected by the PC.

    Do you have both USB cables hooked up?

    The way the example works is one port connects to the ICDI over UART, and the other connects over USB like normal. Then you can ping pong data back and forth with two terminal windows open on your PC.

    You definitely don't need UART setup to send with USB. If you had both cables hooked up perhaps you removed something related to the USB interface.

    2)What will be the best way to just send the sensor data to the HOST via USB?

    usb_dev_serial is where I would start, just need to get it cleaned up a bit for your needs. Review what you have after trimming out the UART stuff vs what was in the original example and if you can't see anything that you accidentally deleted, I can take a look tomorrow if you post your code.

  • Thank you so much for the reply.

    Do you have both USB cables hooked up?

    No, we are using only one USB cable that too also only will be used for the data transmission to the host.

    The way the example works is one port connects to the ICDI over UART, and the other connects over USB like normal. Then you can ping pong data back and forth with two terminal windows open on your PC.

    This I observed while working on the usb_dev_serial.c

    just need to get it cleaned up a bit for your needs.

    So basically we are only using one USB cable. I remove some part of the code which follows.

    //*****************************************************************************
    //
    // 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)
        {
    
        }

    I did make a change here in the main (of the usb_dev_serial.c) only.

    One thing I observed that if I flash the above code on our custom board pc is detecting USB port here I'm attaching a picture.

    But now if i flash the following code (i removed UART0 initialization here because i had already initialized the UART0 before calling USB init function in the main application)

    //*****************************************************************************
    //
    // 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);
    		
    }

    After flashing the above code I'm getting following error

    Can you please help me solve this issue?

    Regards

    Omkar

  • This issue is solved. Basically, I integrated my application into the usb_dev_serial.c so now I'm able to send the data to the host. Thank you, for the support.

  • Hello Omkar,

    Oh that's great to hear! Sorry I hadn't gotten back to you yet. I'm glad to hear you were able to get the issue resolved and your program is working as expected.

    Best Regards,

    Ralph