Lankapage Logo Recent Top Stories
CP 11 YEARS
Go Home Home Serving the Sri Lankan community globally since 2000
go to LankaPage.com

Leading News from Sri Lanka::

* Host USB-HID communication for Texas Instruments MSP430F5529 using Embarcadero RAD Studio XE .
Wed, Dec 15, 2010, 03:34 am SL Time, ColomboPage News Desk, Sri Lanka.

For this, many examples are available on the web. But, I did not see any RAD Studio XE (Delphi and C++Builder) example to do USB communication for Ti - MSP430 family (or any other) microcontroller. In this example I am trying to show how easy to use RAD-XE to make a USB host program. The source I used is free and can modify as you wish. But you must have following items in order to try.

Evaluation Board :

First you need a microcontroller (MCU), I chose Texas Instruments MSP430F5529. In order to use, it needs a (eval-board) sample board and I picked MSP430F55xx 80-Pin FET tool and target board combination (part number MSP-FET430U80USBP). This comes with all the necessary hardware including JTAG interface, software and documents for $149.

FOR MCU programming it is easy to use and debug with Code Composer Studio (CCStudio) Integrated Development Environment (IDE) v4.x (CCS) . You do not have to pay money for this and it comes with above eval-board package. Follow the instructions, install full version of Ti-Package that comes with the CD including "slac285b" example zip files. Try the files on "HID-only example/CCS/HID-Datapipe/API_STACK" directory and see how it is working with CCS and the JTAG interface.

Next you need Embarcadero RAD Studio XE (2011) with nrComm Lib - USB component. This nrComm Lib includes some components, classes and routines useful for work with serial port devices, USB, HID, GPS, data and voice modems, barcode scanners and speech conversion and others. If you do not have that download trial version for now.

Sample Host Program from Ti:

There is an example program that comes with the CD, (MSP430 HID Demo App) , use this and see how MCU will respond to the command. Try typing "LED OFF!" and "LED ON!" and etc. You will see the result on the screen and the demo board LED changes.

In the directory "HID-only example/CCS/HID-Datapipe/API_STACK" you see "main.c" source which is running in the F5529 MCU. The format supposed to send from Host PC to this code in MCU via USB is a string of data. In USB full speed, size of the data string (array) is 64 bytes. First byte is all ways "report id" and Ti use report id as "$3f". Then receiving data string supposed to have char('0') as the send byte and the data followed by "!" (Char(20) ) string. You can change this format later, but for now do not change any. That is the format agreement in "main.c" to receive a data from Host program.

RAD-XE Sample program:

Now you can run the example program in RAD-XE. There are 4 buttons on the panel. "LED OFF", "LED ON", etc. try those and see the result. This program can be downloaded and contain complete source to modify. Also in that zip file you will find the "main_mod.c".

Now you can replace the code in main.c file, with "main_mod.c" file . This gives some nice return values. Practically it is almost "main.c" with couple of lines added.

For example if you want to send "LED ON" string to MCU and considering how "main.c" is expecting from the host, you have to send:

Report[0]    := $3f; 
Report[1]    := ord('0'); 
Report[2..7] := ORD('L')...Ord('N);  // LED ON!

then last data byte as Data[8] := ord('!');

This last byte "!" uses to tell "main.c" , the end of the string.

Using nrCom-lib in RAD-XE ::

var ToWrite : Cardinal; Report : Array of Byte; i : smallint; s : string; s:='0LED ON!'; ToWrite := nrHid1.HidDevice.OutputReportLength; //Get the Report length SetLength(Report, ToWrite); for i:= 0 to ToWrite - 1 do Report[i] := 0; Report[0]:=$3f; for i := 1 to length(s) do Report[i] :=ord(s[i]); nrHID1.WriteReport(Report, ToWrite);

Things for you to try:

As the report ID, Ti, in this example use $3f, you can try to change to any and change the host program to work with it. Secondly, sending the "!" char as the end of the string. I like to have the length as the second byte and then do the data at the end.

Data[0] := $3f; 
Data[1] := ord('0');   
Data[2] := $06;                    // [ Length('LED ON') = 6 ].
Data [3..8]:=ORD('L')....Ord('N'); // with out '!'.

So change both "main.c" for MCU and and the RAD-XE example "UsbHid430.pas" to work.

If you need any help please send an e-mail to Ti , RAD_XE or nrComm-lib. Do not send to me, I have no idea how those are working.

Good luck.
Gamini Gunaratna

Please send an e-mail to me ( msp430(at)lankapage.com ) and I will send *.zip file to you



ColomboPage - Recent 10 Stories

Warning: require(/home/vesamuni/public_html/DB/latest_10.php) [function.require]: failed to open stream: No such file or directory in /home/content/58/7376258/html/archive_10B/Dec15_1292364245CH.php on line 252

Fatal error: require() [function.require]: Failed opening required '/home/vesamuni/public_html/DB/latest_10.php' (include_path='.:/usr/local/php5/lib/php') in /home/content/58/7376258/html/archive_10B/Dec15_1292364245CH.php on line 252