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.

MSP430 Driverlib I2C: Problem Reading Registers

Hello!

I'm trying to read 3 different registers from Accelerometer using I2C.

Here's my initialisation code:

WDT_A_hold(WDT_A_BASE);

	//Set DCO frequency to 1MHz
	CS_setDCOFreq(CS_DCORSEL_0,CS_DCOFSEL_0);
	//Set ACLK = VLO with frequency divider of 1
	CS_initClockSignal(CS_ACLK,CS_VLOCLK_SELECT,CS_CLOCK_DIVIDER_1);
	//Set SMCLK = DCO with frequency divider of 1
	CS_initClockSignal(CS_SMCLK,CS_DCOCLK_SELECT,CS_CLOCK_DIVIDER_1);
	//Set MCLK = DCO with frequency divider of 1
	CS_initClockSignal(CS_MCLK,CS_DCOCLK_SELECT,CS_CLOCK_DIVIDER_1);

	// Configure Pins for I2C
	//Set P1.6 and P1.7 as Secondary Module Function Input.
	/*

	 * Select Port 1
	 * Set Pin 6, 7 to input Secondary Module Function, (UCB0SIMO/UCB0SDA, UCB0SOMI/UCB0SCL).
	 */
	GPIO_setAsPeripheralModuleFunctionInputPin(
			GPIO_PORT_P1,
			GPIO_PIN6 + GPIO_PIN7,
			GPIO_SECONDARY_MODULE_FUNCTION
	);

	/*
	 * Disable the GPIO power-on default high-impedance mode to activate
	 * previously configured port settings
	 */
	PMM_unlockLPM5();

	EUSCI_B_I2C_initMasterParam param = {0};
	param.selectClockSource = EUSCI_B_I2C_CLOCKSOURCE_SMCLK;
	param.i2cClk = CS_getSMCLK();
	param.dataRate = EUSCI_B_I2C_SET_DATA_RATE_100KBPS;
	param.byteCounterThreshold = 0;
	param.autoSTOPGeneration = EUSCI_B_I2C_NO_AUTO_STOP;
	EUSCI_B_I2C_initMaster(EUSCI_B0_BASE, &param);

	//Specify slave address
	EUSCI_B_I2C_setSlaveAddress(EUSCI_B0_BASE, SLAVE_ADDRESS);

	//Set Master in receive mode
	EUSCI_B_I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_MODE);

	//Enable I2C Module to start operations
	EUSCI_B_I2C_enable(EUSCI_B0_BASE);

	EUSCI_B_I2C_clearInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_NAK_INTERRUPT);
	//Enable master Receive interrupt
	EUSCI_B_I2C_enableInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_NAK_INTERRUPT);

I'm successful in writing values to the registers. I can see the correct signals in Oscilloscope.

However, when I try reading register that has Acceleration along X, Y, Z axis, I'm getting only Acceleration along Z-Axis. Here's the code for receiving part:

                EUSCI_B_I2C_masterSendMultiByteStart(EUSCI_B0_BASE, 0x01);

		while(EUSCI_B_I2C_masterIsStartSent(EUSCI_B0_BASE) == EUSCI_B_I2C_SENDING_START);

		EUSCI_B_I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_RECEIVE_MODE);

		EUSCI_B_I2C_clearInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_RECEIVE_INTERRUPT0+ EUSCI_B_I2C_TRANSMIT_INTERRUPT0);

		EUSCI_B_I2C_enableInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_RECEIVE_INTERRUPT0);

		EUSCI_B_I2C_masterReceiveStart(EUSCI_B0_BASE);

		while(EUSCI_B_I2C_masterIsStopSent(EUSCI_B0_BASE) == EUSCI_B_I2C_SENDING_STOP);
		ZAcceleration = RXData/21.0;

		__bis_SR_register(GIE);    // Enable interrupts



