Created Fri, 09 Dec 2011 07:12:26 +0000 by Jacob Christ
Fri, 09 Dec 2011 07:12:26 +0000
One of the boards I'm working on is Frankenstein mash-up of a Uno32 with a PIC32MX440 chip that has USB built in. This allows me to use USB for Serial (with much love from Mark Sproul for helping me to understand how to customize MPIDE for use with my board). The PIC32MX440 has two USART's as well as USB and I have a GPS receiver hooked up to one of the USARTS. To verify the GPS is working I want to turn the PIC32 into a USB to Serial converter to talk to the GPS chip. So I made the following simple project. I thought it might help others so I'm passing it along here:
/*
usb_to_serial
Turns your PIC32 into a really expensive usb to serial converter.
Copyright 2011 by Jacob Christ
This code is licensed under apache 2.0.
*/
void setup()
{
Serial.begin(115200);
Serial0.begin(115200);
pinMode(43, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(13,HIGH);
digitalWrite(43,HIGH);
delay(100);
digitalWrite(13,LOW);
digitalWrite(43,LOW);
delay(100);
digitalWrite(13,HIGH);
digitalWrite(43,HIGH);
delay(100);
digitalWrite(13,LOW);
digitalWrite(43,LOW);
delay(100);
}
void loop()
{
if( Serial.available() > 0) {
digitalWrite(13,LOW);
digitalWrite(43,HIGH);
ch = Serial.read();
Serial0.print(ch);
}
if( Serial0.available() > 0) {
digitalWrite(13,HIGH);
digitalWrite(43,LOW);
ch = Serial0.read();
Serial.print(ch);
}
}
Like the Uno32, I have pins 13 and 43 connected to LED's. If your board has LED's in different places, feel free to change the pin numbers.
EDIT: Actually this is almost exactly whats posted on the Arduino site for Serial lib for multiple serial ports.
Jacob
Fri, 18 May 2012 09:43:04 +0000
I like your script vary much and that is very useful and helpful for me. Thanks for share this valuable post.