[i2c] i2c Driver for AT91SAM9260

Paul Kavan pkavan at gmail.com
Wed Apr 25 23:26:48 CEST 2007


I now have my DAC set up and am trying to get some communications between
the AT91SAM9260 and the DAC. My scope is telling me that the driver is
sending the start bit, but does not seem to be sending what I send and, inf
fact, seems to time out quickly after that. In my userspace code, I am
writing to the i2c with:

/**********************CODE********************/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include < stdio.h>
#include <linux/i2c-dev.h>
#include <linux/i2c.h>

#define WRITE_FILE      "adc_values.dat"
#define MAX_SIZE        10

int main(void)
{
  unsigned short adc_vals[MAX_SIZE];
  unsigned short shift_vals[MAX_SIZE];
  int len, i, j, adc_fd, i2c_fd;
  char c;

  i2c_fd = open("/dev/at91_i2c", O_RDWR);
  if(i2c_fd == -1)
  {
    printf("i2c open error...\n");
    return 1;
  }
  else
   printf("at91_i2c Opened\n");

  adc_fd = open("/dev/at91_adc", O_RDWR);
  if(i2c_fd == -1)
  {
    printf("adc open error...\n");
    return 1;
  }

  for(i=1 ; i<MAX_SIZE ; i++)
  {
    //len = read(adc_fd,&adc_vals[i], sizeof(adc_vals));
    adc_vals[i] = 0x2AA;
  }

  int addr = 0x4C; /* The I2C address */
  if (ioctl(i2c_fd,I2C_SLAVE,addr) < 0)
  {
    printf("Address Error\n");
    exit(1);
  }
  else

  for(j=1 ; j<i ; j++)
  {
    shift_vals[j] = (adc_vals[j]<<2);
    write(i2c_fd,&shift_vals[j],2);
    printf("press enter to continue\n");
    c = getchar();
  }

  close(adc_fd);        //Close the adc
  close(i2c_fd);        //Close the i2c
}

/******************END OF CODE********************/

The DAC I am using (TI DAC6571) has a standard mode that operates in a
standard mode and a fast mode (100 kHz and 400 kHz respectively)--plus a
high-speed mode (which I dont really need). It
expects on the first update a start condition, a valid i2c address, the 2
bytes I send that contain control information and the 10-bit number for the
DAC.

The address is 0b1001100 or 0x4c. To indicate a 'write' it wants a '0', then
it sends an ack. then the two message bytes follow, separated by an ack, and
another ack follows the second byte.....I assume this is fairly standard for
the i2c (It has been about 3 yrs since I used it)

I believe that I am doing everything correctly, but could very well be wrong
in that assumption. I am going over the i2c driver code now to try and trace
what is happening...it seems like it should work.

Does anyone have any ideas or suggestions of possible errors on my part?

Thanks.

Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.lm-sensors.org/pipermail/i2c/attachments/20070425/c7e985b5/attachment.html 


More information about the i2c mailing list