Continue to Site

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.

  • 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

Status
Not open for further replies.

TucsonDon

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

C:
uint16_t i2c2_read2ByteRegister(uint8_t address, uint8_t reg)
{
uint16_t    result;
I2C2_Initialize();
I2C2ADB1 = (uint8_t)(address<<1);
wait4BusFree();
I2C2CNT = 1;
I2C2CON0bits.RSEN = 1;
I2C2CON0bits.S = 1; //Start
wait4Start();
sendByte(reg);
wait4MDRSetcount(2);
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
wait4Stop();
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
 

Attachments

  • screenshot.png
    screenshot.png
    113.4 KB · Views: 191
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top