Raghupathikokkarakonda
Newbie level 2
Hi,
I have written the below piece of code for getting the data from a humidity sensor to MSP430F2774.
the execution control is not going inside the interrupt routine.please help me in finding out the bug in the code.
one more help is how to set the clock and baudrate for I2C communication. actually I am using the ACLK,but not able to find ACLK value, hence not able to set the baudrate exactly.
I have written the below piece of code for getting the data from a humidity sensor to MSP430F2774.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 //include the controller header #include "msp430f2274.h" #include "intrinsics.h" #include "in430.h" void delay(void); void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT P3SEL |= 0x06; // Assign I2C pins to USCI_B0 UCB0CTL1 |= UCSWRST; // Enable SW reset UCB0CTL0 = UCMODE_3 + UCSYNC + UCMST; // I2C mode, sync mode UCB0I2CSA = 0x27; // deafult slave address is 027h UCB0CTL1 |= UCSSEL_1 ; UCB0BR0 = 2; //start the transmission UCB0CTL1 &= ~UCSWRST ; // Clear SW reset, resume operation IE2 |= UCB0RXIE + UCB0TXIE; // Enable TX and RX interrupts __bis_SR_register(GIE); // Enable global interrupts while(1) { UCB0CTL1 |= UCTR; //sending the MR to HIH sensor UCB0CTL1 |= UCTXSTT; // start bit is enable while (UCB0CTL1 & UCTXSTT); //in-loop for getting the ACK // making master to receive mode: UCB0CTL1 &= (~UCTR); UCB0CTL1 |= UCTXSTT; // start bit is enable while (UCB0CTL1 & UCTXSTT);//waiting the ACK from sensor TXData = UCB0RXBUF; } } // USCI_B0 State ISR #pragma vector = USCIAB0RX_VECTOR __interrupt void USCIAB0RX_ISR(void) { TXData = UCB0RXBUF; RxFlag=1; } #pragma vector = USCIAB0TX_VECTOR __interrupt void USCIAB0TX_ISR(void) { P1DIR = 0x1; P1OUT = 0x01; delay(); } void delay(void) { P1DIR = 0x01; unsigned int i = 0; while( i<65000 ) { P1OUT = 0x01; i++; } P1OUT = 0x00; }
the execution control is not going inside the interrupt routine.please help me in finding out the bug in the code.
one more help is how to set the clock and baudrate for I2C communication. actually I am using the ACLK,but not able to find ACLK value, hence not able to set the baudrate exactly.
Last edited by a moderator: