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 question

Status
Not open for further replies.

YAN-1

New Member
Hi. I have a question to ask regarding sending data from the master to the slave in the I2C module. After I send the address of the slave, I should wait for the ACK from the slave. What if I didn't get an ACK because of something going on at the slave end? What would be a reasonable action in that case? What I did was that after each byte sent to the slave, I go into a while loop. The loop tries to send that byte over and over until it is sent and an ACK is received so that the program gets out of the loop. In case the byte is an address, the loop sends a repeated start and then sends the address again. In case the byte was data, the loop just sends it again. Is that logical? Thanks.
 
I assume you're talking PIC here.
The I2C protocol standard is quite poorly planned overall. Also the PIC has had a number of errata regarding their I2C module that may give rise to bad states like you mention. Microchip never documented an error recovery process using the I2C module but then neither did the standard.

As you note, say you miss an ACK for whatever reason. The protocol does not outline any recovery procedure. The thing to do is the master just needs to have a reasonable timeout, forget about the existing packet, and issue a new request, address and all. The odd part is the protocol spec does not have a state diagram and never explicitly required that the slave implementation be able to respond to a restart from a state where it's waiting for data. But as I recall it seems to work since the designers were basically sane.
 
Hmm. Thanks. I was wondering. It says in one of the documents by Microchip that there are some addresses that are reserved and that cannot be assigned to the slaves (I am usign a 16F877). Does anyone know what these are? I gave the slave I am communicating with an address of 0x02. However, it doesn't seem to be responding. I am pretty sure the problem is in my program and not in the address, but I was just wondering because there should be like 5 other slaves in the near future. And about the process of assigning an address to a slave, I just write the value of the address to SSPADD register once and that's it? (like SSPADD = 0x02;) Thanks.
 
Status
Not open for further replies.

Latest threads

Back
Top