Because of the holidays, TI E2E™ design support forum responses will be delayed from Dec. 25 through Jan. 2. Thank you for your patience.

This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430G2553 I2C Interface with MCP4725 12-bit DAC

Other Parts Discussed in Thread: MSP430G2553, MSP430G2253

I am having trouble interfacing the MSP430G2553 with the Sparcfun breakout board for MCP4725. I never get the interrupt to hit:

 

The DAC is inittialized after POR to 1/2 of VCC. I have simplified the code to just set the DAC to 0V.

 

The following is the initialization sequence:

 

void XI2C_Init()

{

   P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0

   P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0

  

//    P1OUT |= BIT6 + BIT7;

//    P1REN |= BIT6 + BIT7;

//    P1DIR |= BIT6 + BIT7;

   

   UCB0CTL1 |= UCSWRST;    

   UCB0CTL0 = UCMODE_3 + UCMST +  UCSYNC;     // I2C, Master, synchronous mode

   UCB0CTL1 = UCSSEL_2 + UCSWRST;             // Use SMCLK, keep SW reset

   UCB0BR0 = 12;                             // fSCL = SMCLK/12 = ~100kHz

   UCB0BR1 = 0;

   UCB0I2CSA = 0xC0;                         // Set slave address

   UCB0CTL1 &= ~UCSWRST;                     // Clear SW reset, resume operation

   IE2 |= UCB0TXIE;                          // Enable TX ready interrupt

   UCB0CTL1 |= UCTR + UCTXSTT;               // I2C TX, start condition

   UCB0TXBUF = 0x00;                         // Write MSB

 }

 

The following is the interrupt vector:

 

#pragma vector=USCIAB0TX_VECTOR

__interrupt void USCI0TX_ISR(void)

{

    DOUT_Toggle(LED_RED);

    UCB0TXBUF = 0;    // Transmit data byte

}

 

I gave read several times the MSP430 I2C Guide, the MCP4725, several examples, but I am still missing something.

The I2C transmitter interrupt never hits???

 

Your help would be appreciated.

Eduardo

  • eduardo said:
    UCB0I2CSA = 0xC0;                         // Set slave address

    0xc0 is the 'write address' o fthe slave (and 0xc1 is the 'read address'). However, teh MSP does set the R/W bit based on the UCTR bit and the slave address oyu have to write to CSA register is 7 bit sized without the R/W bit (and right-aligned). You'll need to use 0x60 as slave address.

    After sendign the start condition, th eslave doesn't answer. The USCI module sets the NACKIFG bit and if you'd set up the RX_ISR (which handle state interrupts in I2C mode, while the TX_ISR handles TX and RX events), you'd see it get called, ellign you that the slave selection failed.

  • Hi Jens-Michael,

     

    Thank you very much! you solved my problem. . The right-shift of the address fixed the problem.  By setting the UCB0I2CSA = 0x60;   (0xC0 right shifted 1)  the MCP4725 gets addressed correctly.

    I was able to get interrupts running and set the output to zero based on the code that I posted.

     

    Because I plan to use I2C bus with other slave devices, the I2C interface cannot be left dedicated to a single slave. I have to use

    a) Open Device: Sets the device into a known state and ready for master commands.

    b) RD or WR Device

    c) Close Device.

     

    Question:  What is the best way to set a given I2C slave into a known state?  Is this the answer?

    UCB0CTL1 |= UCTXSTP; // Send a STOP 

     

    Question: Do you have source code to share or a good sample for the I2C interface and the MCP4725 ?

     

    Again, thank you for the great help.

    Regards,

    Eduardo

     

     

     

  • eduardo said:
    ecause I plan to use I2C bus with other slave devices, the I2C interface cannot be left dedicated to a single slave

    I2C is a transaction-based bus protocol.

    Each transaction begins with a start, which sends the slave address and the direction bit, and ends with either another start (usually to switch from sending to receiving, e.g. sending a register address, then read it) or a stop.
    Since only a few devices (e.g. a single-port D/A without configuration) support continuously reading or writing without need to reset the communication protocol or switching the direction, you usually only end a transfer sooner or later with a stop. Then the bus is free for the next transfer to a different slave.

    In theory, you can even switch the slave before sending a repeated start. (necessary in a multi-master system when you do not want the other master to grab the bus).

    But yes, setting UCTXSTP  will end the current transfer after the currently send/read byty is finished, and you can write a new slave address and a new start.

  • I've followed the thread re your" MSP430g2253 to MCP4725" Connection.  I've tried much the same thing but with no success. Would you please  post your code in it's entirety. My attempts have frustrated me at every turn. I even tried substantially the same code as you put in your thread. (I right-shifted the slave address). 

    I suspect I'm missing some small detail.

    - Did you use the Launchpad power to power the MCP4725?

    - Did you use the Pull Up resistors on the MCP4725?

    Thanks

    Mike

  • Hello "Eduardo"

     

    Did you actually get the msp430G2553 talking to the MCP4725 Demo Board? If you have it working, I would be extremely interested in your configuration and what you did regarding the pullup resistors.

    I've had 0 success. I tried the right shift>>1 of the 0xC0 address.

     

    Thanks

    Mike

**Attention** This is a public forum