Other Parts Discussed in Thread: HDC2022
Hello all,
I'm working on I2C in msp430fr5043. I'm tried to interface with AD5122A (Digital potentiometer).
I selected SCLK frequency is 100KHz. ADDR0 and ADDR1 of AD5122A is connected to GND so according to datasheet of AD5122A, slave address is 0101111.
After start condition and slave address i sent two more bytes to set the potentiometer of 10K ohm is 0x10, 0x0D.
Here the problem is after the start condition UCNACKIFG is set.
Please find the code below.
#include <msp430.h> /** * main.c */ char array[] = {0x10,0x0D}; int cnt=0; int main(void) { WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer // Software reset enable UCB1CTLW0 |= UCSWRST; // Clock source selection and SCLK speed UCB1CTLW0 |= UCSSEL__SMCLK; UCB1BRW = 10; //I2C Mode UCB1CTLW0 |= UCMODE_3; //Master mode UCB1CTLW0 |= UCMST; //Transmitter mode UCB1CTLW0 |= UCTR; //Slave address UCB1I2CSA = 0x5E; //Auto stop UCB1CTLW1 |= UCASTP_2; UCB1TBCNT = sizeof(array); // GPIO Initialization P5SEL0 &=~ BIT5; P5SEL1 |= BIT5; P5SEL0 &=~ BIT6; P5SEL1 |= BIT6; PM5CTL0 &=~ LOCKLPM5; //Disable software reset UCB1CTLW0 &=~ UCSWRST; //Enable interrupt UCB1IE |= UCTXIE0; __enable_interrupt(); int i=0; while(1) { UCB1CTLW0 |= UCTXSTT; for(i=0;i<10;i++); } return 0; } #pragma vector = EUSCI_B1_VECTOR __interrupt void EUSCI_B1_I2C_ISR(void) { if(cnt == sizeof(array)-1) { UCB1TXBUF = array[cnt]; cnt=0; } else { UCB1TXBUF = array[cnt]; cnt++; } }
I'm using
1. MSP430-FR5043 microcontroller
2. MSP430 USB-Debug - Interface (MSP-FET430UIF) for programming.
Please guide me where I'm doing mistake.
Thanks,
Ashok.