1
\$\begingroup\$

I am having difficulty getting I2C communication going on the MSP430g2553. After working on this for a couple of days I finally stripped down the code to what I thought should be the bare bones needed just to send the start pattern and the slave address, but even that does not seem to work.

I have an oscilloscope hooked up to pins 1.6 and 1.7 but haven't been able to capture anything at all. In addition, I turn on an LED while the start pattern has not been sent and attempt to turn it off afterwards, but it never turns off.

Here is stripped down code. Can anyone throw some light on this?

#include <legacymsp430.h>
#include <msp430g2553.h>

int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  // Set up the DCO
  BCSCTL1 = CALBC1_1MHZ;
  DCOCTL = CALDCO_1MHZ;

  P1SEL |= BIT6 + BIT7;                   // Assign I2C pins to USCI_B0
  P1SEL2|= BIT6 + BIT7;                   // Assign I2C pins to USCI_B0
  P1REN |= BIT6 + BIT7;

  P1DIR |= 0x01;                          // For the LED
  P1OUT &= ~BIT0;                         // Make sure it's off

  UCB0CTL1 |= UCSWRST;                    // Enable SW reset
  UCB0CTL0 |= UCMST + UCMODE_3 + UCSYNC;  // I2C Master, synchronous mode
  UCB0CTL1 |= UCSSEL_2 + UCSWRST;         // Use SMCLK, keep SW reset
  UCB0BR0 = 10;                           // SMCLK/10
  UCB0BR1 = 0;
  UCB0I2COA = 0;                          // Master own address
  UCB0CTL1 &= ~UCSWRST;                   // Clear SW reset, resume operation

  UCB0I2CSA = 0x78;                       // Slave Address
  UCB0CTL1 |= UCTXSTT;                    // Send start and slave address
  while(UCB0CTL1 & UCTXSTT){
    P1OUT |= BIT0;                        // Turn on the LED while the start has not been sent.
  }

  P1OUT &= ~BIT0;  // This never gets executed.

  LPM0;

  return 0;
}
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

The I²C data/clock lines require pull-up resistors. Setting the P1REN bits without setting the corresponding P1OUT bits is likely to result in pull-down resistors.

Furthermore, the pull-up resistors must be strong enough to overcome the parasitic capacitances of your circuit fast enough; a typical value for 100 kHz is 10 kΩ. The G2553's built-in resistors can have up to 50 kΩ, so it would be a better idea to use external resistors, or to reduce the clock frequency.

\$\endgroup\$
2
  • \$\begingroup\$ Well, that was it. Thank you! Using external 10K resistors worked even though the internal resistors were previously pulling the pins high. Also, it's not clear to me why the LED would stay lit. Is the hardware doing more than just pulsing the pins? Does it sense whether or not it was able to pull the line low? \$\endgroup\$
    – HeadCode
    Jan 3, 2016 at 18:22
  • \$\begingroup\$ Slow devices can slow down the master with clock stretching (pulling the clock line low). \$\endgroup\$
    – CL.
    Jan 3, 2016 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.