I found this... do you have to specify the second set of pins by enabling Dual Control... looks like it. Simple enough to try. I've only read this about seven times. Let's see...
Working on slave ATM, can't seem to get it to respond to it's address... so i'm not sure what is needed. Focusing in on getting it to respond at this point. With most of the 'C' code I find, it does a couple of bus and error checks(collision , buserr) and then checks the APIF(address|stop). Guess I need to concentrate on that Slave code with the APIF detect. APIF can be either stop condition or address match which is determined by the AP bit in SSTATUS. For me the problems usually avalanche and fall...
I rarely use MPLABX for anything anymore. Sooner or later MPLABX will be all we have. I'll see if I can make heads or tails of it. My assembly is NOT the way to go for Hardware i2C ... I have no idea what I'm doing or what a typical slave/master relationship looks like this early in my attempts. I have not attempted to do any bus error checking or timeout loops yet. The only thing I can do reliably is set an address and read my 24LC256 EEPROM with polling only. I have a lot of time invested in I2C...
As far as the formula for TWI... ??? I can't guarantee it's validity. There is a calculation for T_Rise and I think it is assumed to be Zero in this formula. There are latency bits to be set in CTRLA... i think? I'm not having a lot of success getting the slave mode working. 400 KHz may need smaller values in the resistors... I'm using 10K right now, but only up to 200 KHz. I'm glad you're having some luck!
New TWI read code
Sometimes the data sheet works against you...
There is excess code that needs to be trimmed in the " rdone_check: " loop. The program was malfunctioning on my tn1616. I will send updated code later after I verify that the new code works(better)on the m4809. After that, on to the Slave...
This code sets(writes) an address of 32 in the 24LC64, reads the 32 bytes starting @ address 32, prints to USART3 , Waits 2 sec, Repeat. All done by polling the TWI flags.