-2
\$\begingroup\$

I'm currently trying to receive data from the 2-wire serial interface of an image sensor with a PIC18F45K20 written with C18 in MPLAB X IDE v. 1.41. How do I initialize the I2C protocol and how do I generate the serial clock at 25MHz from the PIC?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

You don't "initialize" IIC protocol. The bus simply starts out idle, which is each line passively pulled up. Individual message do have a special start and end sequence. A start is the data line going low with the clock high (normally the data line is not allowed to change when the clock is high), and a stop is the data line going high with the clock high.

As for how to generate the clock, this is done inside the IIC hardware (assuming you are using IIC hardware). In this case, IIC is implemented as one capability of the MSSP (master/slave serial port) peripheral. This peripheral is very well described in chapter 17 of the datasheet starting on page 193. If you are planning on using this peripheral to communicate with the IIC bus, you of course have to read that chapter of the datasheet. Details like how to set up the baud rate generator are in there.

As a separate note 25 MHz is way too fast for IIC, and I doubt the PIC can produce that baud rate anyway. I haven't looked just now, but the baud rate generator usually works off the instruction clock, which is limited to 16 MHz on that PIC. Most IIC devices are specified to work up to 400 kHz, with some only 100 KHz. Remember that IIC has passive pullups on both lines and the maximum current sink requirement for devices is rather low, so rising edges can only be so fast.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.