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.

Timer and I2C intergration issues

Other Parts Discussed in Thread: MSP430F1612

Hi,

I am using I2C and timer in the MSP430F1612 controller. I have taken the code from slaa208.zip as reference for interfacing with the EEPROM. Everything works fine (Write & Read). But when I use the timer, program control is hanging at I2C routines. What could be the problem? I have attached the source code.

Test code.rar
  • Hi,

    I assume that the program control is hanging at the function EEPROM_AckPolling. The I2C module of the MSP430x16x family does not really support the transmission of the control byte onlhy. However, with a trick that is used in the app note slaa208 this can be realized. Care should be taken regarding to the timing within the EEPROM_AckPolling routine - it should not be interrupted.

    So first of all I would check where the code execution is hanging (my assumption is it hangs within the EEPROM_AckPolling function). 

    If so I would try either:

    - to replace the EEPROM_AckPolling function by a wait loop (length depends on the EEPROM)

    - or try to change the EEPROM_AckPolling function as follow:

    void EEPROM_AckPolling(void)
    // Description:
    //   Acknowledge Polling. The EEPROM will not acknowledge if a write cycle is
    //   in progress. It can be used to determine when a write cycle is completed.
    { unsigned int count;
      while (I2CDCTL&I2CBB); // wait until I2C module has finished all operations
      U0CTL &= ~I2CEN;       // clear I2CEN bit => necessary to re-configure I2C module
      I2CTCTL |= I2CRM;      // transmission is software controlled
      U0CTL |= I2CEN;        // enable I2C module
      I2CIFG = NACKIFG;      // set NACKIFG
      while (NACKIFG & I2CIFG)
      {
        I2CIFG=0x00;            // clear I2C interrupt flags
        U0CTL |= MST;           // define Master Mode
        I2CTCTL |= I2CTRX;      // I2CTRX=1 => Transmit Mode (R/W bit = 0)

        _DINT;   // **** disable interrupts. following code lines should not be interrupted (time critical!!!)

        I2CTCTL |= I2CSTT;      // start condition is generated
        while (I2CTCTL&I2CSTT); // wait till I2CSTT bit was cleared
        I2CTCTL |= I2CSTP;      // stop condition is generated after slave address was sent
                                //      => I2C communication is started

        _EINT;   //**** enable interrupts again

        while (I2CDCTL&I2CBB); // wait till stop bit is reset
      }
      U0CTL &= ~I2CEN;       // clear I2CEN bit => necessary to re-configure I2C module
      I2CTCTL &= ~I2CRM;     // transmission is by the I2C module
      U0CTL |= I2CEN;        // enable I2C module

      return;
    }

  • Oh yes thanks, it is working now. 

    1. But why it is said that the global interrupt should be disabled only when using the  EEPROM_AckPolling function? Why it is not happening in the Read cycle routines or when there is a write routine?
    2. Is it only the timer interrupt or any other interrupt that is making the I2C module to get hanged? I couldn't understand why exactly this is happening.

    Please help me in this regard. Thanks in advance.

**Attention** This is a public forum