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
}
}
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
}
}