This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/EK-TM4C123GXL: Two i2c slave ports active at the same time on the TM4C123

Part Number: EK-TM4C123GXL
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();
}

  • Why do you consider 10K pull-up Rs a (potential) problem?   (they prove far more effective than much higher value, MCU internal Rs.)

    You've presented unique, "function calls only" (with ALL of the "code details "hidden"" - such proves (beyond) the abilities of most here (or likely anywhere) - to review & guide/comment.

    You must realize that your, "actual" code IS required" (calling functions alone - prove w/out (much) value) - ("much" - to be kind...)

    As an example - you call, "Wire.setModule(2);"     How can anyone here "know" the "workings of that function?    And the "correctness of your code implementation?    Other than the "Serial.print()" - which we may be able to "guess" - myself/others - have NO CLUE!     

    Is it not your job - when seeking assistance here - to provide such (NEEDED) detail?

  • Hi Can,
    TM4C123 supports second slave address. Please refer to the datasheet for details. It has both the I2CSOAR and I2CSOAR2 registers. I think 10K should be fine for pullup for standard speed. It will depend on the I2C speed and the total capacitance on the bus from the number of devices you have. But to calculate I2C pullup you can reference this app note. www.ti.com/.../slva689.pdf

    I don't have much experience with Energia. If you want to utilize the full capability of the MCU I will recommend you use the TivaWare library. Below is the API to use to configure two different slave addresses.

    16.2.2.36 I2CSlaveAddressSet
    Sets the I2C slave address.
    Prototype:
    void
    I2CSlaveAddressSet(uint32_t ui32Base,
    334 July 25, 2016
    Inter-Integrated Circuit (I2C)
    uint8_t ui8AddrNum,
    uint8_t ui8SlaveAddr)
    Parameters:
    ui32Base is the base address of the I2C module.
    ui8AddrNum determines which slave address is set.
    ui8SlaveAddr is the 7-bit slave address
    Description:
    This function writes the specified slave address. The ui32AddrNum field dictates which slave
    address is configured. For example, a value of 0 configures the primary address and a value
    of 1 configures the secondary.
    Note:
    Not all Tiva devices support a secondary address. Please consult the device data sheet to
    determine if this feature is supported.
    Returns:
    None
  • Greetings Charles,

    Our poster made no mention of "energia" - it was entirely absent from poster's: Subject Line, Post's Body, and Tags.
    I recall you past being, "reserved about "energia's use" (due to its limitations) - yet you (somehow) have (now) recognized poster's function calls as being, "energia-based."

    As "energia" has its own, dedicated forum - and as poster made NO mention of "energia's exclusive use - "How could a "non-energia user" have "known" that "energia" was "in play?"

    Might you advise such posters - when presenting issues & code (outside) of (the expected) "normal/customary" TM4C style & usage - that they should make (some) mention of their "special usage?"   Had I had the slightest "hint" of energia - I would not have misspent time/effort...

  • Hi cb1,
    You are right. Re-read the post the poster did not mention Energia specifically. He mentioned about Raspberry Pi and the code looks Energia sketches to me using the "Wire" library for I2C. But it could be the code for the RP. Let's wait for the poster to clarify.
  • Hello cb1_module,

    You are right - this is Energia code, I should have tagged it as such.
    Although I use CCS as well, I usually prototype in Energia, then import it to CCS. Basically I am transitioning to CCS from Energia.

    Thank you,
    -CA