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(¶ms); 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, ¶ms); if (handle == NULL) { // Error opening I2C openDone = false; while (1); } // Do I2C transfer (in callback mode) I2C_transfer(handle, &i2cTrans); return (NULL); }