alexandros
Well-known member
I need to use a Teensy LC as an I2C slave for a Raspberry Pi, which at the same time will act as an I2C master in order to control Adafruit's quad DAC, MCP4728.
Teensy LC has two I2C busses, where the first bus is at pins 18 and 19, and the second at pins 22 and 23, right? I'm trying to access the second bus with Wire1 but I get this error:
Here's my code:
Any ideas?
Teensy LC has two I2C busses, where the first bus is at pins 18 and 19, and the second at pins 22 and 23, right? I'm trying to access the second bus with Wire1 but I get this error:
Code:
'Wire1' was not declared in this scope
Here's my code:
Code:
#include <Adafruit_MCP4728.h>
#include <Wire.h>
Adafruit_MCP4728 mcp;
byte inBytes[12];
void setup(void) {
Wire1.begin(0x0A);
Wire1.onReceive(receiveEvent);
mcp.begin();
Serial.begin(115200);
while (!Serial);
}
void loop() {
}
void receiveEvent(int howMany) {
int index = 0;
int val;
while (Wire1.available()) {
inBytes[index++] = Wire1.read();
}
switch (howMany) {
case 3:
val = inBytes[1] + (inBytes[2] * 128);
mcp.setChannelValue(inBytes[0], val);
Serial.print("channel "); Serial.print(inBytes[0]);
Serial.print(", val: "); Serial.println(val);
break;
case 6:
val = inBytes[1] + (inBytes[2] * 128);
mcp.setChannelValue(inBytes[0], val);
Serial.print("channel "); Serial.print(inBytes[0]);
Serial.print(", val: "); Serial.println(val);
val = inBytes[4] + (inBytes[5] * 128);
mcp.setChannelValue(inBytes[3], val);
Serial.print("channel "); Serial.print(inBytes[3]);
Serial.print(", val: "); Serial.println(val);
break;
case 9:
val = inBytes[1] + (inBytes[2] * 128);
mcp.setChannelValue(inBytes[0], val);
Serial.print("channel "); Serial.print(inBytes[0]);
Serial.print(", val: "); Serial.println(val);
val = inBytes[4] + (inBytes[5] * 128);
mcp.setChannelValue(inBytes[3], val);
Serial.print("channel "); Serial.print(inBytes[3]);
Serial.print(", val: "); Serial.println(val);
val = inBytes[7] + (inBytes[8] * 128);
mcp.setChannelValue(inBytes[6], val);
Serial.print("channel "); Serial.print(inBytes[6]);
Serial.print(", val: "); Serial.println(val);
break;
case 12:
val = inBytes[1] + (inBytes[2] * 128);
mcp.setChannelValue(inBytes[0], val);
Serial.print("channel "); Serial.print(inBytes[0]);
Serial.print(", val: "); Serial.println(val);
val = inBytes[4] + (inBytes[5] * 128);
mcp.setChannelValue(inBytes[3], val);
Serial.print("channel "); Serial.print(inBytes[3]);
Serial.print(", val: "); Serial.println(val);
val = inBytes[7] + (inBytes[8] * 128);
mcp.setChannelValue(inBytes[6], val);
Serial.print("channel "); Serial.print(inBytes[6]);
Serial.print(", val: "); Serial.println(val);
val = inBytes[10] + (inBytes[11] * 128);
mcp.setChannelValue(inBytes[9], val);
Serial.print("channel "); Serial.print(inBytes[9]);
Serial.print(", val: "); Serial.println(val);
break;
default:
break;
}
}
Any ideas?