#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_B0_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(USCI_B0_VECTOR)))
#endif
void USCIB0_ISR(void)
{
	static uint8_t count = 0;

	switch(__even_in_range(UCB0IV,0x1E))
	{
	case 0x00: break;                                // Vector 0: No interrupts break;
	case 0x02: break;
	case 0x04:
		//resend start if NACK
//		EUSCI_B_I2C_masterSendStart(EUSCI_B0_BASE);
		break;                                // Vector 4: NACKIFG break;
	case 0x16:
		RXData = EUSCI_B_I2C_masterReceiveSingle(EUSCI_B0_BASE);                           // Get RX data
		if(++count > 1)
		{
			count = 0;
			EUSCI_B_I2C_masterReceiveMultiByteStop(EUSCI_B0_BASE);
		}
		__no_operation();
		break;     // Vector 24: RXIFG0 break;
	case 0x18:
		if(TXByteCtr)                         // Check TX byte counter
		{
			EUSCI_B_I2C_masterSendMultiByteNext(EUSCI_B0_BASE, *(++dataPointer));
			TXByteCtr--;                        // Decrement TX byte counter
		}
		else
		{
			EUSCI_B_I2C_masterSendMultiByteStop(EUSCI_B0_BASE);
			__no_operation();
		}
		break;                                // Vector 26: TXIFG0 break;
	default: break;
	}
}

No matter what register I point with EUSCI_B_I2C_masterSendMultiByteStart(EUSCI_B0_BASE, 0x01); function, I'm getting data from 0x02 register. I see the values changing in Oscilloscope but can't get correct data back from Accelerometer.( 0x01 Register holds acceleration along Y-Axis)

Please help me solve this problem.

Best

