• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

I2C Comm


I am using a PIC18F47K42 as a master and a PIC18F46K22 as a slave with the following code from MMC for the master

uint16_t i2c2_read2ByteRegister(uint8_t address, uint8_t reg)
uint16_t    result;
I2C2ADB1 = (uint8_t)(address<<1);
I2C2CNT = 1;
I2C2CON0bits.RSEN = 1;
I2C2CON0bits.S = 1; //Start
address = (uint8_t)(address<<1);
I2C2ADB1 = (uint8_t)(address| 0x01); //Change the R/W bit for read
I2C2CON0bits.S = 1; //Start
I2C2CON0bits.RSEN = 0;
result = receiveByte();//read MSB of the 2byte register
result = result<<8;
result = result | receiveByte();//read LSB of the 2byte register
return result;
AHEN, DHEN, SEN bits on the slave are set.

If you look at the trace you can see that the master send the write address (0x18) and the register to the slave with the slave ACK'ing but the master is not sending the read address, instead it appears to time out and send a P. I know that the master is waiting for something form the slave but not sure what. The slave is reading the buffer to clear the flag and is releasing the clock.

You can see in the trace that it then goes on to write to (0x50) the display.

If the slave NACK's then the master will send both the read and write address


Latest threads

EE World Online Articles