# I2C with PIC32 and MCP4706 Not Working

We're working on a battery charger for an electric bicycle at the moment, but prototyping with a PIC32MX695F512H kit board and an MCP4706 DAC soldered onto a breakout board, programmed using a PICKIT3. We've got a few other peripherals all working so far, including a 20x4 LCD also over I2C, so at least that is working. Our issue is that our DAC operates on and outputs 5V, regardless of whether or not we have a Vref connected. (the chip defaults to short Vref to Vdd if nothing is connected to the pins)

The output from the DAC goes to a voltage follower that controls a power MOSFET, allowing a variable amount of current to flow to the battery based upon readings from a current sensor (in-line) and voltage sensor across the battery terminals.

Relevant code snippets are attached below:

#define DAC 0x60
.
.
.
// Configure I2C registers
void ConfigI2C()
{
//1 USES RD10 AS SCL1 AND RD 9 AS SDA1
/// I2CxCON I2CxSTAT I2CxADD I2CxMSK I2CxTRN I2CxRCV
I2C1BRG=0x186;                  //390 for 80MHz to 100KHz
I2C1CONbits.DISSLW=1;           //disable slew control for standard
I2C1CONbits.ACKDT=0;            //Use and ACK not NACK
TRISD=0;                        //Sets Port D to output
I2C1CONbits.ON=1;               //turn on I2C
}
.
.
.
// Start
void I2C_start(void)
{
I2C1CONbits.SEN=1;          //send start
while(I2C1CONbits.SEN){}  //waits till start bit detected
}

void I2C_stop(void)
{
I2C1CONbits.PEN=1;          //send stop
while(I2C1CONbits.PEN){}    //waits till stop bit detected
}
.
.
.
void SendI2C3(char addrs,char regis, char data)
{
char ack;
I2C_start();
ack=I2C_write(regis); //0xFE for LED
ack=I2C_write(data);  //0x20to0x7F standard
I2C_stop();
}


We just get Vref out. We've tried all 8 address the board can have, and no dice.

Anybody have any advice on how to help us? we've been stuck on this problem for a couple of days. Thanks.

• Do you see anything happening on the lines when viewing at the oscilloscope or logic analyzer? Mar 21 '13 at 0:53
• Didn't even think of that. We're hooking it up right now to take a look. Mar 21 '13 at 0:58
• This is only a 6 pin device. Desolder it and try another one. You could waste a lot of time on a problem that is specific to just one instance of a bad device. Which package do are you using for that DAC, by the way? SOT or DFN?
– Kaz
Mar 21 '13 at 1:09
• Is the working 20x4 LCD on the same I2C bus? That tends to confirm that the bus traces are working.
– Kaz
Mar 21 '13 at 1:15
• Same I2C bus, LCD still working. SOT package, so while it's a pain to solder, I can always try another device. Mar 21 '13 at 1:22

We got it working about a week or two ago-- sorry for the delay. Turns out the chip was either fried or bad. We used another breakout board (it's a tiny package that was a pain to solder, and only had one breakout), soldered the chip on, works completely fine. Marking it solved.

You're configuring the I2C lines as outputs.

TRISD=0;                        //Sets Port D to output


The output drivers may be interfering. Try configuring them as inputs. (This is what I have to do on PIC24.)