Jump to content
43oh

I2C Clock driven to 1.8V, bus seems borked


Recommended Posts

I've got a pretty simple project, connecting an LIS3DH accelerometer to an MSP430G2553 (using MSP-EXP430G2ET). 

Here's the code:

#include <stdint.h>
#include <msp430.h>

#define SLAVE_ADDR 0x19

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

    __disable_interrupt(); // Just polling for now

    // Set to 1 MHz operation
    BCSCTL1 = CALBC1_1MHZ;
    DCOCTL = CALDCO_1MHZ;
    
    // Configure P1.6 and P1.7 as I2C SCL and SDA respectively
    P1SEL = 0xc0;
    P1SEL2 = 0xc0;

    // This byte is signed for some reason. P1.3 is the button input.
    P1DIR = ~(int8_t)(BIT6 | BIT7 | BIT3);
    P1OUT = 0;

    // Initialize I2C subsystem
    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; // 1 MHz / 10 = 100 kHz
    UCB0BR1 = 0;
    UCB0I2CSA = SLAVE_ADDR;
    UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
    IE2 &= ~(UCB0RXIE + UCB0TXIE); // Disable RX and TX interrupt

    while (1)
    {
        while (UCB0CTL1 & UCTXSTP); // Wait for stop
        UCB0CTL1 |= UCTXSTT; // Gen start
        while (UCB0CTL1 & UCTXSTT); // Wait until addr clocked out
        UCB0CTL1 |= UCTXSTP; // Gen stop
    }
}

I just have the SCL and SDA pins, as well as 3.3V and ground connected to a SparkFun LIS3DH breakout board. My logic analyzer shows a start condition (SDA high->low while SCK high) followed by a single clock pulse (it stays low for about 5μs; half a cycle at 100 kHz) and then it just freezes there. The data line stays pulled low forever while the clock stays high forever.

However, the clock line's high is about 1.8V even though it's being pulled up to 3.3V (if I disconnect the MSP430, it goes up to 3.3). The data line is a touch under 3.3V when high.

Here's a screen capture from my logic analyzer.1_8v.thumb.png.010515cb733dec380da6387f0cd2cfb2.png

If the pin is open drain, I don't see how it drives it to 1.8V. Am I missing something in my setup code? Further, even with the weird 1.8V output, I would expect the above code to at least clock out the address, read bit, and ACK/NACK. I'd expect that even with the accelerometer disconnected.

So I tried disconnecting the accelerometer entirely, and adding some external pull ups on SDA and SCL, and I see basically the same thing, though my pull ups are larger so I see 1.6V on the clock line. SDA is spot on at 3.3V.

Link to post
Share on other sites

I've tried with and without. The only difference is the exact voltage (and size of pull up resistor). That makes me suspect it's sinking a lot of current through the SCK pin. With the 4.7k pull ups on the breakout board, that's about 300μA through the pin. I just tried it again with 100k pull ups, and it went to 2.3V. That's about 1μA.

Link to post
Share on other sites

Alright, this is weird. After having P1.6 and P1.7 configured as outputs, if I program it with the code I posted I get the results I expect. However, as soon as I power cycle the system, it:

  • pulls SCK and SDA low
  • waits 282 ms
  • then both go high for a quarter of a millisecond
  • SDA goes low while SCK is high (start condition)
  • SCK pulses low for 5μs
  • everything stops, with SDA low and SCK high forever

Trying it without the accel module next.

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...