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

Thread: Teensy 4.0 Serial and Audio issue

  1. #1
    Junior Member
    Join Date
    Jan 2021
    Posts
    4

    Teensy 4.0 Serial and Audio issue

    Hello,

    I am running a project where I need audio and serial. I am using a cs42448 codec with a teensy 4.0 and windows 10 on my computer.

    APPROACH 1
    If I set the device as audio/midi/serial it will work HOWEVER, if I pass it through a USB hub I start to have serial connection issues.

    --Here is the weird part--

    The audio is still working but i cannot send any USB serial to the teensy AFTER I SEND THE FIRST MESSAGE. I can still receive messages from the teensy but cannot transmit to it. I confirmed the first serial message I send gets to the teensy (tell it to turn on LED) but after that, It's like any other command I send gets ignored.

    --I have confirmed it has something to do with the USB Hub--

    If I use the same code but remove the hub, everything works fine. I have tried 4 different types of hubs (2.0/3.0 and 1 of which was an externally powered hub). I have to use a hub as the computer I will eventually use for the project will only have one port available and other hardware will need to go through it.

    Has anyone heard of this before? Is there a specific type of hub I should try to use/avoid.



    APPROACH2
    I tried to just set the device as Audio and use the Hardware Serial pins for serial communication. I am using an FTDI chip to translate USB <-> Serial. The FTDI chip and the teensy's USB both go through a hub to the computer. As soon as I do HWSERIAL.begin(any Baud Rate), I lose all audio.
    Below is the example usb audio passthorugh I modified for the CS42448 that I used for the test. Everything works fine until I uncomment HWSERIAL.begin(). I can then communicate via hardware serial but lose all audio. I have also tried setting the teensy as audio/midi/serial while doing this approach with the exact same results.


    Any suggestions or insight would be greatly appreciated. Thanks!


    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>

    #define HWSERIAL Serial5

    AudioInputUSB usb1; //xy=200,69 (must set Tools > USB Type to Audio)
    AudioOutputTDM i2s1; //xy=365,94
    AudioConnection patchCord1(usb1, 0, i2s1, 0);
    AudioConnection patchCord2(usb1, 1, i2s1, 2);
    AudioControlCS42448 sgtl5000_1; //xy=302,184

    void setup() {

    Serial.begin(9600);
    //HWSERIAL.begin(38400);
    AudioMemory(12);
    sgtl5000_1.enable();
    sgtl5000_1.volume(0.6);
    }

    void loop() {
    // read the PC's volume setting
    float vol = usb1.volume();
    int incomingByte;

    if (Serial.available() > 0) {
    incomingByte = Serial.read();
    Serial.print("USB received: ");
    Serial.println(incomingByte, DEC);
    HWSERIAL.print("USB received:");
    HWSERIAL.println(incomingByte, DEC);
    }
    if (HWSERIAL.available() > 0) {
    incomingByte = HWSERIAL.read();
    Serial.print("UART received: ");
    Serial.println(incomingByte, DEC);
    HWSERIAL.print("UART received:");
    HWSERIAL.println(incomingByte, DEC);
    }
    // scale to a nice range (not too loud)
    // and adjust the audio shield output volume
    if (vol > 0) {
    // scale 0 = 1.0 range to:
    // 0.3 = almost silent
    // 0.8 = really loud
    vol = 0.3 + vol * 0.5;
    }

    // use the scaled volume setting. Delete this for fixed volume.
    sgtl5000_1.volume(vol);

    delay(100);
    }

    // Teensyduino 1.35 & earlier had a problem with USB audio on Macintosh
    // computers. For more info and a workaround:
    // https://forum.pjrc.com/threads/34855...l=1#post110392
    Last edited by nerdID55; 06-23-2021 at 05:47 PM. Reason: added serial echo

  2. #2
    Junior Member
    Join Date
    Jan 2021
    Posts
    4
    I added delay(1) when I am reading my serial and it appears to have fixed the issue when going through a hub (approach 1). Just sharing in case anyone else has this issue.

  3. #3
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    1,057
    I had problems with usb1.volume() and quit using it. Calling it too fast might be the issue.

Posting Permissions

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