Hello,
I am trying to interface MLX90614
my code gets trapped in the while loops of the tempRead() function
any thoughts why would that happen?
#include <msp430g2553.h> #ifndef TIMER0_A1_VECTOR #define TIMER0_A1_VECTOR TIMERA1_VECTOR #define TIMER0_A0_VECTOR TIMERA0_VECTOR #endif void FaultRoutine(void); void ConfigWDT(void); void ConfigClocks(void); void ConfigLED(void); void ConfigI2C(void); int tempRead(void); void ConfigTimerA2(void); #define SLAVEAD 0x00 int TRead=0; int temp; int temp_high; int temp_low; unsigned int PEC; int main(void) { volatile unsigned int i; ConfigWDT(); ConfigClocks(); ConfigLED(); ConfigI2C(); ConfigTimerA2(); _BIS_SR(LPM0_bits+GIE); //Enable global interrupts while(1){ } } void ConfigWDT(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer } void ConfigClocks(void) { if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF) FaultRoutine(); // If calibration data is erased // run FaultRoutine() BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO IFG1 &= ~OFIFG; // Clear OSCFault flag BCSCTL2 |= SELM_0 + DIVM_2 + DIVS_2; // MCLK = DCO/4, SMCLK = DCO/4 } void FaultRoutine(void) { P1OUT = BIT0; // P1.0 on (red LED) while(1); // TRAP } void ConfigLED(void){ P1DIR = BIT0+BIT6; // P1.0 (red) output P1OUT = 0; // LED off } void ConfigI2C(void){ P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0 P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0 UCB0CTL1 |= UCSWRST; // Reset I2C to configure IE2 |= UCB0TXIE + UCB0RXIE; // enable TX and RX interrupts /* Configurign I2C */ UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // Master, I2C mode, Synchronous UCB0CTL1 = UCSSEL_2 + UCSWRST; // SMCLK, and keep as reset UCB0BR0 = 5; // SMCLK/5 = 100 KHz UCB0BR1 = 0; UCB0I2CSA = SLAVEAD; // Set Slave address UCB0CTL1 &= ~UCSWRST; // Enable I2C } int tempRead(void){ UCB0CTL1 |= UCTR+UCTXSTT; // Start transmission while (!(IFG2 & UCB0TXIFG)); UCB0TXBUF = 0x07; // Access RAM, object Temperature 1 //while(UCB0CTL1 & UCTXSTT); // wait until start condition is sent while (!(IFG2 & UCB0TXIFG)); UCB0CTL1 &= ~UCTR; // Change to RX while (UCB0CTL1 & UCTXSTT); UCB0CTL1 |= UCTXSTT; // Start while(!(IFG2 & UCB0RXIFG)); temp_low=UCB0RXBUF; // Get low byte while(!(IFG2 & UCB0RXIFG)); temp_high=UCB0RXBUF; // Get high byte while(!(IFG2 & UCB0RXIFG)); PEC=UCB0RXBUF; // Read packet error code UCB0CTL1 |= UCTXSTP; // Stop temp = temp_low | (temp_high << 8); // Concatinate MSB and LSB temp = (temp*2 - 27315)/100; // temperature in degree celceues return temp; } void ConfigTimerA2(void){ CCTL0 = CCIE; // Allow periodic interrupt CCR0 = 12000; // Enable interrupts every 1 second TACTL = TASSEL_1 + MC_1; } #pragma vector=TIMER0_A0_VECTOR __interrupt void Timer_A_ISR (void){ TRead = tempRead(); CCR0 +=12000; }
I am new to MSP430 so I don't know much
I have been reading the manuals, I don't understand them very well though