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.

Msp430fr6989 using MCP4725 DAC through I2C



Here is my code, but the interrupt in the while loop never triggers.

A0 is connected to GND, that would make my slave address 0b1100010 from the MCP4725 DAC.


Please help.



#include <msp430.h>
#include <stdint.h>
#include <math.h>

uint8_t thirdByte = 0, fourthByte = 0, i=0;


void accel_init() {

    P4REN |= BIT0 | BIT1;

    P4OUT |= BIT0 | BIT1;

    P4SEL0 &= ~(BIT0 | BIT1);

    P4SEL1 |=  (BIT0 | BIT1);



    UCB1CTL1 |= UCSWRST; //changed

    UCB1CTLW0 |= UCMST | UCMODE_3 | UCSYNC | UCSSEL__SMCLK;

    UCB1TBCNT = 0x07; //This may not be needed

    UCB1BRW = 60;  // as the email said.

    UCB1I2CSA = 0x62; // 0x62 when A0 pin = GND, 0x63 otherwise

    UCB1CTL1 &= ~UCSWRST;
    __enable_interrupt();
    PM5CTL0 &= ~LOCKLPM5;    // Unlock ports from power manager
}



accel_update(uint8_t thirdByte, uint8_t fourthByte){

    while (UCB1CTLW0 & UCTXSTP);

    UCB1CTL1 = UCSSEL__SMCLK | UCTXSTT | UCTR;


    while (!(UCB1IFG & UCTXIFG0));

    UCB1TXBUF = 0x00; // send data bits 11-8 and 0000 for control bits

    while (!(UCB1IFG & UCTXIFG0));

    UCB1TXBUF = 0x00;

    while (!(UCB1IFG & UCTXIFG0));

    UCB1CTL1 = UCSSEL__SMCLK | UCTXSTP;
}
void triangular_up(){
    for (thirdByte=0; thirdByte<0x100;thirdByte += 1){
        for (fourthByte=0; fourthByte<0x100;fourthByte += 16){
            accel_update(thirdByte, fourthByte);
            __delay_cycles(10);
        }
    }

}
void triangular_down(){
    for (thirdByte=0xFF; thirdByte>0;thirdByte -= 1){
        for (fourthByte=0xF0; fourthByte>0;fourthByte -= 16){
            accel_update(thirdByte, fourthByte);
            __delay_cycles(10);
        }
    }
}
void oc(void)
{
    /////OC
    // Unlock clock control registers
    CSCTL0_H = CSKEY_H ;
    // Set DCO to 24 MHz
    CSCTL1 = DCORSEL | DCOFSEL_6 ;
    // Set SMCLK and MCLK to 12 MHz
    CSCTL3 = DIVA_0 | DIVS__2 | DIVM__2 ;
    // Relock clock control registers
    CSCTL0_H = 0;
}
void main(void) {
    WDTCTL = WDTPW | WDTHOLD;    // kill the watchdog
    oc();// increase clock speed
    accel_init();
    while(1){
        accel_update(0,0);
    }
    //0 - 3.3v range
    //12 bit value, what you want to output
    //4096 values to output
    //each time you increment that by 1 bit, it increments by 1/4096 of the max values
    //just 3.3/4096 volts per increment of the values
}

  • Hi Tae!

    Tae Kim27 said:
    the interrupt [...] never triggers

    I think you did not completely understand the usage of interrupts yet. You do not have any interrupt enabled and you also do not have any interrupt handler function if one would occur. Instead you are polling the interrupt flags, which is OK. But you also enabled the global interrupts, so it looks like the mechanism isn't completely clear to you. I would suggest that you first try to understand the difference between using interrupts and polling the flags and then decide which way you want to go. There are code examples for your processor that help to learn working with it.

    Dennis

**Attention** This is a public forum