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.

CCS/CC2640R2F: Interfacing AS7262 Spectrometer with CC2640 Launchpad

Part Number: CC2640R2F
Other Parts Discussed in Thread: CC2640, TMP116

Tool/software: Code Composer Studio

Hi,

I have been trying to interface AS7262 Spectrometer module with CC2640R2F Launchpad. It has an I2C interface. I am using i2ctmp116 driver example for interfacing the spectrometer.

I am successful in interfacing it with CC2640 but I am getting 0 as received data from the sensor. I think I am doing something wrong with registers initialization. Below is the data sheet for as7262 and code used by me.

https://cdn.sparkfun.com/assets/f/b/c/c/f/AS7262.pdf

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 */

Display_printf(display, 0, 0, "Starting the i2ctmp116 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");
}

/* Point to the die tempature register and read its 2 bytes */
txBuffer[0] = TMP116_DIE_TEMP;
i2cTransaction.slaveAddress = 0x49;
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 1;


if(I2C_transfer(i2c, &i2cTransaction))
{

while (1)
{
// Read slave I²C status to see if the write buffer is ready.
if ((rxBuffer[0] & I2C_AS72XX_SLAVE_TX_VALID) == 0)
// No inbound TX pending at slave. Okay to write now.
break;
}

}
I2C_close(i2c);


I2C_Params_init(&i2cParams1);
i2cParams1.bitRate = I2C_400kHz;
i2c1 = I2C_open(Board_I2C_TMP, &i2cParams1);

txBuffer1[0] = 0x81;
txBuffer1[1] = 0x01;
i2cTransaction1.slaveAddress = 0x49;
i2cTransaction1.writeBuf = txBuffer1;
i2cTransaction1.writeCount = 2;
i2cTransaction1.readBuf = rxBuffer1;
i2cTransaction1.readCount = 20;

I2C_transfer(i2c1, &i2cTransaction1);

I2C_close(i2c1);

I2C_Params_init(&i2cParams2);
i2cParams2.bitRate = I2C_400kHz;
i2c2 = I2C_open(Board_I2C_TMP, &i2cParams2);

txBuffer2[0] = 0x02;
txBuffer2[1] = 0x28;
//txBuffer2[2] = 0x0;

i2cTransaction2.slaveAddress = 0x49;
i2cTransaction2.writeBuf = txBuffer2;
i2cTransaction2.writeCount = 2;
i2cTransaction2.readBuf = rxBuffer2;
i2cTransaction2.readCount = 20;

/* Take 20 samples and print them out onto the console */

for (sample = 0; sample < 20; sample++) {
if (I2C_transfer(i2c2, &i2cTransaction2)) {

Display_printf(display, 0, 0, "Sample %u: %d ",
sample, rxBuffer2[sample]);
}
else {
Display_printf(display, 0, 0, "I2C Bus fault.");
}

/* Sleep for 1 second */
sleep(1);
}

I2C_close(i2c2);
Display_printf(display, 0, 0, "I2C closed!");

Results:

I2C Initialized!

Sample 0: 0
Sample 1: 0
Sample 2: 0
Sample 3: 0
Sample 4: 0
Sample 5: 0
Sample 6: 0
Sample 7: 0
Sample 8: 0
Sample 9: 0
Sample 10: 0
Sample 11: 0
Sample 12: 0
Sample 13: 0
Sample 14: 114
Sample 15: 64
Sample 16: 0
Sample 17: 0
Sample 18: 0
Sample 19: 0
I2C closed!