Quantcast

i2c in overo

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

i2c in overo

zudil
I am trying to read data from ADS7830 in my overo using i2c. I used a level-translator in between.
According to datasheet, address byte is 1 0 0 1 0 a1 a2 r/w  should be followed by command byte (channel and mode selection).
I have a problem that there is no communication between gumstix and the device. I dont know where is the mistake is.

My code is

#include <stdint.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/i2c-dev.h> /* for I2C_SLAVE */
#include <errno.h>

int main(void) {

int fh;
uint8_t data = 0x84;

fh = open("/dev/i2c-3", O_RDWR);
if (fh < 0) {
              perror("open");
              return 1;
}

// tell the driver we want the device at address 0b1001000
ioctl(fh, I2C_SLAVE, 0x48);

// write 0x84 ( 1000 0100 - command byte to read from channel one)
write(fh, data, 1);

// read output from device
read(fh, data, 1);
printf("%x", data);

close(fh);
return 0;
}

output is always 84, even if I don't connect my device to gumstix. I am able to see some fluctuation in SDA and SCL lines when I run the program.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: i2c in overo

Bob Feretich
Two obvious bugs. One severe. The other should not make a difference, but might.
  1. read() and write() need the address of the buffer, not the value...
    write(fh, &data, 1);
    read(fh, &data, 1); 
  2. Using a write() followed by a read() will generate two separate bus transactions with a STOP bit in between. The preferred style is to use ioctl(file, I2C_RDWR, struct i2c_rdwr_ioctl_data *msgset)
    with the first message in the set being the write and the second the read. This will eliminate the STOP bit and perform a restart instead.
Regards,
Bob F.

I am trying to read data from 
http://www.upgradeindustries.com/media/files/products/ti-adc-ads7830.pdf
ADS7830  in my overo using i2c. I used a 
http://www.ti.com/lit/ds/symlink/pca9306.pdf level-translator  in between.
According to datasheet, address byte is 1 0 0 1 0 a1 a2 r/w  should be
followed by command byte (channel and mode selection).
I have a problem that there is no communication between gumstix and the
device. I dont know where is the mistake is.

My code is

#include <stdint.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/i2c-dev.h> /* for I2C_SLAVE */ 
#include <errno.h>

int main(void) { 

int fh; 
uint8_t data = 0x84; 

fh = open("/dev/i2c-3", O_RDWR); 
if (fh < 0) { 
              perror("open"); 
              return 1; 
} 

// tell the driver we want the device at address 0b1001000 
ioctl(fh, I2C_SLAVE, 0x48); 

// write 0x84 ( 1000 0100 - command byte to read from channel one) 
write(fh, data, 1); 

// read output from device
read(fh, data, 1); 
printf("%x", data); 

close(fh); 
return 0; 
} 

output is always 84, even if I don't connect my device to gumstix. I am able
to see some fluctuation in SDA and SCL lines when I run the program.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
gumstix-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gumstix-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: i2c in overo

zudil
Thanx for the reply.
I tried using write(fh, &data, 1); and read(fh, &data, 1);. Now, its giving me random output like a0, c7 and so on, but I was expecting a constant value because I am giving a constant signal to the ADC.
I tried using  ioctl(file, I2C_RDWR, struct i2c_rdwr_ioctl_data *msgset), but it gave me error while compiling
array type has incomplete element type   in the line struct i2c_msg   msgs[2];

root@overo:~# i2cdetect -y -r 3          gives me                                      
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f                            
00:          -- -- -- -- -- -- -- -- -- -- -- -- --                            
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --                            
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --                            
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --                            
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --                            
50: -- 51 -- -- -- -- -- -- -- -- -- -- -- -- -- --                            
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --                            
70: -- -- -- -- -- -- -- --    

I guess 48 is for slave address , but could't find out what is 51

Does it mean that my problem is in program, not in hardware?
Loading...