Page 1 of 1

I2C reading MCP 3424

Posted: Tue Dec 06, 2011 7:34 am
by ssultana
I am trying to use MCP 3424(A to D converter) with MOD 5213.I can communicate with the converter as I can see I am able to write the configuration byte and it sends 1(OK to write) .But while reading the conversion byte it appears to me Mod 5213 is not reading the correct values.Please advice me on that.

Re: I2C reading MCP 3424

Posted: Tue Dec 06, 2011 8:02 am
by v8dave
Hi there,

It just so happens I am using the MCP3424 myself. For this MCP3424 I have the Address line A0 tied high as this is the second device on the bus.

Code: Select all

void ReadSensors()
{
    int Bits;
    BYTE ch1, ch2, config;
    BYTE address = 0x6C;		// Address of the MCP3424 for 4 channel
    BYTE Status;
    BYTE buf[10];

    OSCritEnter(&ShareI2C, 0);
    Status = I2CReadBuf(address, buf, 3, true);
    if(Status > 3)
    {
        OSCritLeave(&ShareI2C);
        return;
    }
    OSCritLeave(&ShareI2C);

    ch1 = buf[0];
    ch2 = buf[1];
    config = buf[2];

    if(!(config & 0x80))			// Not doing a conversion?
    {
        Bits = ((int) ch1 << 8) + ch2;

        Sensor[ADCChannel].Current = EngUnits(Bits, 4, 20, 6400, 32000);
        Sensor[ADCChannel].Calculated = EngUnits(Bits, 0,
                                                                   ConfigData.SensorRange[ADCChannel],
                                                                   6400, 32000) +
                                                                   ConfigData.SensorOffset[ADCChannel];
        ADCChannel++;
        if(ADCChannel > 3) ADCChannel = 0;
        //
        // Start a conversion going
        //
        buf[0] = 0x88 | ADCChannel << 5;
        OSCritEnter(&ShareI2C, 0);
        I2CSendBuf(address, buf, 1, true);
        OSCritLeave(&ShareI2C);
    }
}
I use OSCritEnter because I use the I2C elsewhere for the real time clock and found that calling I2C functions in more than 1 task really messed things up.

Hope this helps.
Dave...

Re: I2C reading MCP 3424

Posted: Fri Dec 09, 2011 8:46 pm
by ahbushnell
Thank you. That looks like it should be helpful.
Andy