Other Parts Discussed in Thread: ENERGIA
Tool/software: Code Composer Studio
Hello,
I am trying to emulate 2 i2c slave devices with the TM4C123G. Basically I need to be able to receive i2c as slave in two adresses.
So from my rasberry pi which I have as the i2c master, I have connection to SCL2/SCL3 and SDA2/SDA3, and 10K pull up resistors, in place.
The following code partially works. i2cdetect will detect two devices at 0x40 and 0x42, but you can only write to 0x42 - and if you write to 0x40 it will crash. If the code is commented out to enable one i2c bus at one time, it will work for either i2c buses. I used 10K resistors, maybe that could be the problem.
But if there is a dual adress scheme for the tm4c it would be great, so i would not spend those extra pins.
Any ideas / help /recomendation greatly appreciated.
Best Regards,
C.A.
#include <Wire.h> void setup() { Wire.setModule(2); Wire.onReceive(receiveEvent2); Wire.begin(0x40); Wire.setModule(3); Wire.onReceive(receiveEvent3); Wire.begin(0x42); Serial.begin(230400); Serial.println("INIT"); } void loop() { } void receiveEvent2(int n) { Wire.setModule(2); Serial.print("2:\t"); while(0 < Wire.available()) { int c = Wire.read(); Serial.print(c); Serial.print('\t'); } Serial.println(); } void receiveEvent3(int n) { Wire.setModule(3); Serial.print("3:\t"); while(0 < Wire.available()) { int c = Wire.read(); Serial.print(c); Serial.print('\t'); } Serial.println(); }