Hello all,
I am trying to establish i2c communication between MSP430g2955 and DRV2604L. The i2c code I am using works with a different slave device, but with the DRV2604L I always get a NACK.
I have tried several methods of debugging using a Bus Pirate to sniff the i2c bus and an oscilloscope. The data obtained by the bus pirate varies a lot. There are times where only a start and stop condition is transmitted. Other times the wrong address is sent. A few times I see the correct address and NACK from the slave.
I am setting the DCO to 1 MHz and running i2c off the SMCLK at 100KHz. I am using 1K external resistors on SDA and SCL.
Below are some code snippets of my i2c setup and simple writes that I am trying to perform on the haptics driver. The haptics driver enable is connected to VDD for now as I am currently trying to debug the i2c issue.
void i2c_init()
{
P3SEL |= BIT1 | BIT2; // Assign I2C pins to USCI_B0 0x06;
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMST | UCMODE_3 | UCSYNC; // I2C Master, synchronous mode
UCB0CTL1 = UCSSEL_2 | UCSWRST; // Use SMCLK, keep SW reset
UCB0BR0 = 10; // fSCL = 1 MHZ SMCLK/10 = ~100kHz
UCB0BR1 = 0; // upper byte of divider word
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
}
int i2c_writeByte(char slave_addr, char reg_addr, char data)
{
while((UCB0STAT & BUSY)!=0); //make sure bus is free
UCB0I2CSA = slave_addr; // Slave Address is 0x18 for accelerometer
UCB0CTL1 |=UCTR; //set write bit
UCB0CTL1 |= UCTXSTT; // send start and slave address+Write
UCB0TXBUF=reg_addr; //load register address to transmitt buffer
while(UCB0CTL1 & UCTXSTT); // Wait for the start sequence to complete
if (UCB0STAT & UCNACKIFG) //address not acknowledged
{
UCB0CTL1 |= UCTXSTP; // I2C stop condition
UCB0STAT &= ~UCNACKIFG; //clear nack flag
}
UCB0TXBUF=data;
UCB0CTL1 |= UCTXSTP; // I2C stop condition
return 0;
}
void init_Haptics() {
__delay_cycles(300);
i2c_writeByte(0x5A,0x01,0x00); //take device out of standby
i2c_writeByte(0x5A,0x01,0x43); //put device back to standby mode and set pwm input mode
}
void main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
if (CALBC1_1MHZ != 0xFF) // If calibration constant erased
{
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz
DCOCTL = CALDCO_1MHZ;
}
i2c_init(); //initialize i2c capabitilies for msp430
init_Haptics();
}
Any help is appreciated, Thanks in advance.
Regards,
Ever