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.

I2C SCL going 200Hz

Other Parts Discussed in Thread: MSP430G2553

Hi,

So I have been trying to get a working I2C interface on my MSP430G2553 and I have recently run into another issue. I now have the right patterns being generated but I kept receiving a NACK from the slave when I realized that my SCL was only clocking at around 100Hz (no I did not mean kHz). I then started to look at the clocking documentation and have set all registers to about as high as the DCO can go. Here is a screen shot of the register values.

As you can see the DCO is set to 3, RSEL is set to 15, all clock dividers are set to 0, and SMCLK is set to the DCO. I was unable to capture it in the screenshot but my I2C interface is set to use SMCLK as its source and the prescalar is set to 0. When I do this my SCL clocks in the 200Hz range (I am no longer in the lab so I have forgot the exact number). I am assuming this low frequency clock is the reason that I keep getting a NACK from the slave but I have not idea what the problem is. My initializations code is:

void Initialize_I2C()
{
    //Set up UC Module as I2C Master
    DISABLE_I2C;                                // Enable SW RESET
    UCB0CTL0 = (UCMST + UCMODE_3 + UCSYNC);        // Setup UC Modules as I2C 7 bit addressing and as a Master
    UCB0CTL1 = (UCSSEL_2 + UCSWRST);             // Setup I2C module with SMCLK
    UCB0BR0 = 0;                                // Set Prescalar value
    UCB0BR1 = 0;

    //Interrupts
    UCB0I2CIE = UCNACKIE;                        // Enable NACK interrupt
    IE2 |= UCB0TXIE + UCB0RXIE;                    // Enable TX and RX interrupts

    ENABLE_I2C;                                    // Disable SW Reset
}

In the register screenshot above I also added this line of code to try to increase the DCO

    BCSCTL1 |= RSEL3;

Thanks for everyone's help.

  • William,

    Have you measured MCLK and SMCLK to determine what that actual clock frequencies are?  My suspicion is that your clocks are not running that the expected frequencies.

    You can use the pre-calibrated DCO constants in flash to select a predetermined frequency for MCLK, then you have an accurate clock to generate your I2C clock signal from.

    A better solution is to use Grace.  With Grace, you can you configure the MCLK frequency from a drop down list, then very easily set up your I2C to the specified frequency.  I highly recommend you give Grace a try, it solves these types of issues and is VERY easy to use.

    Grace should be included in all the latest versions of CCS, so you shouldn't have to download and install it separately.  The User's Guide section of the Grace link above provides a good getting started guide.

    Mike

  • Mike,

    Unfortunately I do not have grace installed on my computer. Also I have routed SMCLK to P1.4 on the microcontroller and have measured the frequency of the output. I get exactly what I expect. With DCO set at (15,3) I get SMCLK at 14MHz and with DCO set as the default (7,3) I get 1.1MHz which means that my SMCLK is clocking at the proper frequency.  My UCB0BR0 and UCB0BR1 registers are both set to 0x00 so there should be no clock division and my UCB0CTL1 register has the UCSSEL0 bits set to 10 which is SMCLK. I have also tried setting the UCSSEL0 bits to 11 which is also SMCLK and have the exact same problem. When I have SMCLK set at 1.1MHZ my SCL frequency is 17.07 Hz and when SMCLK is set at 14MHz my SCL frequency is 219.8 Hz. this is consistent with the change in SMCLK since they are both in about a 12:1 ratio.

  • William,

    What version of CCS are you using?

    Try setting a clock divider with the UCB0BRn registers.  The G2553 supports I2C Fast mode up to 400KHz.  If you don't have any divider from the BRn registers, with a 1.1MHz or 14MHz SMCLK, that is clearly WAY too fast.  Also, section 17.3.5 of the User's Guide says the maximum bit clock is Fbrclk/4 (if not multimaster), again indicating you are trying to run it too fast.

    Try setting the UCB0BR to 0x64, which should give you a I2C clock of 11KHz with a 1.1MHz SMCLK, or 140KHz with a 14MHz SMCLK.

    Mike

  • Thank you I never thought that my clock going too fast would be the issue to my clock going too slow. MSP430 is new to me so I am still learning. That fixed the problem though.

  • William Hodges said:
    I never thought that my clock going too fast would be the issue to my clock going too slow.

    Possibly a state machine aliasing effect. The state machine is missing most of the clock pulses because the duty cycle is too short.
    Like what you see when you watch a video recording of a rotating wheel. If the wheel rotates half as fast as the video framerate, it suddenly seems to rotate backwards. If goes even faster, the backwards movement slows down and when it rotates as fast as the video framerate it seems to stop, then begins slowly moving forward again and so on.

**Attention** This is a public forum