AudioOutputI2S affecting H/W serial transmit?

Status
Not open for further replies.

Hemi

New member
Hi.

I have been using Teensy 4.0 and the audio shield to synthesize and output audio. Now I also need to send data out on a hardware serial port to control a second microcontroller (Arduino Nano v3).
It seems that sending of data through a serial port stops working when an instance of AudioOutputI2S is included in my code (i have tried TX1, TX2, TX6 and TX7). Without this instance the transmit behaves as expected.
My first thought was that the AudioOutputI2S object was reserving the pins, but looking at the source code (https://github.com/PaulStoffregen/Audio/blob/master/output_i2s.cpp) they do not appear to be used.
I created the simple example below. When the I2s1 object is included, the byte being transmitted by HWSERIAL.write(c); will not be received by the nano. For this example I am using pins 28 and 29 (Serial7).
Code:
#include <Audio.h>

//AudioOutputI2S           i2s1; // <<< RE-ADDING THIS LINE STOPS ALL OUTPUT ON THE HW SERIAL PORTS
AudioControlSGTL5000     sgtl5000_1;

#define HWSERIAL Serial7

void setup() {
  Serial.begin(9600);
  HWSERIAL.begin(9600);
  AudioMemory(10);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.8);
}

unsigned long g_lastSendTime = micros();
int c = 0;

void loop() {
  unsigned long now = micros();
  if(now - g_lastSendTime > 30000)
  {
    g_lastSendTime = now;
    HWSERIAL.write(c);
    c++;
    if(c == 255) c = 0;
  }  
}
I should mention that this is my first Arduino/Teensy project and I'm learning as I go along. Any help or guidance on this issue would be most appreciated. If this is the expected behaviour then I will search for some other workaround.

Thanks in advance,
Chris.
 
Hi.
Does anyone know if the code above *should* work with the i2s1 object commented back in? i.e. should HWSERIAL.write(c); still behave correctly?
If so then I will rebuild my circuit step-by-step from scratch since there may be a bad solder somewhere, or something else has gone awry.
Thanks,
Chris.
 
Is that NANO running at 5V? It might not see the 3.3V as high without level shifters in use?? - and if 5V the Nano will put 5V on the Rx and Tx pins which the T_4 won't tolerate.
 
Thanks for the reply.
I'm not sure but I think it might be running on 5V. I can check it this evening after work.
Cheers.
 
Hi Chris,

I ran your code successfully on a Teensy 4. The only thing I changed is the HWserial to TX1 [I did not want to solder wires on the backside of the Teensy4].
Modified code:
Code:
#include <Audio.h>

AudioOutputI2S           i2s1; // <<< RE-ADDING THIS LINE STOPS ALL OUTPUT ON THE HW SERIAL PORTS
AudioControlSGTL5000     sgtl5000_1;

#define HWSERIAL Serial1

void setup() {
  Serial.begin(9600);
  HWSERIAL.begin(9600);
  AudioMemory(10);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.8);
}

unsigned long g_lastSendTime = micros();
int c = 0;

void loop() {
  unsigned long now = micros();
  if(now - g_lastSendTime > 30000)
  {
    g_lastSendTime = now;
    HWSERIAL.write(c);
    c++;
    if(c == 255) c = 0;
  }  
}

Here is the output of the logic analyzer [T4 pin 1 connected to channel 0]:
DSView-200513-093130.jpg

So the code part is fine.

Arduino 1.8.12, Teensyduino 1.51.

Regards,
Paul
 
I ran it here on Teensy 4.1 using Teensyduino 1.52-beta4. I watched the serial output by connecting pin 29 to a FTDI cable.

I get the same output with and without AudioOutputI2S.

sc.png
 
Status
Not open for further replies.
Back
Top