Teensy 4.0 Serial.read fails with AudioOutputTDM2

Status
Not open for further replies.

geekEE

Active member
Here's a weird problem and so far I haven't found any workaround. I've got the Teensy 4.0 and I can use the Serial.read function to read characters from the USB emulated serial port. However, If I try to use AudioOutputTDM2 as well, then the Serial.read stops working. It just returns a 1 if characters come in slowly or occasionally a 0 if characters come in quickly. There is no problem with using AudioOutputTDM.

In the following example, I load it to the Teensy 4.0 and then run a terminal program (TeraTerm) to type characters. It should just print the ASCII codes for each character that I type, but that is not what happens if I try to use the AudioOutputTDM2. What's going on?

#include <Arduino.h>
#include <Audio.h>

// The behavior of this program depends on which TDM is used for tdm_out
// AudioOutputTDM: Serial.read will return the character read, as it should
// AudioOutputTDM2: Serial.read will return 1 or 0

AudioOutputTDM2 tdm_out;

void setup()
{
Serial.begin(115200); // opens serial port, sets data rate to 115200 bps
}

void loop()
{
if (Serial.available() > 0)
{
int incomingByte = Serial.read(); // read character
Serial.println(incomingByte, HEX); // print ASCII code in hex
}
}
 
This problem does not seem to occur when I use I2S2 output, only TDM2 output. I guess I'll have to do some cutting and jumping to swap some signals on my board.
 
Something is ODD indeed - using post #1 sketch and commenting out the line :: AudioOutputTDM2 tdm_out;

Really messes with the output. Instead of printing the ASCII HEX of the incoming character it just prints 69 and 0 some number of times - often less than the number of characters after the first.

Comment it out and it shows the ASCII in HEX of each entered character as expected. Perhaps easier to see with this altered code:
Code:
//#include <Arduino.h>
#include <Audio.h>

// https://forum.pjrc.com/threads/62073-Teensy-4-0-Serial-read-fails-with-AudioOutputTDM2?p=249232#post249232

// The behavior of this program depends on which TDM is used for tdm_out
// AudioOutputTDM: Serial.read will return the character read, as it should
// AudioOutputTDM2: Serial.read will return 1 or 0

//AudioOutputTDM2 tdm_out;

void setup()
{
	Serial.begin(115200); // opens serial port, sets data rate to 115200 bps
	while (!Serial && millis() < 4000 );
	Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
}

void loop()
{
	int gg = 0;
	while (Serial.available() > 0)
	{
		char incomingByte = Serial.read(); // read character
		Serial.print(incomingByte, HEX); // print ASCII code in hex
		Serial.print(',');
		gg = 1;
	}
	if ( gg )
		Serial.print('\n');
}
 
Status
Not open for further replies.
Back
Top