# MCP3221 ADC always returns zero in Proteus

I am interfacing PIC18F2320 with MCP3221 ADC over I2C. When I try to read the converted value from ADC, only zeros are returned. I'm using MPLAB libraries. ADC is in A5 address mode. The AIN voltage is 2.503 V, what should be around 2048 after conversion.

Schematic looks like this (sorry for the mess, there was other stuff around and I'm debugging it so it isn't clean, just ignore MAX232, as removing it doesn't affect the result):

Captured lines look like this (upper is clock; it's easy to observe the three groups of 9b each):

The code I'm using is following:

// Set the ports to input, as the manual instructs
TRISCbits.TRISC3 = 1;
TRISCbits.TRISC4 = 1;

// Open I2C in master mode, slew off, as I'm aiming for 100kHz
OpenI2C(MASTER, SLEW_OFF);
SSPADD = 10; // A bit under 100kHz, because the MCU is on 4.1925 MHz

StartI2C();
voltage = ReadI2C(); // voltage is a global int; read upper byte
AckI2C();
voltage <<= 8;       // Make room for the lower byte
NotAckI2C();
StopI2C();


I have tried adding a delay after the address byte, but the result stays the same.

I have tried addressing with 0x9A only, in which case the data line is always high during reading.

Any other ideas?

• My advice is that its only marginally useful to put your effort into getting a simulation like this to work. You're better off working with a real system. – Scott Seidman Feb 2 '16 at 16:30
• What library are u using? Why are the I2C pins set as input when you are using the PIC as a master? Why are you even touching the pins or SSPADD at all? From what I recall, any library that has a function like OpenI2C() usually does the all the pin/register manipulation internally, especially considering that the SDA pin acts as both input and output in I2C operations. I recommend you look at the I2C source code to determine the arguments you need to pass to the functions to start the I2C peripheral, read and write to it as well. – SoreDakeNoKoto Feb 2 '16 at 17:07
• I'm using MPLAB C18. I'm setting pins as input because the PIC18F2320 manual says that it's required to use I2C. I've gone over the source code and SSPADD isn't read or written anywhere, nor is PORT C. Furthermore, one of the examples in the library's docs sets it this exact way. I'm afraid that the library doesn't handle the mentioned things. – Alfis Feb 2 '16 at 17:15