Skip to content

Instantly share code, notes, and snippets.

@Bouni
Last active August 29, 2015 14:06
Show Gist options
  • Save Bouni/7087db3915bc530b41c2 to your computer and use it in GitHub Desktop.
Save Bouni/7087db3915bc530b41c2 to your computer and use it in GitHub Desktop.
Arduino IDE 1.5.7 serial test sketch
int modes[30] = {
SERIAL_5N1,
SERIAL_5E1,
SERIAL_5O1,
SERIAL_5N2,
SERIAL_5E2,
SERIAL_5O2,
SERIAL_6N1,
SERIAL_6E1,
SERIAL_6O1,
SERIAL_6N2,
SERIAL_6E2,
SERIAL_6O2,
SERIAL_7N1,
SERIAL_7E1,
SERIAL_7O1,
SERIAL_7N2,
SERIAL_7E2,
SERIAL_7O2,
SERIAL_8N1,
SERIAL_8E1,
SERIAL_8O1,
SERIAL_8N2,
SERIAL_8E2,
SERIAL_8O2,
SERIAL_9N1,
SERIAL_9E1,
SERIAL_9O1,
SERIAL_9N2,
SERIAL_9E2,
SERIAL_9O2
};
int limits[5] = {
0x1F, // 5 bit
0x3F, // 6 bit
0x7F, // 7 bit
0xFF, // 8 bit
0x1FF, // 9 bit
};
void setup() {
// Serial connectio over UART for test output
Serial.begin(115200);
delay(5000);
}
int counter = 0;
void test_usart(int mode, int limit) {
// set up the USARTS
Serial1.begin(9600, modes[mode]);
Serial2.begin(9600, modes[mode]);
Serial3.begin(9600, modes[mode]);
for(int i=0; i <= limits[limit]; i++) {
Serial1.write(i);
Serial2.write(i);
Serial3.write(i);
counter++;
while(!Serial1.available());
while(!Serial2.available());
while(!Serial3.available());
int result1 = Serial1.read();
int result2 = Serial2.read();
int result3 = Serial3.read();
if(result1 == i) {
Serial.print("Serial1 sent ");
Serial.print(i, HEX);
Serial.print(", received ");
Serial.print(result1, HEX);
Serial.println(", OK! ");
} else {
Serial.print("Serial1 sent ");
Serial.print(i, HEX);
Serial.print(", received ");
Serial.print(result1, HEX);
Serial.println(", >>>> FAIL <<<< ");
}
if(result2 == i) {
Serial.print("Serial2 sent ");
Serial.print(i, HEX);
Serial.print(", received ");
Serial.print(result2, HEX);
Serial.println(", OK! ");
} else {
Serial.print("Serial2 sent ");
Serial.print(i, HEX);
Serial.print(", received ");
Serial.print(result2, HEX);
Serial.println(", >>>> FAIL <<<< ");
}
if(result3 == i) {
Serial.print("Serial3 sent ");
Serial.print(i, HEX);
Serial.print(", received ");
Serial.print(result3, HEX);
Serial.println(", OK! ");
} else {
Serial.print("Serial3 sent ");
Serial.print(i, HEX);
Serial.print(", received ");
Serial.print(result3, HEX);
Serial.println(", >>>> FAIL <<<< ");
}
Serial.print(counter, DEC);
Serial.println(" bytes sent");
}
}
void loop() {
// put your main code here, to run repeatedly:
// for each frame width
for(int i=0; i<4; i++) {
// for each mode in this frame width
for(int j=0; j<6; j++) {
Serial.print("Test mode ");
Serial.println(i*6 + j, DEC);
test_usart(i*6 +j, i);
delay(500);
}
}
delay(1000);
}
@Bouni
Copy link
Author

Bouni commented Sep 7, 2014

This is the sketch i used to test the Serial ports of the Arduino Due.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment