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.

Compiler/LAUNCHXL-CC2640R2: SHT31-D Temperature & Humidity Sensor

Part Number: LAUNCHXL-CC2640R2
Other Parts Discussed in Thread: CC2640

Tool/software: TI C/C++ Compiler

Hello, I got the SHT31-D sensor (Humidity & Temperature), I've been working to interface it with the LAUNCHXL-CC2640R2 with no success...

There's a library example for Arduino which works fine. But when trying to port the library to CCS, I simply can't get it working...

The quantity reported by the sensor is always negative (which doesn't make sense).

This is my code:

#define SHT31_SENSOR_ADDR 0x44
#define SHT31_MEAS_HIGHREP 0x2400
#define SHT31_SOFTRESET 0x30A2

void *mainThread(void *arg0) { unsigned int i; float humidity, temp; uint8_t txBuffer[2]; uint8_t rxBuffer[6]; uint16_t ST, SRH; I2C_Handle i2c; I2C_Params i2cParams; I2C_Transaction i2cTransaction; /* Call driver init functions */ Display_init(); GPIO_init(); I2C_init(); /* Configure the LED pin */ GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); /* 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 SHT31-D Sensor (Temp & Humidity)\n"); /* Create I2C for usage */ I2C_Params_init(&i2cParams); i2cParams.bitRate = I2C_100kHz; //400kHz i2c = I2C_open(Board_I2C_TMP, &i2cParams); if (i2c == NULL) { Display_printf(display, 0, 0, "Error Initializing I2C\n"); while (1); //return false; } else { txBuffer[0]=SHT31_SOFTRESET >>8; txBuffer[1]=SHT31_SOFTRESET & 0xFF; i2cTransaction.slaveAddress = SHT31_SENSOR_ADDR; i2cTransaction.writeCount = sizeof(txBuffer); i2cTransaction.writeBuf = txBuffer; sleep(0.5); Display_printf(display, 0, 0, "I2C Initialized!\n"); //return true; } /* Take 20 samples and print them out onto the console */ for (i = 0; i< 20; i++){ txBuffer[0] = SHT31_MEAS_HIGHREP >> 8; //0x2400 txBuffer[1] = SHT31_MEAS_HIGHREP & 0xFF; i2cTransaction.slaveAddress = SHT31_SENSOR_ADDR; i2cTransaction.writeCount = sizeof(txBuffer); i2cTransaction.writeBuf = txBuffer; //Wire.write(SHT31_MEAS_HIGHREP >> 8); i2cTransaction.readCount = sizeof(rxBuffer); i2cTransaction.readBuf = rxBuffer; sleep(0.5); if(I2C_transfer(i2c, &i2cTransaction)){ ST = rxBuffer[0]; ST <<= 8; ST |= rxBuffer[1]; if (rxBuffer[2] != crc8(rxBuffer, 2)) i=20; //return false; SRH = rxBuffer[3]; SRH <<= 8; SRH |= rxBuffer[4]; if (rxBuffer[5] != crc8(rxBuffer+3, 2)) i=20;//return false; double stemp = ST; stemp *= 175; stemp /= 0xffff; stemp = -45 + stemp; Display_printf(display, 0, 0, "Temperature %u *C = %d \n", i, stemp); double shum = SRH; shum *= 100; shum /= 0xFFFF; Display_printf(display, 1, 0, "Humidity %u %%RH = %d \n", i, shum); } else { Display_printf(display, 0, 0, "I2C Bus fault\n"); } /* Sleep for 1 second */ sleep(1); } /* Deinitialized I2C */ I2C_close(i2c); Display_printf(display, 0, 0, "I2C closed!\n"); return (NULL); }

The sensor-board connections:

SCL = DIO04

SDA = DIO05

Thanks for the help!

  • First you should print ST and SRH to make sure you are getting results that make sense.

    If your system uses 32 byte ints, 0xFFFF will turn into -1. Try a "UL" suffix.

    Since you are using doubles, why not just divide by 4294967295.0?
  • it seems that your problem is not related to the CC2640R2 or the I2C interface, but how to convert/interpret the data your are getting from the sensor.
    I would therefore recommend that you contact the sensor manufacturer for support.

    BR

    Siri
  • of course it's a problem with the CC2640R2, because the sensor works perfectly with other platforms.... Siri, such an answer is not what the customers are looking for... we pay for TI products (are not given for free to beg for help...), the least you can do is "try" to help... not just try to wash away your hands... (dissapointing)
  • Thanks Keith... unfortunately the negative quantities are coming from ST and SRH... about the "UL" suffix, don't really get it (sorry for my ignorance)
  • OxFFFF will be interpreted as an int. If ints are 32 bits on the system that will be -1. If you want to have 0xFFFF to be interpreted as an unsigned long, use 0xFFFFUL.

    Could your data be byte reversed? try reversing them to see what happens.
  • I was not my intention to try an easy way out and not give your support. However, from the information you posted, I could not see that this was a CC2640 problem.
    The I2C driver is obviously up and running since you are able to send and receive data from the sensor, making me believe that you did not need help with the I2C driver.
    You only description of the problem is that the SENSOR is reporting negative numbers, and you think that is wrong.
    I am then thinking one out of two:
    1) Either you are not sending the correct information to the sensor over the I2C interface (the sensor provider could verify this if you send them a plot of what you are sending over I2C
    2) You are getting the correct results from the sensor, but are converting them incorrectly
    (also this the sensor provide would be able to help you with)
    If you think that the problem is related to the I2C, what do you think the problem is?
    If you for example know that the some specific data should be sent over I2C but are not able to do so with the CC2640, we can be able to help you send the data you want to send
    Or if you know that you are receiving the correct data, but you are not getting the conversion correct, we could help you with that.
    Just saying that you use a sensor (that is not on our development boards) and then assume that we should be able to tell you why you are reading wrong data from this sensor when this is not a sensor we provide on our HW and have the chance to test, is not possible.
    Please provide me with more information about what you are struggling with, and we will try to help.
    Siri
  • I am closing this due to lack of feedback. Once more information is posted, it will be re-opened again.
  • alright Siri, thanks for your answer.

    I have purchased four BOOSTXL-SENSORS. Already tried them with the "i2ctmp007_CC2640R2_LAUNCHXL_tirtos_ccs" example project (untouched) and for all of them the output is:

    Everything is being sold by TI, now do you think I can get some help?...

    Thanks

  • Hi Andrew

    Looking at the product page for the BoosterPack ( http://www.ti.com/tool/BOOSTXL-SENSORS ) I realized that the TMP007 is not mounted:

    "PCB footprint to add TI TMP007 Infrared temperature sensor", and this is why you get a bus fault.

    Searching through E2E I found that this sensor is actually discontinued.

    I am really sorry that I was not aware of this.

    I guess that the developers of the example have old BoosterPacks where this sensor is still present. I will file a Jira Ticket regarding this issue and see if we can replace the temp007 example with an example for one of the sensors that are actually mounted.

    There are MSP430 examples for the different sensors on the BoosterPack and you can find those examples here.

    http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP-EXP430FR5994/latest/index_FDS.html

    I am not in the office now, but I have managed to get hold of a boosterpack that I will get tomorrow.

    Please try looking at the MSP430 code and see if you can get it up and running on the CC2640R2LP. If you run into problems, please let me know and I will try to help you with some code.

    BR

    Siri