Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Teensy 4.0 Serial.read fails with AudioOutputTDM2

  1. #1
    Junior Member
    Join Date
    Apr 2020
    Posts
    13

    Teensy 4.0 Serial.read fails with AudioOutputTDM2

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

  2. #2
    Junior Member
    Join Date
    Apr 2020
    Posts
    13
    Could this be related to the other bug that I found with the TDM2 input?
    https://forum.pjrc.com/threads/60605...e-stereo-input

  3. #3
    Junior Member
    Join Date
    Apr 2020
    Posts
    13
    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.

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,231
    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');
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •