VoCore i2c detect problem

SabbraCadabra
 
Posts: 1
Joined: Mon Jul 06, 2015 11:47 am

VoCore i2c detect problem

Mon Jul 06, 2015 12:17 pm

Hello everybody,

When i try to search sensor which are connected to my vocore i had a problem. sensors connected with i2c interfaces. i'm using the command 'i2cdetect -r 0' and after the terminal screen gives me an blank table. The i2c tables comes with no sensors. I could not find how can i fix this problem. The output is below;

root@OpenWrt:~# i2cdetect 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
0 1 2 3 4 5 6 7 8 9 a b c d e f
00:
10:
20:
30:
40:
50:
60:
70:


and when im execute this code i had an error too, Error message 'i2c write failed'.

/* ------------------------------------------------------------------------ *
* PCF8591.c - check / test for YL-40 connected to Vocore *
* ------------------------------------------------------------------------ *
*
* No error checking, just dumping values to the commandline
* Vocore PDF VoCore.v1.0.pcb.pdf gives wrong information:
* Pin next to RESET is CLK not DATA.
* Pnnames are swapped. Correct is: Pin 1 GND, 2 RESET, 3 I2C_SCLK, 4 I2C_SD
*
* (c) 2014 Ton Augustin
*
* See: http://openwrt.pbworks.com/w/page/13164269/I2C
*
*/

#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/i2c-dev.h>

/* from i2c.h */
#define I2C_SLAVE 0x0703 /* Change slave address */


#define PCF8591_ADDR 0x48


//Control Register Defines for PCF8591
//AD Channels
#define PCF8591_ADC0 0x00
#define PCF8591_ADC1 0x01
#define PCF8591_ADC2 0x02
#define PCF8591_ADC3 0x03
//AD Channel Mask
#define PCF8591_CHMSK 0x03

//Auto Increment flag (0=disable, 1=enable)
#define PCF8591_AIF 0x04

//AD Channels Input modes
//4 Single Channels (Chan0=AIN0, Chan1=AIN0, Chan2=AIN0, Chan3=AIN0)
#define PCF8591_4S 0x00
//3 Diff Channels (Chan0=AIN0-AIN3, Chan1=AIN1-AIN3, Chan2=AIN2-AIN3)
#define PCF8591_3D 0x10
//2 Single Channels (Chan0=AIN0, Chan1=AIN1)
//1 Diff Channel (Chan2=AIN2-AIN3)
#define PCF8591_2S_1D 0x20
//2 Diff Channels (Chan0=AIN0-AIN1, Chan1=AIN2-AIN3)
#define PCF8591_2D 0x30
//ChannelMode Mask
#define PCF8591_CHMDMSK 0x30
//Analog Output enable flag (0=disable, 1=enable)
#define PCF8591_AOUT 0x40

//Default Mode: ADC0, AutoIncr On, 4 Single Chan, AnalogOut Off
#define PCF8591_CTRL_DEF (PCF8591_ADC0 | PCF8591_AIF | PCF8591_4S)



int main(int argc, char *argv[]) {
int file;
int adapter_nr = 0; /* there is only one */
char filename[20];
unsigned long addr;
int rc,ct;
unsigned char data[1];
unsigned char analog[12];


sprintf(filename,"/dev/i2c-%d",adapter_nr);
if ((file = open(filename,O_RDWR)) < 0) {
/* ERROR HANDLING; you can check errno to see what went wrong */
fprintf(stderr, "%s: failed to open %s, err=%d\n",argv[0],filename,file);
exit(1);
}

addr = PCF8591_ADDR; /* The I2C address */
if ((rc=ioctl(file,I2C_SLAVE,addr)) < 0) {
/* ERROR HANDLING; you can check errno to see what went wrong */
fprintf(stderr, "%s: addr ioctl failed, addr=0x%03lX, err=%d\n",argv[0],addr,rc);
exit(1);
} else
//fprintf(stderr, "%s: ioctl set I2C_SLAVE addr=0x%03lX\n",argv[0],addr);

while(1) {
data[0] = PCF8591_CTRL_DEF;
if ( write(file,data,1) != 1) {
/* ERROR HANDLING: i2c transaction failed */
fprintf(stderr, "%s: i2c write failed\n",argv[0]);
exit(1);
}
ct=read(file,analog,6);
printf("Light:%3d Temp:%3d X:%3d Potmeter:%3d\r", analog[2],analog[3],analog[4],analog[5]); // Skip first bytes
}

return(0);
}


Anyone know how can i beat this i2c problem ? Thx for advices.

Vonger
 
Posts: 896
Joined: Sun Oct 19, 2014 6:00 am

Re: VoCore i2c detect problem

Fri Jul 10, 2015 3:51 pm

VoCore I2C do not have pull up resistor by default.
I2C CLK/DATA must be pull high with 4.7k ohm to use. Maybe add two pull up resistor will fix such issue :)

brad
 
Posts: 31
Joined: Tue Jan 06, 2015 5:19 am

Re: VoCore i2c detect problem

Wed Aug 12, 2015 9:31 am

There is also some confusion over the pins. From this link http://vocore.io/wiki/index/id:7 the pins are reversed. I use clk on the sd and sd on the clk. And vonger is right, you need the pullups.
Not sure if that helps.

Return to VoCore & VoCore+Dock

Who is online

Users browsing this forum: Google [Bot] and 28 guests