Communicating with the Critter Board from a computer is a good thing to be able to do. Whether you are debugging your programs, collecting sensor data, or controlling actuators, serial provides an easy way to do this.
Downloads:
The good news: if you have setup all the software to upload programs to the Critter Board, you already have a working serial connection. And all that is needed is some software on the Critter Board. This functionality is included with all the exampes in the file system.c. Download the Simple Serial example above and try it out.
The example sends some characters to the computer, and then echos back everything it recieves.
int main (void) {
// Initialize the MCU, also sets up the serial connection to 115200
Initialize();
led_board(0);
delay_ms(100); // flash LEDs
led_board(1);
delay_ms(100);
led_board(0);
delay_ms(100);
led_board(1);
put_char('R');
put_char('e');
put_char('a');
put_char('d');
put_char('y');
put_char('\n');
for(;;){
put_char(get_char()); // echo character
}
} // main()
To try it out, build the program and upload it to the Critter Board. Then open a terminal (if your using Mac OSX or Linux, if you use windows use hyperterminal) and run the command:
'screen /dev/tty.usbserial[TheRestOfThePortName] 115200'
Reset the board and you should see 'Ready' printed to the screen. Try typing some characters and they will echo back.
printf() is a much more convinient way to send information. The printf() function in the standard C library is very large, so in the example we use a slightly smaller 'embedded' printf function. The example is pretty self-explanatory, it reads ADC 1.5 and sends the value back to the computer. If nothing is connected to this pin, it will be fluctuating around.
The printf() function does require some code from the C library for ARM, which is part of the GCC toolchain, but it's location needs to be specified in the makefile. Check out this line of the makefile of the printf example:
LFLAGS = -Map main.map -T LPC2138_flash.cmd -L /home/owen/ARM/gnuarm-3.4.3/arm-elf/lib \
-L /home/owen/ARM/gnuarm-3.4.3/lib/gcc/arm-elf/3.4.3
You will have to change the two paths after both -L flags to the location of your toolchain.