having problems with i2c

hello you all

i've been working on an i2c communication among a unique master and several slaves (all of them pic16f877) but a problem arose when trying to send data from slaves to the master:

when working with a slave as transmitter, after setting sspcon2.RCEN, the SDA line is supposed to get the value of the most significant bit contained in SSPBUF and then shifting out the next bits with the falling edges of the SCL line (so that the second bit of the byte to be transmitted is shifted out with the falling edge of the first clock pulse, the third bit with the second falling edge... and so on), but what happens in my case is that the first bit shifted out is not the MSB (bit 7), but the next (i.e. the sixth). With this, data like

10000000 is received by the master as 0 because the first bit shifted out is a 0 (bit 6) and both, the first and second clock pulses read 0; and data like 01000000 is received as 11000000 because with the first and second clock pulses a 1 is read. Using a scope probe to view the state of the SDA & SCL lines -simulation in proteus 6- i saw that the first change in the bits to be shifted out is not happening at the first falling edge of SCL but in the second....

in a former conversation i was told that maybe the problem was on two control bits for the clock which are: polarity and phase

since the beginning i had very clear one of them:

- CKP (clock polarity) which must be set after writing sspbuf (according to i2c specs) but i'm not sure about the second:

- clock phase. After reading the specifications I could not find something specific regarding that control bit, but the most similar one i found was (please correct me if i'm wrong) CKE (clock edge select) that, when working in i2c mode, must be set for SMBUS specs input levels or cleared for i2c specs input levels ...

in my code (which is based on microchip app notes 734 and 735) CKE is always clear in the slaves, and CKP is set after writing sspbuf (as sugested above)

but what should i check by that control bits besides that?

Sorry for not having this very clear but, as you should have noticed, I´m just a beginner...

thank you very much for your help... and patience, to read such a long message

juan

Reply to
juan
Loading thread data ...

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.