I2C reading MCP 3424

Discussion to talk about software related topics only.
Post Reply
ssultana
Posts: 3
Joined: Tue Oct 18, 2011 8:08 am

I2C reading MCP 3424

Post 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.
v8dave
Posts: 333
Joined: Thu Dec 31, 2009 8:31 pm

Re: I2C reading MCP 3424

Post 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...
ahbushnell
Posts: 25
Joined: Thu Apr 24, 2008 7:45 pm

Re: I2C reading MCP 3424

Post by ahbushnell »

Thank you. That looks like it should be helpful.
Andy
Post Reply