nbm 1 Posted December 29, 2020 Share Posted December 29, 2020 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. 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. Quote Link to post Share on other sites
bluehash 1,580 Posted December 29, 2020 Share Posted December 29, 2020 Have you looked at the code samples in CCS? Quote Link to post Share on other sites
nbm 1 Posted December 29, 2020 Author Share Posted December 29, 2020 I haven't looked in CCS specifically, but I have found code samples from TI; the above is the smallest program I could make that seemed like it should work. Quote Link to post Share on other sites
bluehash 1,580 Posted December 29, 2020 Share Posted December 29, 2020 Try to fix the clock line first. Can you make the clock an output and see if the high gets to 3.3V? Quote Link to post Share on other sites
nbm 1 Posted December 29, 2020 Author Share Posted December 29, 2020 When I take the pull ups out of the circuit, I can drive SCK and SDA in a nice square wave between 0 and about 3.2V. Quote Link to post Share on other sites
bluehash 1,580 Posted December 30, 2020 Share Posted December 30, 2020 Hmmm.. Ok, when you do the SCK test(1.8V), do you have the accelerometer connected? Quote Link to post Share on other sites
nbm 1 Posted December 30, 2020 Author Share Posted December 30, 2020 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. Quote Link to post Share on other sites
nbm 1 Posted December 30, 2020 Author Share Posted December 30, 2020 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. Quote Link to post Share on other sites
nbm 1 Posted December 30, 2020 Author Share Posted December 30, 2020 Yep, without the module I get a nice train of NACKs on the address. Looks like the accelerometer is stretching my clock. Quote Link to post Share on other sites
nbm 1 Posted December 30, 2020 Author Share Posted December 30, 2020 I just realized that the red LED on the EXP430G2ET is connected to SCK. That would explain why it's drawing power. Quote Link to post Share on other sites
nbm 1 Posted December 30, 2020 Author Share Posted December 30, 2020 And with J7 removed, everything works just fine. Note to the future: if trying to do I2C on EXP430G2ET, remove J7. It probably says that somewhere in the user guide. bluehash 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.