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 / LAUNCHXL-CC1310 :DS1307 Connect I2C Example Source Code

Part Number: LAUNCHXL-CC1310
Other Parts Discussed in Thread: TMP006, HDC1080, CC1310, SIMPLELINK-SDK-SENSOR-ACTUATOR-PLUGIN

Tool/software: Code Composer Studio

I tried many things by watching tmp006 and i2ctmp and HDC1080.그러나 연결되지 않습니다.

Can you give me an example?

I need your help.

  • Hi,

    Have you reviewed the i2ctmp example of your SDK (examples\rtos\CC1310_LAUNCHXL\drivers\i2ctmp)?

    Hope this will help,

    Regards,

  • Yes, I reviewed it but didn't get the answer I wanted.

    How do I connect to the DS1307 I2C?

  • Hi,

    I am not aware of any code implementation provided for this specific sensor.

    You can review the SIMPLELINK-SDK-SENSOR-ACTUATOR-PLUGIN for more examples of sensors interfaced through I2C.

    Regards,

  • Our examples show how to use the driver. If you want to use a device with I2C that is covered by our examples you typically have to:

    - Check the slave address (check table 4 in the DS1307

    - Check which registers you want to access and find the addresses for these.

    Since DS1307 is not a TI part we can't support you on how to use this part in detail, you have to consult the datasheet.

  • #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       768
    
    static Display_Handle display;
    
    
    uint8_t         txBuffer[1];
    uint8_t         rxBuffer[7];
    I2C_Handle      i2c;
    I2C_Params      i2cParams;
    I2C_Transaction i2cTransaction;
    
    /*
     *  ======== mainThread ========
     */
    void *mainThread(void *arg0)
    {
    
        /* Call driver init functions */
        Display_init();
        GPIO_init();
        I2C_init();
    
        /* Configure the LED and if applicable, the TMP116_EN pin */
        GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    #ifdef Board_GPIO_TMP116_EN
        GPIO_setConfig(Board_GPIO_TMP116_EN, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH);
        /* 1.5 ms reset time for the TMP116 */
        sleep(1);
    #endif
    
        /* 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_100kHz;
        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.slaveAddress = (0x68);    //ds1307 address
        txBuffer[0] = 0x00;                    //ds1307 Write Mode
    
        i2cTransaction.writeBuf = txBuffer;
        i2cTransaction.writeCount = 1;
        i2cTransaction.readBuf = NULL;
        i2cTransaction.readCount = 0;
    
        if (I2C_transfer(i2c, &i2cTransaction)) {
        }
        else {
            Display_printf(display, 0, 0, "I2C Bus fault.");
        }
    
        i2cTransaction.slaveAddress = (0x68);    //ds1307 address
    
        i2cTransaction.writeBuf = NULL;
        i2cTransaction.writeCount = 0;
        i2cTransaction.readBuf = rxBuffer;
        i2cTransaction.readCount = 7;
    
        if (I2C_transfer(i2c, &i2cTransaction)) {
        }
        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);
    }
    

    This is my source code and execution result.

    This is the first transmission waveform

    .

    Second transmission waveform.

    What am I doing wrong?

  • Hi,

    Did you manage to solve your issue? Have you verified if the commands are compliant with the data sheet of your part?

    FYI, the I2C driver can be configured to send and receive data at the same time.

    Let me know if you need more assistance,

    Kind regards,