Hello
I am trying to communicate with a 9DoF stick using I2C on the f5529. I was able to do the same thing using the g2553, but decided to switch to the 5529 because of its higher speed. Therefore, a lot of my code is patched together from my previous work using the 2553. The problem that I am having is that the code never enters the 2nd if statement (tx counter = 1) in the interrupt. What could be causing this? Code is posted below. I am using Energia.
Thanks
#include <msp430f5529.h> #define ADXL345_ADDRESS (0xA6 >> 1) //There are 6 data registers, they are sequential starting with th LSB of X. //We'll read all 6 in a burst and won't address them individually #define ADXL345_REGISTER_XLSB (0x32) //Need to set power control bit to wake up the adxl345 #define ADXL_REGISTER_PWRCTL (0x2D) #define ADXL_PWRCTL_MEASURE (1 << 3) #define ITG3200_ADDRESS (0xD0 >> 1) //request burst of 6 bytes from this address #define ITG3200_REGISTER_XMSB (0x1D) #define ITG3200_REGISTER_DLPF_FS (0x16) #define ITG3200_FULLSCALE (0x03 << 3) #define ITG3200_42HZ (0x03) #define HMC5843_ADDRESS (0x3C >> 1) //First data address of 6 is XMSB. Also need to set a configuration register for continuous measurement. #define HMC5843_REGISTER_XMSB (0x03) #define HMC5843_REGISTER_MEASMODE (0x02) #define HMC5843_MEASMODE_CONT (0x00) int accelerometer_data[3]; int gyro_data[3]; int magnetometer_data[3]; byte i2c_tx_reg; byte i2c_tx_data; int tx_counter; int rx_counter; int i; volatile boolean i2c_busy; byte read_data[6]; #pragma vector= USCI_B0_VECTOR __interrupt void USCI_B0_ISR(void){ if(UCB0IFG & UCTXIFG){ //Tx interrupt if(tx_counter == 2){ UCB0TXBUF = i2c_tx_reg; tx_counter--; } else if(tx_counter == 1){ UCB0TXBUF = i2c_tx_data; tx_counter--; } else if(tx_counter == 0){ UCB0CTL1 |= UCTXSTP; //Stop condition UCB0IFG &= ~UCTXIFG; //Clear interrupt flag i2c_busy = false; } } } void init_i2c(void){ UCB0IE &= ~(UCRXIE + UCTXIE); //Disable RX and TX interrupt UCB0CTL1 |= UCSWRST; // Enable SW reset UCB0CTL0 |= 0x0F; // I2C Master, synchronous mode UCB0CTL1 |= UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset UCB0BR0 = 0x80; UCB0BR1 = 0x00; UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation UCB0IE |= UCRXIE + UCTXIE; //Enable RX and TX interrupt } void i2c_write(int address, byte reg, byte data){ while(UCB0CTL1 & UCTXSTP); //Wait for stop condition to clear tx_counter = 2; i2c_busy = true; UCB0I2CSA = address; //Write slave address i2c_tx_reg = reg; i2c_tx_data = data; UCB0CTL0 &= ~UCSLA10; //Set size of address to 7-bit UCB0CTL1 |= UCTR; UCB0CTL1 |= UCTXSTT; //Set for transmitter mode and generate a start condition while(i2c_busy); //Wait for i2c to finish } void init_itg3200(){ //Set DLPF to 42 Hz and set the scale to "Full Scale" i2c_write(ITG3200_ADDRESS, ITG3200_REGISTER_DLPF_FS, ITG3200_FULLSCALE | ITG3200_42HZ); } int main(void){ WDTCTL = WDTPW + WDTHOLD; // Stop WDT P4SEL |= BIT1 + BIT2; P4REN |= BIT1 + BIT2; init_i2c(); __bis_SR_register(GIE); i2c_busy = false; while(1){ init_itg3200(); } }