Part Number: LAUNCHXL-CC2640R2
Tool/software: TI-RTOS
Hello,
I have seen several responses to people using the 'i2ctmp007' project as a base. I am currently struggling to get a ST-Micro LIS3DH accelerometer to connect to my LaunchXL-CC2640R2 board. Before I post my code I have a few basic questions:
1 - I haven't seen anywhere how to configure the device registers, i.e., even for the original 'i2ctmp007' project/code, for the TMP007 sensor I didn't see any code to set-up the device. Is it just assumed that the defaults will suffice, or, are these, i.e., registers being set somewhere else ? Even if the registers are being set somewhere else, what is the correct method ? For transmit, I send, of course, the board address as part of the ' i2cTransaction.slaveAddress'. Then, I put the device register I'm trying to set-up in one buffer location, and the value to write to the register in a second buffer location. For 'reads', I just send the 'slaveAddress', then the register to be read from in a buffer location. For transmit, I have tried to implement two 'empty' loops to send these values to the registers. I am getting the 'I2C Initialized' message. I also get the "I2C closed!\n" message (not shown in the code below). However, none of the code related to the accel/registers seems to be doing anything.
Need help, please.
Thanks,
J.
My modifications to the 'i2ctmp007' code follows (not including the various new 'defines', ....)
uint8_t txBuffer[10];
uint8_t rxBuffer[10];
uint8_t Accel_X;
I2C_Handle i2c;
I2C_Params i2cParams;
I2C_Transaction i2cTransaction;
/* Call driver init functions */
Display_init();
GPIO_init();
I2C_init();
/* Open the HOST display for output */
display = Display_open(Display_Type_UART, NULL);
if (display == NULL) {
while (1);
}
/* Turn on user LED */
GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);
Display_printf(display, 0, 0, "Starting the i2ctmp007 example\n");
/* Create I2C for usage */
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_400kHz;
i2c = I2C_open(Board_I2C_TMP, &i2cParams);
if (i2c == NULL) {
Display_printf(display, 0, 0, "Error Initializing I2C\n");
while (1);
}
else {
Display_printf(display, 0, 0, "I2C Initialized!\n");
}
//------------------ ALL OF THE ABOVE WORKS !!!!! -----------------------
//=======================================================================
//----- Init the LIS3DH Accel
// Init CNTRL_REG0....
txBuffer[0] = CTRL_REG0;/* CTRL_REG0 Address 0x1E */
txBuffer[1] = 0x10; /* Value to write to 'CNTRL_REG0', i.e., Enable the LIS3DH */
txBuffer[2] = 0x00; /* Do not auto-increment register address */
i2cTransaction.slaveAddress = Board_TMP_ADDR; // 0x18
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 3;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 0;
if (I2C_transfer(i2c, &i2cTransaction)) {
}
// Init CNTRL_REG1....
txBuffer[0] = CTRL_REG1;
txBuffer[1] = 0x27;
txBuffer[2] = 0x00; /* Do not auto-increment register address */
i2cTransaction.slaveAddress = Board_TMP_ADDR; //0x18
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 3;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 0;
if (I2C_transfer(i2c, &i2cTransaction)) {
}
/* NOTE: May have to initialize other CTRL registers */
//====================================================================
// Set-up ADC read
txBuffer[0] = OUT_X_L; // Output register for the X-axis lower byte, JUST TO TRY
i2cTransaction.slaveAddress = Board_TMP_ADDR; //0x18
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 1;
i = 1; // just to temporarily make the next lines happy (have removed loop)
if (I2C_transfer(i2c, &i2cTransaction)) {
Accel_X = rxBuffer[0];
Display_printf(display, 0, 0, "Getting Accel Data !\n");
Display_printf(display, 0, 0, "Sample %u: %d (C)\n", i, Accel_X);
}
//==================================================================================
