Adafruit I2C Capacitive Moisture Sensor to TILAUNCHXL-CC1310

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
moonknight
 
Posts: 1
Joined: Fri Apr 08, 2022 11:18 pm

Adafruit I2C Capacitive Moisture Sensor to TILAUNCHXL-CC1310

Post by moonknight »

Hello,

I have been trying to connect to soil sensor to my TI MCU over I2C. I have been successful in connecting the sensor to board, it is connected to SCL, SDA, 3V3, GND. I am also able to connect through the address 0x36. My issue comes when trying to read either the moisture data or temperature data. I have tried changing the registers that it reads from, but I have not had any luck. I know the data should come from the registers 0x0F and 0x10. When I try reading from 0x10, i get the value 65535 returned. I have been reading through the source code from the sensor and have come to understand that this number is the default value from the touchRead function. So it seems as if I am in the right place, but I am unable to read the data. What am I doing wrong that is prohibiting me from accessing the data? Thank you very much for your help!

Code: Select all

#include <stdint.h>
#include <stddef.h>
#include <unistd.h>

/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/I2C.h>
#include <ti/display/Display.h>

/* Example/Board Header files */
#include "Board.h"

#define TASKSTACKSIZE       640

/*
 *  ======== TMP Registers ========
 */
#define ADA_REG         0x10
#define ADA_ADDR        0x36;

static Display_Handle display;

/*
 *  ======== mainThread ========
 */
void *mainThread(void *arg0)
{
    uint16_t        sample;
    uint16_t        temperature;
    uint8_t         txBuffer[1];
    uint8_t         rxBuffer[2];

    I2C_Handle      i2c;
    I2C_Params      i2cParams;
    I2C_Transaction i2cTransaction;

    /* Call driver init functions */
    Display_init();
    GPIO_init();
    I2C_init();

    /* Configure the LED*/
    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 i2ctmp example.");

    /* 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");
    }

    /* Common I2C transaction setup */
    i2cTransaction.writeBuf   = txBuffer;
    i2cTransaction.writeCount = 1;
    i2cTransaction.readBuf    = rxBuffer;
    i2cTransaction.readCount  = 2;

    txBuffer[0] = ADA_REG;
    i2cTransaction.slaveAddress = ADA_ADDR;

    /* Print which TMP is in use */
    if (ADA_REG == txBuffer[0]) {
        Display_printf(display, 0, 0, "Detected ADA sensor.");
    }

    /* Take 20 samples and print them out onto the console */
    for (sample = 0; sample < 20; sample++) {
        if (I2C_transfer(i2c, &i2cTransaction)) {

            temperature = (rxBuffer[0] << 8) | (rxBuffer[1]);

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

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

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

    return (NULL);
}

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”