KurtE
Senior Member+
Serial6 update: There is probably still work to be done, but I do believe enough of it is working to go ahead and pull it in and allow others to play. So I issued a pull request: https://github.com/PaulStoffregen/cores/pull/158
I wrote a test sketch that I have a T3.2 using Serial1 connecting up to Serial6 of T3.5, as well as I have Pins 13 hooked up to each other, and the Master program (one that has D2 pulled low, walks through a list of baud rates and some formats. It lets the Slave know which table entry to use by how many times it blinks the led.
I then currently output the characters 'a'-'z' from host to slave, and if slave receives it it sends it back, which the host compares...
So far most everything is passing, except at baud rate 300. However I think the problem is with the T3.2, as when I look at the generated character with Logic Analyzer, it looks like it was generated at baud 1660. Will investigate.
If anyone is interested in test program:
Here is some output from masters terminal:
Update:Looks like the Pull Request was pulled in
Figured out 300 baud won't work on T3.2 at 96mhz.
Serial1 uses F_CPU to calculate 13 bit baud divisor:
Which with 96mhz and 300 baud comes out to Divisor of: 320000 or 0x4E200 Which won't fit in 13 bits
I wrote a test sketch that I have a T3.2 using Serial1 connecting up to Serial6 of T3.5, as well as I have Pins 13 hooked up to each other, and the Master program (one that has D2 pulled low, walks through a list of baud rates and some formats. It lets the Slave know which table entry to use by how many times it blinks the led.
I then currently output the characters 'a'-'z' from host to slave, and if slave receives it it sends it back, which the host compares...
So far most everything is passing, except at baud rate 300. However I think the problem is with the T3.2, as when I look at the generated character with Logic Analyzer, it looks like it was generated at baud 1660. Will investigate.
If anyone is interested in test program:
Code:
// Quick and Dirty Serial Test between two Teensy processors.
#define MASTER_PIN 2
#define TRIGGER_PIN 13
#define TEST_PIN 3
#define FIRST_CHAR 'a'
#define LAST_CHAR ('z'+1)
#define Serial1 Serial1
#if defined(__MK66FX1M0__)
#define SLAVE_SERIAL Serial6
#else
#define SLAVE_SERIAL Serial3
#endif
uint32_t baudRates[] = {9600, 38400, 115200, 1000000, 2000000, 2400, 300, 38400, 38400, 38400, 38400, 38400};
uint32_t formats[] = {0, 0, 0, 0, 0, 0, 0, SERIAL_8N1_RXINV_TXINV, SERIAL_8N2, SERIAL_7E1, SERIAL_7O1};
uint8_t baudRatesIndex = 0xff;
bool we_are_master = false;
void setup() {
// put your setup code here, to run once:
uint32_t start_time = millis();
// Wait up to 2 seconds for Serial port...
while (!Serial && ((millis() - start_time) < 2000))
;
pinMode(MASTER_PIN, INPUT_PULLUP);
pinMode(TEST_PIN, OUTPUT);
we_are_master = !digitalRead(MASTER_PIN);
if (we_are_master) {
Serial.println("Master");
pinMode(TRIGGER_PIN, OUTPUT);
digitalWrite(TRIGGER_PIN, HIGH);
} else {
Serial.println("Slave");
pinMode(TRIGGER_PIN, INPUT_PULLUP);
}
delay(500);
}
void loop() {
if (we_are_master) {
DoMasterStuff();
} else {
DoSlaveStuff();
}
}
void DoMasterStuff() {
// Lets tell Slave to go to new mode Blink the number of times
if (baudRatesIndex >= (sizeof(baudRates) / sizeof(baudRates[0])))
baudRatesIndex = 0;
Serial.printf("Now Testing Baud rate: %d format: %x ", baudRates[baudRatesIndex], formats[baudRatesIndex]);
digitalWrite(TRIGGER_PIN, LOW);
for (uint8_t i = 0; i < baudRatesIndex; i++) {
delay(100);
digitalWrite(TRIGGER_PIN, HIGH);
delay(100);
digitalWrite(TRIGGER_PIN, LOW);
}
if (formats[baudRatesIndex])
Serial1.begin(baudRates[baudRatesIndex], formats[baudRatesIndex]);
else
Serial1.begin(baudRates[baudRatesIndex]);
baudRatesIndex++;
delay(500);
digitalWrite(TRIGGER_PIN, HIGH);
delay(100); // Give time to setup
// Now try to output all valid characters and see if we get a response back...
int charOut, charIn;
uint32_t start_time;
digitalWrite(TEST_PIN, HIGH);
for (charOut = FIRST_CHAR; charOut < LAST_CHAR; charOut++) {
for (uint8_t retry_count = 0; (retry_count < 5) && (charIn != charOut); retry_count++) {
Serial1.write(charOut);
// Now try to get a char back from the Slave
start_time = millis();
while (((charIn = Serial1.read()) == -1) && ((millis() - start_time) < 100)) ;
}
// See if I need to remove parity...
if (charIn != -1)
charIn &= 0x7f;
if (charIn != charOut) {
digitalWrite(TEST_PIN, LOW);
Serial.printf("FAIL: %d != %d delta time: %d\n\r", charIn, charOut, millis() - start_time);
digitalWrite(TEST_PIN, HIGH);
break;
}
}
if (charOut >= LAST_CHAR)
Serial.println("*** Succeeded ***");
Serial1.end();
digitalWrite(TEST_PIN, LOW);
delay(500);
}
void DoSlaveStuff() {
// See if master is trying to signal us...
if (!digitalRead(TRIGGER_PIN)) {
uint8_t blink_count = 0;
uint32_t pulse_width;
for (;;) {
// Master is signalling.
uint32_t start_time = millis();
while (!digitalRead(TRIGGER_PIN)) ;
pulse_width = millis() - start_time;
if (pulse_width < 250) {
blink_count++; //
// wait until it goes low again
while (digitalRead(TRIGGER_PIN)) ;
} else
break; // done
}
// SO hopefully we have the correct index to use from the master.
if (baudRatesIndex != 0xff)
SLAVE_SERIAL.end();
// lets setup the baud rate
baudRatesIndex = blink_count;
Serial.printf("Now Testing Baud rate: %d format: %x\n\r", baudRates[baudRatesIndex], formats[baudRatesIndex]);
if (formats[baudRatesIndex])
SLAVE_SERIAL.begin(baudRates[baudRatesIndex], formats[baudRatesIndex]);
else
SLAVE_SERIAL.begin(baudRates[baudRatesIndex]);
digitalWrite(TEST_PIN, !digitalRead(TEST_PIN));
}
// mainly just echo anything we receive back
int charIn = SLAVE_SERIAL.read();
if (charIn != -1) {
charIn &= 0x7f; // see if this fixes Parity stuff...
SLAVE_SERIAL.write(charIn);
Serial.write(charIn);
}
}
Here is some output from masters terminal:
Code:
Master
Now Testing Baud rate: 38400 format: 0 *** Succeeded ***
Now Testing Baud rate: 115200 format: 0 *** Succeeded ***
Now Testing Baud rate: 1000000 format: 0 *** Succeeded ***
Now Testing Baud rate: 2000000 format: 0 *** Succeeded ***
Now Testing Baud rate: 2400 format: 0 *** Succeeded ***
Now Testing Baud rate: 300 format: 0 FAIL: 112 != 97 delta time: 24
Now Testing Baud rate: 38400 format: 30 *** Succeeded ***
Now Testing Baud rate: 38400 format: 4 *** Succeeded ***
Now Testing Baud rate: 38400 format: 2 *** Succeeded ***
Now Testing Baud rate: 38400 format: 3 *** Succeeded ***
Now Testing Baud rate: 38400 format: 801 *** Succeeded ***
Now Testing Baud rate: 9600 format: 0 *** Succeeded ***
Now Testing Baud rate: 38400 format: 0 *** Succeeded ***
Now Testing Baud rate: 115200 format: 0 *** Succeeded ***
Now Testing Baud rate: 1000000 format: 0 *** Succeeded ***
Now Testing Baud rate: 2000000 format: 0 *** Succeeded ***
Now Testing Baud rate: 2400 format: 0 *** Succeeded ***
Now Testing Baud rate: 300 format: 0 FAIL: 96 != 97 delta time: 24
Now Testing Baud rate: 38400 format: 30 *** Succeeded ***
...
Figured out 300 baud won't work on T3.2 at 96mhz.
Serial1 uses F_CPU to calculate 13 bit baud divisor:
Code:
#define BAUD2DIV(baud) (((F_CPU * 2) + ((baud) >> 1)) / (baud))
Last edited: