I2C with PIC32 and MCP4706 Not Working

chushibiao

New Member
Jan 2, 2018
1
0
1
25
Hello guys, forst post in here, please be kind. I am recently 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 http://www.kynix.com/Detail/954152/PICKIT3.html . 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.A10M=0; //Use 7-bit addresses
I2C1CONbits.DISSLW=1; //disable slew control for standard
I2C1CONbits.ACKDT=0; //Use and ACK not NACK
I2C1ADD=22; //Sets slave address for PIC32
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(addrs); //Address for LED is 0x50
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 me? I've been stuck on this problem for a couple of days.
Thanks all advice.
 

Dan

Staff
Staff member
May 25, 2008
12,775
106
48
55
Moosylvania
Howdy and welcome!

Sorry to say I'm lost as to your questions. But some great and brilliant folks here.

Never worry about folks here being unpleasant. It's actually against the rules to be unkind. (Love dead folks!)

But hoping some one will jump in with better understanding of your queries.

Again, welcome!