Part Number: AM4379
Other Parts Discussed in Thread: TMDSEVM437X, AM4372
Tool/software: Code Composer Studio
Hello TI experts,
I'm using the AM4379 custom board(VARSOMAM43) and i'm trying to interface AD5933 through I2C.
I used i2cdetect command in order to read the slave address and was able to read the address 0x0D successfully. upon running the command i2cdump, I was even able to see the data in all the registers.
I have written a simple code to read the value from the register 0x82 which should give me the value which is exactly what i saw in the terminal (upon executing i2cdump). But for some reason the code gives me 0 every time.
can someone please tell me what's wrong.
Note: I haven't initialized any I2C pins manually. If that has to be done, please suggest me how to do that.
-Thanks
//============================================================================
// Name : test_A.cpp
// Author : Adarsh Kumar
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <stdio.h>
#include <string.h>
#include <stdlib.h> // system()
#include <unistd.h> // sleep()
#include <fcntl.h> // oflag like O_RDWR
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
char Readbyte(char address);
char file_I2C1_DEV[30] = "/dev/i2c-0";
int file;
int addr_AD5933 = 0b00001101; // The I2C address of AD5933
int main()
{
printf("I2C Interface Project!\n");
if((file = open(file_I2C1_DEV,O_RDWR)) < 0)
{
perror("Failed to open the i2c bus");
exit(1);
}
if(ioctl(file,I2C_SLAVE,addr_AD5933) < 0)
{
printf("Failed to acquire bus access and/or talk to slave.\n");
exit(1);
}
char temp;
temp = Readbyte(82);
printf("%d\n",temp);
sleep(1);
}
char Readbyte(char address)
{
char data;
char buf[10] = {0};
buf[0] = address;
if(write(file,buf,1) != 1)
{
/* ERROR HANDLING: i2c transaction failed */
printf("Failed to write to the i2c bus.\n");
}
// Using I2C Read
if (read(file,buf,1) != 1)
{
/* ERROR HANDLING: i2c transaction failed */
printf("Failed to read from the i2c bus.\n");
}
else
{
data = buf[0];
}
//BCD To Decimal Conversion
if(address == 0) //remove MSB bit in case of second
{
data = (((data & 0x70) >> 4) * 10) + (data & 0x0F);
}
else
{
data = (((data & 0xF0) >> 4) * 10) + (data & 0x0F);
}
return data;
}