Electronic – MSP430 USB Module and Baud Rate Detection

baudratemsp430usb

I am working on a project which uses the USB module integrated into the MSP430F5529, specifically using the MSP-EXP430F5529LP development board from TI. I am using the USB API provided in MSPWare.

The host talks to my device over MODBUS, and I am saving the current baud rate in NVM. Generally, to change the baud rate, I write a value to a MODBUS register. The device reads this value and configures its UARTs accordingly, so that it can act as a bridge between USB and a TTL device.

The problem is that not all MODBUS implementations will use this MODBUS register as a baud rate config, so writing to that address may not be intended to change the baud rate. Therefore, this method has to go.

I was hoping I might be able to detect the baud rate being used to communicate over the USB signal. The first thought was to use a timer to measure the width of the start bit, and use that to calculate the baud rate. The issue with this is that 1) I need to send an entire dummy byte over USB to my device in order to detect the baud rate, before starting normal communication. The other issue is that the way the MSP430 USB API is built, I do not seem to have access to the individual bits as they come in, but rather the message is stored in a buffer which is then provided after the message is completed. I would not be able to time the start bit in this event.

I don't believe there is a way to just "know" what the baud rate of the host is without sending data, since that information (to my knowledge) is not communicated over the bus. Please correct me if I'm wrong.

How might one go about determining the baud rate of a USB connection, preferably without sending a dummy byte first? I'm not entirely convinced this is even possible, it seems to be asking for the impossible, but I figured someone here would be able to give me a definite answer.

I have been through the TI documents describing the USB module, the API, and their application and have not yet found a solution to this problem.

Best Answer

The baud rate of the USB connection has no relationship with the baud rate of the UART side of a USB to UART converter. Regardless of the baud rate requested by the application, the data that is sent by the application will be packetized and sent over the USB connection at whatever rate the USB link is configured for (according to speed capabilities of the host and device). It is up to the device to set the baud rate of its UART interface to that requested by the application. The requested baud rate should come in as one of the configuration SET messages sent by the host.

This appnote is for a different platform, but has some information on how this is done: https://www.xmos.com/developer/download/private/AN00124:-USB-CDC-Class-as-Virtual-Serial-Port(2.0.2rc1).pdf

You will have to look in the documentation for your API to see how (or if) this configuration data is exposed. If it is not exposed, you may need to dig through the libraries to find a place where you can intercept that SET message and act on it appropriately.