Tool/software:
Hello Everyone,
I am trying to establish a communication between an I2C based sensor and the MSP430 development board. Please see my code below. The sensor won't send an ACK. I have not changed the clock of the system, using the default 1MHz. And the I2C Comm speed is 100KHz.
As shown in the image, I have connected the 4.7K ohm pull up resistors to I2C lines.
#include "driverlib.h" #include <msp430.h> #include "inc/hw_memmap.h" #include "uart_debug.h" #define BAUD_RATE 115200 //****************************************************************************** //! //! Empty Project that includes driverlib //! //****************************************************************************** //****************************************************************************** //! //! Local Function Prototypes //! //****************************************************************************** static void watchdog_stop (void); static void init_i2c(void); static void check_i2c_slave(void); //****************************************************************************** //! //! Local Variables //! //****************************************************************************** int main (void) { watchdog_stop(); init_debug_uart(); init_i2c(); //check_i2c_slave(); while(1) { debug_print("Debugging Working\n\r"); check_i2c_slave(); __delay_cycles(3000000); //3sn } } //****************************************************************************** //! //! Local Function Definitions //! //****************************************************************************** static void watchdog_stop (void) { WDTCTL = WDTPW + WDTHOLD; } static void init_i2c(void) { GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P4, GPIO_PIN2 | GPIO_PIN1);//P4.1 SDA, P4.2 SCL UCB1CTL1 |= UCSWRST; // Enable SW reset UCB1CTL0 = UCMST + UCMODE_3 + UCSYNC; // Master, I2C, Synchronous mode UCB1CTL1 = UCSSEL_2 + UCSWRST + UCTR; // Use SMCLK, keep SW reset UCB1BR0 = 10; // set prescaler, since SMCLK is 1MHz, /10 will give 100KHz UCB1BR1 = 0; UCB1I2CSA = 0x74; // Set slave address UCB1CTL1 &= ~UCSWRST; // Clear SW reset, resume operation while (UCB1STAT & UCBBUSY); // Wait for the I2C Bus to get free. } static void check_i2c_slave (void) { // Send start condition (this happens when the first byte is sent) UCB1CTL1 |= UCTR + UCTXSTT; // Transmit mode, send start bit while (UCB1CTL1 & UCTXSTT); // Wait for start bit to be transmitted debug_print("Start Bit Transmission Complete\r\n"); // Now, you can send data or address //UCB1TXBUF = (0x74) << 1; // Send slave address with write operation // Wait for data transmission to complete while (UCB1CTL1 & UCTXSTT); // Wait for start condition to be sent debug_print("Data Transmission Complete\r\n"); // For now, let's just stop the transmission. UCB1CTL1 |= UCTXSTP; // Send stop condition // Wait for stop condition while (UCB1CTL1 & UCTXSTP); debug_print("Stop Bit Transmission Complete\r\n"); }