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.

sending command and reading data from tiva using python pyusb

Other Parts Discussed in Thread: EK-TM4C1294XL, EK-TM4C123GXL

I need to send command to tiva using pyusb which will be stored in the memory of tiva

And also I need to receive data from tiva and plot it in python.

I don't have idea about how to use usb in tiva, how to receive and send data

Can I get some reference so that i can start by sending and receiving few bytes to tiva  

  • Hello Sheetal,

    In our TivaWare SDK we provide USB examples. You can start with either usb_dev_cdcserial for EK-TM4C1294XL or usb_dev_serial for EK-TM4C123GXL.

    Download TivaWare from here: http://www.ti.com/tool/SW-TM4C

    The examples folders for LaunchPads are located at [Install Path]\TivaWare_C_Series-2.2.0.295\examples\boards

  • I tried usb_dev_serial example. I am not able to understand exactly what is happening.

    What is meant by redirect UART0 via USB. Why are we using uart. I am very confused. Even the readme.txt is not that clear.

    Please someone can tell what is exactly happening in the code.

  • Hello Sheetal,

    The UART0 feeds data to the MCU from a PC terminal port like Putty or Teraterm into the TM4C devices through the ICDI debugger.

    The TM4C then uses that data to send over USB to the USB Host.

    The USB host can be PC itself or another USB host that is configured for CDC mode.

    The UART piece is for demonstration and not indicative of an end application.

    It is a starting point to allow you to see that the USB functionality works.

    You would write your own application to send USB data instead which you then receive in Python to graph.

  • Thanks a lot. Some things are clear.

    So using python if I use the command dev.write() do I need to transfer it through uart or I can directly store the value in usb buffer.

    Even while sending data from tiva to pc via usb can I directly send data from usb buffer.

    Sorry for the inconvenience. I have less knowledge on the tiva side so I am confused with the code.

  • Hello Sheetal,

    I am not familiar with Python but if you have the USB Device port on the LaunchPad connected to your PC so you have a USB Serial Device COM port on your PC, then you can connect to that and send data straight into USB that way.

    For the usb_dev_serial for the EK-TM4C123GXL, you would see the following ports:

    And then sending data, to send into the USB interface so it goes in the USB Buffers and can be read from that inside the TM4C (what you are looking for) would be inputting data into COM15. The usb_dev_serial application then takes that data and sends it over UART to COM37 to echo it back out. The other port, COM37, can also have data input and that goes in through UART and outputs to the USB.

    Here is an example of that, where on the USB side I typed "USB to UART" and on the UART side I typed "UART to USB", and so you can see how the receiving end has received the message:

  • Sheetal Patil said:

    I need to send command to tiva using pyusb which will be stored in the memory of tiva

    And also I need to receive data from tiva and plot it in python.

    I don't have idea about how to use usb in tiva, how to receive and send data

    Can I get some reference so that i can start by sending and receiving few bytes to tiva  

    Before you can even think about transferring data from the microcontroller and using Python, you have to decide what USB Device Class your microntroller design will use. Ralph reasonably suggests using the Commications Device Class (CDC), because your computer will see the micro design as a COM port and you don't need any specialist drivers or fancy pyusb stuff at all.

    Of course if you do that, you have to work out a communications protocol. What message or command will you send to the micro to ask for data? How will you package that data to be sent back to the computer?

    There are many other ways to do this. You could use a vendor-defined USB device that looks like the usbd_bulk example provided by TI. This requires a host driver and some host programming skills. You could make your micro conform to the HID class, which does not need a driver. Just design "reports" that make sense for your data.

    If I was a newbie and didn't have other compelling requirements, I'd go with the CDC option.