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
}