For other users:
------
code
------
/*
Author: LeaflabsAndy
Date: 7/1/10
Revision: 1.0b
Platform: Win XP SP3
Device: Maple Rev. 3 red
IDE Rev.: 0.5.0
Maple 3 Port Serial Comm. Turnaround Test
Insert 3 330 ohm resistors (for current limit protection)
into the following headers on the Maple for each serial port.
USART2 D0-D1 (RX to TX)
USART1 D7-D8 (TX to RX)
USART3 D29-D30 Ext. HDR. (TX to RX) center 5 up either way
This Maple Communication Turnaround Port Test sends out one char then checks the receive buffer
on all three USARTS.
If everything is Ok the blue LED stays on and flashes.
On any char mismatch the program halts and the blue LED is off.
All three resistors will have to be installed. Removing any turnaround resistor will halt the program.
Standard baud rates:
•110 •300 •600 •1200 •2400 •4800 •9600
•14400 •19200 •28800 •38400 •56000
•57600 •115200
max baud on hardware uart is 225000? per okie but this test could only do 153600 max.
Special baud rates:
•128000 •153600 •230400
•256000 •460800 •921600
Program status: OK - it works.
*/
#define BLUE_LED 13
#define BAUD 153600
int toggle = 0;
static int x = 0;
static long loop1, loop2, loop3;
static byte inByte1, inByte2, inByte3;
void setup() {
Serial1.begin(BAUD);
Serial2.begin(BAUD);
Serial3.begin(BAUD);
//Serial1.flush(); <----- does not work????
//Serial2.flush(); <----- does not work????
//Serial3.flush(); <----- does not work????
/* Set up the LED to blink */
pinMode(BLUE_LED, OUTPUT);
}
void abort(void){
digitalWrite (BLUE_LED,LOW);
while(1) {}
}
void serial1Test(void){
Serial1.write(x);
loop1 = 0;
START1:
if (Serial1.available()) {inByte1 = Serial1.read(); goto check_Data1;}
loop1++;
if (loop1 > 5000) {abort();}
goto START1;
check_Data1:
if (inByte1 != x) {abort(); }
}
void serial2Test(void){
Serial2.write(x);
loop2 = 0;
START2:
if (Serial2.available()) {inByte2 = Serial2.read(); goto check_Data2;}
loop2++;
if (loop2 > 5000) {abort();}
goto START2;
check_Data2:
if (inByte2 != x) {abort(); }
}
void serial3Test(void){
Serial3.write(x);
loop3 = 0;
START3:
if (Serial3.available()) {inByte3 = Serial3.read(); goto check_Data3;}
loop3++;
if (loop3 > 5000) {abort();}
goto START3;
check_Data3:
if (inByte3 != x) {abort(); }
}
void loop() {
toggle ^= 1;
digitalWrite(BLUE_LED, toggle);
for(x = 0; x < 256; x++){ //seed values
serial1Test(); // Serial1 test
serial2Test(); // Serial2 test
serial3Test(); // Serial3 test
} // end of for
} //The end