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.

CCS/MSP-TS430DA38: MSP430F2252

Part Number: MSP-TS430DA38

Tool/software: Code Composer Studio

hiii,

i am used i2c sample code(MSP430f2252) from TI Resource explorer using interrupt... Its possible for without interrupt in I2C? using msp430f2252. if possible ????

thanking you

  • Hi Siranjeevi,

    - Can you please link the code example you are referencing?
    - Is your question if the code example can be accomplished without the interrupt?

    Best,
    -Chris

  • 1. this is my project code i want to change polling method with out interrupt

    #include <msp430.h>

    int chkAcInput(void);
    unsigned short int ACInputVoltage (void);
    int chkAcI(void);
    void ADC_init(void);
    void i2c_init(void);

    #define CLOCK_FREQ 16000000

    #define LED_ACIN 0x01 //P1.0

    char AC_FLAG=0, ac_Val=0;

    unsigned int RxByteCtr;
    unsigned int RxWord;

    int main(void)
    {
    WDTCTL = WDTPW + WDTHOLD; // Stop WDT
    if (CALBC1_16MHZ==0xFF) // If calibration constant erased
    {
    while(1); // do not load, trap CPU!!
    }
    DCOCTL = 0; // Select lowest DCOx and MODx settings
    BCSCTL1 = CALBC1_16MHZ; // Set DCO
    DCOCTL = CALDCO_16MHZ;
    P1DIR |= 0x01;
    P1OUT |= ~LED_ACIN;
    while(1)
    {
    ac_Val = ACInputVoltage();
    }
    }
    /*-----------------------------------ADC_value_Comparesion_with_Volt-------------------------------------------------*/
    unsigned short int ACInputVoltage(void)
    {

    unsigned short int AcV_flag = 0;
    float ac_real, ac_ref=3.592;

    i2c_init();

    RxByteCtr = 1; // Load RX byte counter
    UCB0CTL1 |= UCTXSTT; // I2C start condition
    __bis_SR_register(CPUOFF + GIE); // Enter LPM0, enable interrupts

    ac_real=(RxWord/ac_ref);
    AcV_flag=(int)ac_real;
    return(AcV_flag);
    }


    /*-----------------------------------I2C_setup-------------------------------------------------*/
    void i2c_init(void)
    {
    P1DIR |= 0x01; // P1.0 output
    P3SEL |= 0x06; // Assign I2C pins to USCI_B0
    UCB0CTL1 |= UCSWRST; // Enable SW reset
    UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode
    UCB0CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset
    UCB0BR0 = 12; // fSCL = SMCLK/12 = ~100kHz
    UCB0BR1 = 0;
    UCB0I2CSA = 0x48; // Set slave address
    UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
    IE2 |= UCB0RXIE; // Enable RX interrupt
    }


    // The USCIAB0TX_ISR is structured such that it can be used to receive any
    // 2+ number of bytes by pre-loading RxByteCtr with the byte count.
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector = USCIAB0TX_VECTOR
    __interrupt void USCIAB0TX_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCIAB0TX_VECTOR))) USCIAB0TX_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
    RxByteCtr--;
    RxWord |= UCB0RXBUF; // Get final received byte,
    if (RxByteCtr == 1) // Only one byte left?
    {
    UCB0CTL1 |= UCTXSTP; // Generate I2C stop condition
    __bic_SR_register_on_exit(CPUOFF); // Exit LPM0
    }
    }

    2) i want to change polling method for without interrupt.

  • Siranjeevi,

    As noted in this thread - it is recommended to use an interrupt and follow the TI example code over polling unless you have a very specific application. 

    What is your application for this code that requires polling?

    -Chris

**Attention** This is a public forum