Rolfdegen
Well-known member
I'm building an effects device with Teensy4.0. I want to control Teensy4 FX parameters via I2C. A Teensy4.1 controls the FX parameters via I2C and supplies the audio signal to the Teensy4.0 via I2S. I have Teensy4.1 as the I2C master and Teensy4.0 as the I2C slave. Errors occur again during I2C transmission. If I disable the audio functions, I2C works flawlessly.
For testing, I plugged the Teensy4.0 and Teensy4.1 onto a breadboard and connected them via I2C. I'm not using audio, only I2C. I2C transmission is OK. Now I'm using a simple audio example on the Teensy4.1 (see code), and the I2C transmission is faulty. The I2C cables are very short, and I have 4.7K pull-up resistors on the I2C lines.
I use Arduino IDE Version 2.3.5 and Teensy Loader 1.59
Code Teensy4.1 I2C master
Code Teensy4.0 I2C slave
Rigol MSO5104 I2C analysis
For testing, I plugged the Teensy4.0 and Teensy4.1 onto a breadboard and connected them via I2C. I'm not using audio, only I2C. I2C transmission is OK. Now I'm using a simple audio example on the Teensy4.1 (see code), and the I2C transmission is faulty. The I2C cables are very short, and I have 4.7K pull-up resistors on the I2C lines.
I use Arduino IDE Version 2.3.5 and Teensy Loader 1.59
Code Teensy4.1 I2C master
C:
// Wire Master Sender
#include <Audio.h>
#include <Wire.h>
int led = 13;
AudioSynthWaveformSine sine1; //xy=285,416
AudioOutputI2S i2s1; //xy=501,413
AudioConnection patchCord1(sine1, 0, i2s1, 0);
AudioConnection patchCord2(sine1, 0, i2s1, 1);
void setup() {
AudioMemory(64);
pinMode(led, OUTPUT);
Wire1.begin();
Wire1.setClock(100000UL); // I2C speed 100KHz
sine1.amplitude(0.5);
sine1.frequency(500);
}
void loop() {
digitalWrite(led, HIGH); // briefly flash the LED
Wire1.beginTransmission(40); // transmit to device #40
Wire1.write(20); // sends five bytes
Wire1.write(55); // sends one byte
Wire1.endTransmission(); // stop transmitting
digitalWrite(led, LOW);
delay(250);
}
Code Teensy4.0 I2C slave
C:
// Wire Slave Receiver
#include <Audio.h>
#include <Wire.h>
int led = 13;
AudioInputI2S2slave i2s1; //xy=284,366
AudioOutputI2S i2s2; //xy=531,368
AudioConnection patchCord1(i2s1, 0, i2s2, 0); // is connected to DAC (PCM5102)
AudioConnection patchCord2(i2s1, 1, i2s2, 1);
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
while (Wire1.available() > 1) { // loop through all but the last
uint8_t c = Wire1.read(); // receive byte as a character
Serial.println(c); // print the character
digitalWrite(led, HIGH); // briefly flash the LED
}
int x = Wire1.read(); // receive byte as an integer
Serial.println(x); // print the integer
digitalWrite(led, LOW);
}
void setup() {
Serial.begin(9600); // start serial for output
Wire1.begin(40); // join i2c bus with address #40
Wire1.onReceive(receiveEvent); // register event
AudioMemory(64);
pinMode(led, OUTPUT);
}
void loop() {
delay(10);
}
Rigol MSO5104 I2C analysis
Last edited: