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.

LAUNCHXL-CC2640R2: I2C comm never has successful transfer

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

I am new to I2C communication and I have made the following code to interface with a TI DAC7571. I have everything wired correctly and have made an initial code to only transmit signal.ampAC for now. The code seems correct to me but I still don't know why I can't get a successful transfer with I2C_Transfer(). Could anybody help me gain some insight as to what exactly is going wrong? CCS Cloud doesn't kick out any errors, it just never transfers the data. Sorry for the semi-messy code; it's obviously still a work in progress. Thanks in advance.

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

/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/I2C.h>
#include <ti/drivers/i2c/I2CCC26XX.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/power/PowerCC26XX.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <xdc/runtime/Types.h>

/* Board Header file */
#include "Board.h"

uint8_t rxBuffer[0];            // Receive buffer
uint8_t txBuffer[2];            // Transmit buffer
bool transferDone = false;
bool openDone = true;
bool status;

static void writeCallbackDefault(I2C_Handle handle, I2C_Transaction *transac, bool result){
    // Set length bytes
    if (result) {
        transferDone = true;
    } else {
        // Transaction failed, act accordingly...
    }
};

struct { //Used to store the signal amplitude (max is 4095)
    unsigned int ampAC : 12;
    unsigned int ampDC : 12;
} signal;



/*
 *  ======== mainThread ========
 */
void *mainThread(void *arg0){
   // Locals
    I2C_init();
    I2C_Handle handle;
    I2C_Params params;
    I2C_Transaction i2cTrans;
    
    // Configure I2C parameters.
    I2C_Params_init(&params);
    params.bitRate = I2C_400kHz;
    params.transferMode = I2C_MODE_CALLBACK;
    params.transferCallbackFxn = writeCallbackDefault;
    
    // Prepare data to send
    signal.ampAC = 2047;
    signal.ampDC = signal.ampAC/2;
	txBuffer[0] = signal.ampAC;
	txBuffer[1] = signal.ampAC >> 8;
        
    // Initialize master I2C transaction structure
    i2cTrans.writeBuf     = txBuffer;    
    i2cTrans.writeCount   = 2;
    i2cTrans.readBuf      = NULL;    
    i2cTrans.readCount    = 0;
    i2cTrans.slaveAddress = 0x4C;
    
    // Open I2C
    handle = I2C_open(Board_I2C0, &params);
    
    if (handle == NULL) {
        // Error opening I2C
        openDone = false;
        while (1);
    }
    
    // Do I2C transfer (in callback mode)
    I2C_transfer(handle, &i2cTrans);

    return (NULL);
}

  • Hi,

    When you say that it never transmits the data do you mean that it is physically never transmitted on the SCL/SDA pins or that the writeCallbackDefault is never called?

    Do you have a oscilloscope or a logic analyzer that you can probe the pins with and see if any data is transmitted?

    Best Regards,

    R.M

  • So did some testing and the SCL and SDA lines appear to be working correctly. I tested multiple signal levels (100, 2000, 4095, etc.) and the two lines work. The result variable in writeCallbackDefault turns to "true" as well. However, the line out of the DAC never changes. Even on the 2000 test (that should result in a Vout of ~1.5V) I never see any change. What could be going on?

  • I have figured it out. It turns out that the txBuffer was backward. The TI DAC7571 requires 12 bits to control the output and it splits it up into 4 and 8 bits (there is additional information with the byte containing the 4 MSBs of the data) over 2 consecutive bytes. I just assigned them into the buffer incorrectly.

    Thank you for being a springboard and helping me out R.M.