Electrical – MCP3221 ADC always returns zero in Proteus

adci2cmplabpicproteus

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):

Schematic

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

Clock and data line

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();
WriteI2C(0x9B);      // Address of the ADC is 0x9A, 0x01 is read mode
voltage = ReadI2C(); // voltage is a global int; read upper byte
AckI2C();
voltage <<= 8;       // Make room for the lower byte
voltage |= ReadI2C();// Read 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?

Best Answer

To answer my own question almost a year later:

The teaching assistant who gave me this task told me that this behavior is a known "bug" in Proteus and not my fault. Quite anticlimactic.