I need to read data from 3 of the same kind of batteries with SMBus so I decided to use an I2C multiplexer for this purpose. I can communicate with 1 battery without any error. But I cannot communicate with the mux. I use PIC18F26K83 and the mux I am using is TCA9546A.
Datasheet of the mux: TCA9546A
This is the SDA line that goes to mux from my PIC: (I am trying to send 0x01 to the address 0xE0)
Does this data that I send to mux looks okay?
And the code hangs in mux1()
function while(!I2C1CON0.B3){ } //Master Data request loop
And this is the schematic of the mux SCL and SDA lines are connected to PIC. RESET line is also connected to PIC. I make it high in the program.
Edit: This is the last image from the scope. (Blue traces are SCL and yellow traces are SDA from PIC to mux.)
Last Edit: So for MUX to select channel it needs to be reseted all the time…
And for the rest of the problem was occured because I did not correctly do the hardware part. If anyone wonders or needs the code I can send.
Best Answer
I'm writing as an answer so you can try the following code. Use
MFINTOSC
for I2C clock and enable clock stretching. I don't know about relying on "Master Data Request", you can try avoiding that. Use the functioni2c_init
below to initialize i2c, and use common i2c code. This code I converted from MCC to work with your code. Let me know what happens.Even though it uses PCIF it doesn't require the interrupts to be enabled as the flags will still get set - you can still poll the interrupt flags. If it still fails please issue a schematic of your I2C interface between the PIC and the MUX. If you still have trouble with I2C , see TB3191
It might also be an idea to pulse the RESET pin low (low then high) before each MUX write. in the event that communication on the I2C bus enters a fault state, the TCA9546A can be reset to resume normal operation using the RESET pin