This program is a initial connection test of mBed and Texas Instruments EZ430 Chronos Watch. The Chronos RF Access Point radio dongle is connected to mBed usb port , and it's configured as a usb host. The program uses the USBHostSerial library.
Chronos Test
- This program is a successful connection test between mBed and the watch EZ430 Chronos Development Tool from texas Instruments.
- The RF Access Point usb dongle, that comes with the watch, emulates a usb serial port when connected to a PC. I connected it to the mBed usb port , configured as host ( two 10 K ohms resistors from D+,D- to gnd , I know the recommended value is 15k ) and based the development on the USBHostSerial HelloWorld example program.
- The mBed leds are activated based on the button received from the watch : led2 goes on when the "*" button is pressed , led3 when the "#" button is pressed and led4 when the "up"button is pressed .
- In order to function , you have to select the "ppt control" mode on the chronos watch and after that , start the transmission pressing the "down" button on the watch.
main.cpp@0:54aa44094993, 2014-07-30 (annotated)
- Committer:
- jeroavf
- Date:
- Wed Jul 30 02:07:46 2014 +0000
- Revision:
- 0:54aa44094993
- Child:
- 1:461ba80810ce
Initial tests with TI Chronos Watch sending messages to mBed with radio dongle connected to usb port of mbed configured as host
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jeroavf | 0:54aa44094993 | 1 | #include "mbed.h" |
jeroavf | 0:54aa44094993 | 2 | #include "USBHostSerial.h" |
jeroavf | 0:54aa44094993 | 3 | |
jeroavf | 0:54aa44094993 | 4 | DigitalOut led(LED1); |
jeroavf | 0:54aa44094993 | 5 | DigitalOut led2(LED2); |
jeroavf | 0:54aa44094993 | 6 | DigitalOut led3(LED3); |
jeroavf | 0:54aa44094993 | 7 | DigitalOut led4(LED4); |
jeroavf | 0:54aa44094993 | 8 | |
jeroavf | 0:54aa44094993 | 9 | Serial pc(USBTX, USBRX); |
jeroavf | 0:54aa44094993 | 10 | int chronos_answer[10] ; |
jeroavf | 0:54aa44094993 | 11 | |
jeroavf | 0:54aa44094993 | 12 | void serial_task(void const*) { |
jeroavf | 0:54aa44094993 | 13 | USBHostSerial serial; |
jeroavf | 0:54aa44094993 | 14 | |
jeroavf | 0:54aa44094993 | 15 | |
jeroavf | 0:54aa44094993 | 16 | while(!serial.connect()) |
jeroavf | 0:54aa44094993 | 17 | Thread::wait(500); |
jeroavf | 0:54aa44094993 | 18 | |
jeroavf | 0:54aa44094993 | 19 | serial.baud(115200) ; |
jeroavf | 0:54aa44094993 | 20 | |
jeroavf | 0:54aa44094993 | 21 | pc.printf("chronos init ...\n") ; |
jeroavf | 0:54aa44094993 | 22 | |
jeroavf | 0:54aa44094993 | 23 | serial.putc(0xff) ; |
jeroavf | 0:54aa44094993 | 24 | serial.putc(0x07) ; |
jeroavf | 0:54aa44094993 | 25 | serial.putc(0x03) ; |
jeroavf | 0:54aa44094993 | 26 | pc.printf("chronos init completed ...\n") ; |
jeroavf | 0:54aa44094993 | 27 | |
jeroavf | 0:54aa44094993 | 28 | |
jeroavf | 0:54aa44094993 | 29 | while(1) { |
jeroavf | 0:54aa44094993 | 30 | while (1) { |
jeroavf | 0:54aa44094993 | 31 | |
jeroavf | 0:54aa44094993 | 32 | // send read request to chronos |
jeroavf | 0:54aa44094993 | 33 | serial.putc(0xFF); |
jeroavf | 0:54aa44094993 | 34 | serial.putc(0x08); |
jeroavf | 0:54aa44094993 | 35 | serial.putc(0x07); |
jeroavf | 0:54aa44094993 | 36 | serial.putc(0x00); |
jeroavf | 0:54aa44094993 | 37 | serial.putc(0x00); |
jeroavf | 0:54aa44094993 | 38 | serial.putc(0x00); |
jeroavf | 0:54aa44094993 | 39 | serial.putc(0x00); |
jeroavf | 0:54aa44094993 | 40 | Thread::wait(15); |
jeroavf | 0:54aa44094993 | 41 | |
jeroavf | 0:54aa44094993 | 42 | |
jeroavf | 0:54aa44094993 | 43 | // put received characters on an array |
jeroavf | 0:54aa44094993 | 44 | int i = 0 ; |
jeroavf | 0:54aa44094993 | 45 | while (serial.available()) { |
jeroavf | 0:54aa44094993 | 46 | int c_in = serial.getc() ; |
jeroavf | 0:54aa44094993 | 47 | chronos_answer[i++] = c_in ; |
jeroavf | 0:54aa44094993 | 48 | } |
jeroavf | 0:54aa44094993 | 49 | int button = chronos_answer[3] ; |
jeroavf | 0:54aa44094993 | 50 | if(button != 255) { |
jeroavf | 0:54aa44094993 | 51 | printf("Button received : %d\n", button ) ; |
jeroavf | 0:54aa44094993 | 52 | switch(button) { |
jeroavf | 0:54aa44094993 | 53 | case 18 : // * button |
jeroavf | 0:54aa44094993 | 54 | led2 = 1 ; |
jeroavf | 0:54aa44094993 | 55 | led3 = 0 ; |
jeroavf | 0:54aa44094993 | 56 | led4 = 0 ; |
jeroavf | 0:54aa44094993 | 57 | break ; |
jeroavf | 0:54aa44094993 | 58 | case 50 : // up button |
jeroavf | 0:54aa44094993 | 59 | led2 = 0 ; |
jeroavf | 0:54aa44094993 | 60 | led3 = 1 ; |
jeroavf | 0:54aa44094993 | 61 | led4 = 0 ; |
jeroavf | 0:54aa44094993 | 62 | break ; |
jeroavf | 0:54aa44094993 | 63 | case 34 : // # button |
jeroavf | 0:54aa44094993 | 64 | led2 = 0 ; |
jeroavf | 0:54aa44094993 | 65 | led3 = 0 ; |
jeroavf | 0:54aa44094993 | 66 | led4 = 1 ; |
jeroavf | 0:54aa44094993 | 67 | break ; |
jeroavf | 0:54aa44094993 | 68 | |
jeroavf | 0:54aa44094993 | 69 | } |
jeroavf | 0:54aa44094993 | 70 | } |
jeroavf | 0:54aa44094993 | 71 | |
jeroavf | 0:54aa44094993 | 72 | |
jeroavf | 0:54aa44094993 | 73 | Thread::wait(50); |
jeroavf | 0:54aa44094993 | 74 | } |
jeroavf | 0:54aa44094993 | 75 | } |
jeroavf | 0:54aa44094993 | 76 | } |
jeroavf | 0:54aa44094993 | 77 | |
jeroavf | 0:54aa44094993 | 78 | int main() { |
jeroavf | 0:54aa44094993 | 79 | Thread serialTask(serial_task, NULL, osPriorityNormal, 256 * 4); |
jeroavf | 0:54aa44094993 | 80 | while(1) { |
jeroavf | 0:54aa44094993 | 81 | led=!led; |
jeroavf | 0:54aa44094993 | 82 | Thread::wait(500); |
jeroavf | 0:54aa44094993 | 83 | } |
jeroavf | 0:54aa44094993 | 84 | } |