Teja

  • What is that 0x01 that you send? The first register address?

    You are using a single variable, RXData. How do you expect it to contain three values?

  • Hello,

    Thanks for the reply.

    1. Yes. 0x01 is the register address.

    2. Right now, I'm testing if I can read contents from the register.

    According to MMA7660FC datasheet(www.freescale.com.cn/.../MMA7660FC.pdf, 0x00 register contains acceleration along X-Axis, 0x01 register, Y-Axis acceleration and 0x02 register contains Acceleration along Z-Axis. So, if I pass 0x00 in

    EUSCI_B_I2C_masterSendMultiByteStart(EUSCI_B0_BASE, 0x00);

    while(EUSCI_B_I2C_masterIsStartSent(EUSCI_B0_BASE) == EUSCI_B_I2C_SENDING_START);

    I should be getting Acceleration along X-Axis. And 0x01 should give Y-Axis acceleration. But, I cannot receive either X or Y Acceleration data.


    Passing 0x01 as parameter, gives me acceleration along Z-Axis. Thats where I got stuck.
  • The interrupt handler reads two bytes, so at the end, the second one is in RXData.
    "++count>1" is true only when count is two.
  • Thanks for the reply. I changed it to "++count >= 1" But still can't read 0x00 and 0x01 registers.

    Incase if it helps, here's my full code. I can't figure out what's the problem. Can you please help me find it?

    #include "driverlib/MSP430FR5xx_6xx/driverlib.h"
    #include "stdbool.h"
    
    //*****************************************************************************
    
    #define SLAVE_ADDRESS 0x4C
    #define MMA7660_X     						   0x00
    #define MMA7660_Y     						   0x01
    #define MMA7660_Z    	 					   0x02
    #define MMA7660_TILT 	 					   0x03
    #define MMA7660_SRST  						   0x04
    #define MMA7660_SPCNT 						   0x05
    #define MMA7660_INTSU 						   0x06
    #define MMA7660_MODE  						   0x07
    #define MMA7660_STAND_BY 					   0x00
    #define MMA7660_ACTIVE   					   0x01
    #define MMA7660_SR    						   0x08      //sample rate register
    #define AUTO_SLEEP_120  					   0X00		 //120 sample per second
    #define AUTO_SLEEP_64   					   0X01
    #define AUTO_SLEEP_32      					   0X02
    #define AUTO_SLEEP_16   					   0X03
    #define AUTO_SLEEP_8  					   	   0X04
    #define AUTO_SLEEP_4    					   0X05
    #define AUTO_SLEEP_2    					   0X06
    #define AUTO_SLEEP_1    					   0X07
    #define MMA7660_PDET  					   	   0x09
    #define MMA7660_PD    						   0x0A
    
    #define RXCOUNT 							   1
    
    uint8_t TXData = 0;                    // Pointer to TX data
    uint8_t TXByteCtr, RXByteCtr;
    
    int *dataPointer;
    int txBuffer[5];
    int *rxDataPointer;
    int rxBuffer[5];
    bool sendingFlag;
    uint8_t RXData;
    
    float ZAcceleration;
    
    void main(void)
    {
    	WDT_A_hold(WDT_A_BASE);
    
    	//Set DCO frequency to 1MHz
    	CS_setDCOFreq(CS_DCORSEL_0,CS_DCOFSEL_0);
    	//Set ACLK = VLO with frequency divider of 1
    	CS_initClockSignal(CS_ACLK,CS_VLOCLK_SELECT,CS_CLOCK_DIVIDER_1);
    	//Set SMCLK = DCO with frequency divider of 1
    	CS_initClockSignal(CS_SMCLK,CS_DCOCLK_SELECT,CS_CLOCK_DIVIDER_1);
    	//Set MCLK = DCO with frequency divider of 1
    	CS_initClockSignal(CS_MCLK,CS_DCOCLK_SELECT,CS_CLOCK_DIVIDER_1);
    
    	// Configure Pins for I2C
    	//Set P1.6 and P1.7 as Secondary Module Function Input.
    	/*
    
    	 * Select Port 1
    	 * Set Pin 6, 7 to input Secondary Module Function, (UCB0SIMO/UCB0SDA, UCB0SOMI/UCB0SCL).
    	 */
    	GPIO_setAsPeripheralModuleFunctionInputPin(
    			GPIO_PORT_P1,
    			GPIO_PIN6 + GPIO_PIN7,
    			GPIO_SECONDARY_MODULE_FUNCTION
    	);
    
    	/*
    	 * Disable the GPIO power-on default high-impedance mode to activate
    	 * previously configured port settings
    	 */
    	PMM_unlockLPM5();
    
    	EUSCI_B_I2C_initMasterParam param = {0};
    	param.selectClockSource = EUSCI_B_I2C_CLOCKSOURCE_SMCLK;
    	param.i2cClk = CS_getSMCLK();
    	param.dataRate = EUSCI_B_I2C_SET_DATA_RATE_100KBPS;
    	param.byteCounterThreshold = 0;
    	param.autoSTOPGeneration = EUSCI_B_I2C_NO_AUTO_STOP;
    	EUSCI_B_I2C_initMaster(EUSCI_B0_BASE, &param);
    
    	//Specify slave address
    	EUSCI_B_I2C_setSlaveAddress(EUSCI_B0_BASE, SLAVE_ADDRESS);
    
    	//Set Master in receive mode
    	EUSCI_B_I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_MODE);
    
    	//Enable I2C Module to start operations
    	EUSCI_B_I2C_enable(EUSCI_B0_BASE);
    
    	EUSCI_B_I2C_clearInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_NAK_INTERRUPT);
    	//Enable master Receive interrupt
    	EUSCI_B_I2C_enableInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_NAK_INTERRUPT);
    
    
    	while(1)
    	{
    
    		while(EUSCI_B_I2C_isBusBusy(EUSCI_B0_BASE) == EUSCI_B_I2C_BUS_BUSY);
    
    		txBuffer[0] = MMA7660_MODE;
    		txBuffer[1] = MMA7660_STAND_BY;
    		sendingFlag = true;
    		TXByteCtr = 1;                      // Load TX byte counter
    		dataPointer = &txBuffer[0];
    
    		EUSCI_B_I2C_masterSendMultiByteStart(EUSCI_B0_BASE, *dataPointer);
    
    		while(EUSCI_B_I2C_SENDING_STOP == EUSCI_B_I2C_masterIsStopSent(EUSCI_B0_BASE));
    
    		txBuffer[0] = MMA7660_SR;
    		txBuffer[1] = AUTO_SLEEP_120;
    		sendingFlag = true;
    		TXByteCtr = 1;                      // Load TX byte counter
    		dataPointer = &txBuffer[0];
    
    		EUSCI_B_I2C_masterSendMultiByteStart(EUSCI_B0_BASE, *dataPointer);
    
    		while(EUSCI_B_I2C_SENDING_STOP == EUSCI_B_I2C_masterIsStopSent(EUSCI_B0_BASE));
    
    		txBuffer[0] = MMA7660_MODE;
    		txBuffer[1] = MMA7660_ACTIVE;
    		sendingFlag = true;
    		TXByteCtr = 1;                      // Load TX byte counter
    		dataPointer = &txBuffer[0];
    
    		EUSCI_B_I2C_masterSendMultiByteStart(EUSCI_B0_BASE, *dataPointer);
    
    		while(EUSCI_B_I2C_SENDING_STOP == EUSCI_B_I2C_masterIsStopSent(EUSCI_B0_BASE));
    
    		EUSCI_B_I2C_masterSendMultiByteStart(EUSCI_B0_BASE, 0x01);
    
    		while(EUSCI_B_I2C_masterIsStartSent(EUSCI_B0_BASE) == EUSCI_B_I2C_SENDING_START);
    
    		//		EUSCI_B_I2C_disable(EUSCI_B0_BASE);
    		//
    		//		//Set Master in receive mode
    		EUSCI_B_I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_RECEIVE_MODE);
    		//
    		//		//Enable I2C Module to start operations
    		//		EUSCI_B_I2C_enable(EUSCI_B0_BASE);
    
    		EUSCI_B_I2C_clearInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_RECEIVE_INTERRUPT0+ EUSCI_B_I2C_TRANSMIT_INTERRUPT0);
    		//Enable master Receive interrupt
    		EUSCI_B_I2C_enableInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_RECEIVE_INTERRUPT0);
    
    		//		EUSCI_B_I2C_masterReceiveStart(EUSCI_B0_BASE);
    
    		//		RXData = EUSCI_B_I2C_masterReceiveSingle(EUSCI_B0_BASE);
    
    		EUSCI_B_I2C_masterReceiveStart(EUSCI_B0_BASE);
    
    		ZAcceleration = RXData/21.0;
    
    		__bis_SR_register(GIE);    // Enable interrupts
    	}
    }
    
    //------------------------------------------------------------------------------
    // The USCIAB0TX_ISR is structured such that it can be used to transmit any
    // number of bytes by pre-loading TXByteCtr with the byte count. Also, TXData
    // points to the next byte to transmit.
    //------------------------------------------------------------------------------
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=USCI_B0_VECTOR
    __interrupt
    #elif defined(__GNUC__)
    __attribute__((interrupt(USCI_B0_VECTOR)))
    #endif
    void USCIB0_ISR(void)
    {
    	static uint8_t count = 0;
    
    	switch(__even_in_range(UCB0IV,0x1E))
    	{
    	case 0x00: break;                                // Vector 0: No interrupts break;
    	case 0x02: break;
    	case 0x04:
    		//resend start if NACK
    		EUSCI_B_I2C_masterSendStart(EUSCI_B0_BASE);
    		break;                                // Vector 4: NACKIFG break;
    	case 0x16:
    		RXData = EUSCI_B_I2C_masterReceiveSingle(EUSCI_B0_BASE);                           // Get RX data
    		RXData = (RXData << 2)/4;
    		if(++count >= RXCOUNT)
    		{
    			count = 0;
    			EUSCI_B_I2C_masterReceiveMultiByteStop(EUSCI_B0_BASE);
    		}
    		break;     // Vector 24: RXIFG0 break;
    	case 0x18:
    		if(TXByteCtr)                         // Check TX byte counter
    		{
    			EUSCI_B_I2C_masterSendMultiByteNext(EUSCI_B0_BASE, *(++dataPointer));
    			TXByteCtr--;                        // Decrement TX byte counter
    		}
    		else
    		{
    			EUSCI_B_I2C_masterSendMultiByteStop(EUSCI_B0_BASE);
    			__no_operation();
    		}
    		break;                                // Vector 26: TXIFG0 break;
    	default: break;
    	}
    }

  • Don't just say "can't read". What is the problem now?
  • Clemens,

    Code's entering RxISR thrice. And on 3rd time, I'm getting Z-Acceleration.(First two values are 0's) That'll happen only if I point 0x01 register. But sensor should've given Y-Axis Acceleration if I point 0x01.

    When I change the register to 0x00 or 0x02, I get all 0's no matter what the tilt of the sensor is.
  • What happens on the I²C bus?
  • I see 0x98(Write address for sensor) and Reply from Sensor(0x99 + Data) -> 0x99 - 0x02 0x02
  • Please show all bytes, and the start/stop/ack/nack bits.
  • Clemens,

    Thanks for the help. I'm here with an update.

    The three register values that I'm getting turns out to be X, Y andZ accelerations. So, we're getting what we want.

    But there's one small problem. I'm getting the values only if I comment out the Tx Part(i.e., writing into 0x07 and 0x08 registers).

    If I don't comment that part, I'm only getting Z-Acceleration. So, there's little problem with Tx part. Do you find any issue there?
  • What happens on the I²C bus with the TX part? (And a screenshot of the logic analyzer would be more helpful.)
  • Sadly, our Logic Analyzer isn't working from a couple of days. I can give you output from Oscilloscope. But it'd be difficult for you to differentiate.

    Anyways, I got the sensor working. Here's the working code:

    #include "driverlib/MSP430FR5xx_6xx/driverlib.h"
    #include "stdbool.h"
    
    //*****************************************************************************
    
    #define SLAVE_ADDRESS 0x4C
    #define MMA7660_X     						   0x00
    #define MMA7660_Y     						   0x01
    #define MMA7660_Z    	 					   0x02
    
    #define MMA7660_MODE  						   0x07
    #define MMA7660_STAND_BY 					   0x00
    #define MMA7660_ACTIVE   					   0x01
    #define MMA7660_SR    						   0x08      								//sample rate register
    #define AUTO_SLEEP_120  					   0X00										//120 sample per second
    #define AUTO_SLEEP_64   					   0X01
    #define AUTO_SLEEP_32      					   0X02
    #define AUTO_SLEEP_16   					   0X03
    #define AUTO_SLEEP_8  					   	   0X04
    #define AUTO_SLEEP_4    					   0X05
    #define AUTO_SLEEP_2    					   0X06
    #define AUTO_SLEEP_1    					   0X07
    
    #define RXCOUNT 							   1
    
    uint8_t TXByteCtr;							   											//To limit #bytes to be transmitted
    uint8_t txBuffer[5], RXBuffer[3];
    uint8_t *dataPointer;						   											//Pointer for TxBuffer
    uint8_t RXCount;
    
    float XAcceleration, YAcceleration, ZAcceleration;
    
    void main(void)
    {
    	WDT_A_hold(WDT_A_BASE);
    
    	//Set DCO frequency to 1MHz
    	CS_setDCOFreq(CS_DCORSEL_0,CS_DCOFSEL_0);
    	//Set ACLK = VLO with frequency divider of 1
    	CS_initClockSignal(CS_ACLK,CS_VLOCLK_SELECT,CS_CLOCK_DIVIDER_1);
    	//Set SMCLK = DCO with frequency divider of 1
    	CS_initClockSignal(CS_SMCLK,CS_DCOCLK_SELECT,CS_CLOCK_DIVIDER_1);
    	//Set MCLK = DCO with frequency divider of 1
    	CS_initClockSignal(CS_MCLK,CS_DCOCLK_SELECT,CS_CLOCK_DIVIDER_1);
    
    	// Configure Pins for I2C
    
    	GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN6 + GPIO_PIN7, GPIO_SECONDARY_MODULE_FUNCTION);
    
    	PMM_unlockLPM5();
    
    	EUSCI_B_I2C_initMasterParam param = {0};
    	param.selectClockSource = EUSCI_B_I2C_CLOCKSOURCE_SMCLK;
    	param.i2cClk = CS_getSMCLK();
    	param.dataRate = EUSCI_B_I2C_SET_DATA_RATE_100KBPS;
    	param.byteCounterThreshold = 0;
    	param.autoSTOPGeneration = EUSCI_B_I2C_NO_AUTO_STOP;
    	EUSCI_B_I2C_initMaster(EUSCI_B0_BASE, &param);
    
    	EUSCI_B_I2C_setSlaveAddress(EUSCI_B0_BASE, SLAVE_ADDRESS);
    
    	EUSCI_B_I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_MODE);
    
    	EUSCI_B_I2C_enable(EUSCI_B0_BASE);
    
    	EUSCI_B_I2C_clearInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_NAK_INTERRUPT);
    
    	EUSCI_B_I2C_enableInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_NAK_INTERRUPT);
    
    	/*
    	 * Waiting till bus is free. If you don't wait here, code may stuck in masterSendMultiByeStart.
    	 * Specifically, it'll be stuck waiting for interrupt flag to be set
    	 */
    
    	while(EUSCI_B_I2C_isBusBusy(EUSCI_B0_BASE) == EUSCI_B_I2C_BUS_BUSY);
    
    	/*
    	 * To configure MMA7660, we need to put it in standby mode. Writing 0x00 to 0x07 resister will keep it in standby mode.
    	 */
    
    	txBuffer[0] = MMA7660_MODE;
    	txBuffer[1] = MMA7660_STAND_BY;
    	TXByteCtr = 1;																		//#Bytes you want to send apart from First byte(In this case MMA7660_MODE)
    	dataPointer = &txBuffer[0];
    
    	EUSCI_B_I2C_masterSendMultiByteStart(EUSCI_B0_BASE, *dataPointer);
    
    	while(EUSCI_B_I2C_SENDING_STOP == EUSCI_B_I2C_masterIsStopSent(EUSCI_B0_BASE));
    
    	/*
    	 * 0x08 register is used to configure sampling rate. Choose required sampling rate according to your requirement
    	 */
    
    	txBuffer[0] = MMA7660_SR;
    	txBuffer[1] = AUTO_SLEEP_2;
    	TXByteCtr = 1;																		//#Bytes you want to send apart from First byte(In this case MMA7660_SR)
    	dataPointer = &txBuffer[0];
    
    	EUSCI_B_I2C_masterSendMultiByteStart(EUSCI_B0_BASE, *dataPointer);
    
    	while(EUSCI_B_I2C_SENDING_STOP == EUSCI_B_I2C_masterIsStopSent(EUSCI_B0_BASE));
    
    	/*
    	 * After you're done configuring MMA7660, put it back in Active mode. This can be done by writing 0x01 in 0x07 register.
    	 */
    
    	txBuffer[0] = MMA7660_MODE;
    	txBuffer[1] = MMA7660_ACTIVE;
    	TXByteCtr = 1;																		//#Bytes you want to send apart from First byte(In this case MMA7660_MODE)
    	dataPointer = &txBuffer[0];
    
    	EUSCI_B_I2C_masterSendMultiByteStart(EUSCI_B0_BASE, *dataPointer);
    
    	while(EUSCI_B_I2C_SENDING_STOP == EUSCI_B_I2C_masterIsStopSent(EUSCI_B0_BASE));
    
    	__bis_SR_register(GIE);    // Enable interrupts
    
    	while(1)
    	{
    		EUSCI_B_I2C_masterSendMultiByteStart(EUSCI_B0_BASE, 0x01);						//Don't pass any value other than 0x01. You will not get acceleration values
    
    		while(EUSCI_B_I2C_masterIsStartSent(EUSCI_B0_BASE) == EUSCI_B_I2C_SENDING_START);
    
    		EUSCI_B_I2C_clearInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_RECEIVE_INTERRUPT0+ EUSCI_B_I2C_TRANSMIT_INTERRUPT0);
    
    		EUSCI_B_I2C_enableInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_RECEIVE_INTERRUPT0);
    
    		EUSCI_B_I2C_masterReceiveStart(EUSCI_B0_BASE);
    
    		RXCount = 0;
    
    		__delay_cycles(1000);															//Make sure you've some delay between readings. Without this, you can't get values
    	}
    }
    
    //------------------------------------------------------------------------------
    // The USCIAB0TX_ISR is structured such that it can be used to transmit any
    // number of bytes by pre-loading TXByteCtr with the byte count. Also, TXData
    // points to the next byte to transmit.
    //------------------------------------------------------------------------------
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=USCI_B0_VECTOR
    __interrupt
    #elif defined(__GNUC__)
    __attribute__((interrupt(USCI_B0_VECTOR)))
    #endif
    void USCIB0_ISR(void)
    {
    	static uint8_t count = 0;
    
    	switch(__even_in_range(UCB0IV,0x1E))
    	{
    	case 0x00: break;                                // Vector 0: No interrupts break;
    	case 0x02: break;
    	case 0x04:
    		//resend start if NACK
    		EUSCI_B_I2C_masterSendStart(EUSCI_B0_BASE);
    		break;                                // Vector 4: NACKIFG break;
    	case 0x16:
    		RXBuffer[RXCount++] = EUSCI_B_I2C_masterReceiveSingle(EUSCI_B0_BASE);
    		if(++count >= RXCOUNT)
    		{
    			count = 0;
    			EUSCI_B_I2C_masterReceiveMultiByteStop(EUSCI_B0_BASE);
    		}
    		break;     // Vector 24: RXIFG0 break;
    	case 0x18:
    		if(TXByteCtr)                         // Check TX byte counter
    		{
    			EUSCI_B_I2C_masterSendMultiByteNext(EUSCI_B0_BASE, *(++dataPointer));
    			TXByteCtr--;                        // Decrement TX byte counter
    		}
    		else
    		{
    			EUSCI_B_I2C_masterSendMultiByteStop(EUSCI_B0_BASE);
    			__no_operation();
    		}
    		break;                                // Vector 26: TXIFG0 break;
    	default: break;
    	}
    }
    

    I still can't understand why the sensor is giving 3 bytes of data back. MSP is sensing STOP thrice but sensor is sending 3 bytes of data.

    Anyways, thank you for your help! I've been struggling with this sensor for 5 days.

    Teja

**Attention** This is a public forum