Other Parts Discussed in Thread: TMP100
Please provide the code for interfacing LSM6DS33 with my MSP430G2553. I am not having sufficient back up for the same
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.
Please provide the code for interfacing LSM6DS33 with my MSP430G2553. I am not having sufficient back up for the same
Hi Jayakrishnan,
To my knowledge we don't have any official examples for the MSPM0G2553 and LSM6DS33 specifically, but it appears that device can be controlled via I2C or SPI.
We have an example using the MSP430G2553 with the TMP100 here: https://dev.ti.com/tirex/explore/node?node=A__ALJ6CcSCZehPN6QX8ONibw__msp430ware__IOGqZri__LATEST
As well as a standard I2C controller example here: https://dev.ti.com/tirex/explore/node?node=A__ADwdOVnX-fmCfnKgw9hv7Q__msp430ware__IOGqZri__LATEST
If you want to use SPI, you will find a SPI Standard controller example in that same directory on dev.ti.com.
Any of those examples could be modified and used to send and receive data from the LSM6DS33.
Best Regards,
Brandon Fisher
You know, LSM is like a ghost with MSP430. I am getting no samples to look upon it. Please do provide some relevant resources for the same.
At least some code to receive and transmit data from the LSM will do
#include <msp430g2553.h>
unsigned char RX_Data[6];
unsigned char TX_Data[2];
unsigned char RX_ByteCtr;
unsigned char TX_ByteCtr;
int xAccel;
int yAccel;
int zAccel;
unsigned char slaveAddress = 0x6A;
const unsigned char CTRL9_XL = 0x38; // Accelerometer X, Y, Z axes enabled
const unsigned char CTRL1_XL = 0x60; // Accelerometer = 416Hz (High-Performance mode)
const unsigned char INT1_CTRL = 0x01; // Accelerometer Data Ready interrupt on INT1
void i2c_start(void);
void i2c_write(unsigned char);
void i2c_read(unsigned char);
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stopping WDT
/*---------------------*/
UCB0CTL0 |= UCSSEL_3; // chooses SMCLK
UCB0RW = 10; // sets prescalar = 10
UCB0CTL0 |= ucmode_3; // puts into I2C mode
UCB0CTL0 |= UCMST; // puts into master mode
UCB0CTL0 &= ~UCTR; // puts into RX mode (read)
UCB0I2CSA = 0X6A; // slave address
UCBOCTL1 = UCASTP_2
// Set clock speed (default = 1 MHz)
BCSCTL1 = CALBC1_1MHZ; // Basic Clock System CTL (1,8,12 16_MHZ available)
DCOCTL = CALDCO_1MHZ; // Digitally-Controlled Oscillator CTL
// Setting I2C pins
P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0
P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0
// Initialize the I2C state machine
i2c_start();
while (1)
{
slaveAddress = 0x6A; // slave address
TX_Data[0] = ;
TX_ByteCtr = 1;
i2c_write(slaveAddress);
// Read the two bytes of data and store them in zAccel
slaveAddress = 0x6A; // address
RX_ByteCtr = 6;
i2c_read(slaveAddress);
xAccel = RX_Data[5] << 8; // MSB
xAccel |= RX_Data[4]; // LSB
yAccel = RX_Data[3] << 8; // MSB
yAccel |= RX_Data[2]; // LSB
zAccel = RX_Data[1] << 8; // MSB
zAccel |= RX_Data[0]; // LSB
//print data
__no_operation(); // Set breakpoint >>here<< and read
}
}
void i2c_start(void)
{
// set up I2C module
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; // fSCL = SMCLK/40 = ~400kHz
UCB0BR1 = 0;
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
}
void i2c_write(unsigned char slaveAddress)
{
__disable_interrupt();
UCB0I2CSA = slaveAddress; // Load slave address
IE2 |= UCB0TXIE; // Enable TX interrupt
while(UCB0CTL1 & UCTXSTP); // Ensure stop condition sent
UCB0CTL1 |= UCTR + UCTXSTT; // TX mode and START condition
__bis_SR_register(CPUOFF + GIE); // sleep until UCB0TXIFG is set ...
}
void i2c_read(unsigned char address)
{
__disable_interrupt();
UCB0I2CSA = address; // Load slave address
IE2 |= UCB0RXIE; // Enable RX interrupt
while(UCB0CTL1 & UCTXSTP); // Ensure stop condition sent
UCB0CTL1 &= ~UCTR; // RX mode
UCB0CTL1 |= UCTXSTT; // Start Condition
__bis_SR_register(CPUOFF + GIE); // sleep until UCB0RXIFG is set ...
}
/***********************************************************************************/
// USCIAB0TX_ISR
#pragma vector = USCIAB0TX_VECTOR
__interrupt void USCIAB0TX_ISR(void)
{
if(UCB0CTL1 & UCTR) // TX mode (UCTR == 1)
{
if (TX_ByteCtr) // TRUE if more bytes remain
{
TX_ByteCtr--; // Decrement TX byte counter
UCB0TXBUF = TX_Data[TX_ByteCtr]; // Load TX buffer
}
else // no more bytes to send
{
UCB0CTL1 |= UCTXSTP; // I2C stop condition
IFG2 &= ~UCB0TXIFG; // Clear USCI_B0 TX int flag
__bic_SR_register_on_exit(CPUOFF); // Exit LPM0
}
}
else // (UCTR == 0) // RX mode
{
RX_ByteCtr--; // Decrement RX byte counter
if (RX_ByteCtr) // RxByteCtr != 0
{
RX_Data[RX_ByteCtr] = UCB0RXBUF; // Get received byte
if (RX_ByteCtr == 1) // Only one byte left?
UCB0CTL1 |= UCTXSTP; // Generate I2C stop condition
}
else // RxByteCtr == 0
{
RX_Data[RX_ByteCtr] = UCB0RXBUF; // Get final received byte
__bic_SR_register_on_exit(CPUOFF); // Exit LPM0
}
}
}I have taken this by integrating several snippets . what should be added and what should be avoided..? Please do complete my code
Hi Jayakrishnan,
It will be easier to narrow down what might be wrong here with the failure symptoms. Have you built this code and tried it with the LSM device? Do you get any build errors? Do you see any traffic at all when the code is run?
I did notice that Line 51 is incomplete: TX_Data[0] = ;
Best Regards,
Brandon Fisher
Please note that I am just starting off with this programming thing and I am having no idea how to properly work with this code. I need to get the accelerometer values from my MSP430g2553 with lsm6ds33 and I think I have done more than 75%. Please help me with completing the code.
Hi Jayakrishnan,
The first step would be to put this into a CCS project for the MSP430G2553, either in standalone code composer studio (https://www.ti.com/tool/CCSTUDIO) or the cloud based code composer studio tool (dev.ti.com/ide).
If you are not familiar at all with I2C you could also take a look at our MSP430 I2C Academy: https://dev.ti.com/tirex/explore/node?node=A__AN8bTD5cSL1aI5MBrThs3A__com.ti.MSP430_ACADEMY__bo90bso__LATEST
Best Regards,
Brandon Fisher
**Attention** This is a public forum