Anybody been working with I2C yet?
I had the i2c-0 device available, but i2cdetect 0 gave many IC's on almost all addresses, so somethiing goes not well yet.
Also, I strongly suspect Data and Clock are mixed up on the PCB layout.
I2C
- darksoul
- Posts: 45
- Joined: Fri Nov 14, 2014 2:29 am
- Ton
- Posts: 22
- Joined: Sun Nov 16, 2014 4:35 pm
Re: I2C
I changed the i2c section in VOCORE.dts to:
I did not add i2c support in kernel_menuconfig
In make menuconfig I added kernelmodules:
(I think they were already present btw)
I added Makefile (https://dev.openwrt.org/browser/package ... s/Makefile) to
package/i2c-tools/Makefile
Then I did
Utils
i2c-tools
after flash and reboot, I do
Then I connected a YL-40 (https://brainfyre.wordpress.com/2012/10 ... le-review/) module
to 3v3 on pin PB18 (lower right corner, marked 3v3), GND, DATA, and SCLK
Then when you do
you expect only 0x48 to be present, but almost all adresses are present.
It seems something to do with pull-up, so:
Added a 4K7 pull up parallel to the 10K on YL-40, but that did not give any improvement.
Lowered VCC for YL-40 by putting diode inline, did not help too.
Any ideas?
Is there a second function of the pins that need to be disabled?
Is there more that I can check?
Concerning my thoughts about SDATA/SCLK swap:
The sch.pdf shows SCLK next to RESET in the black interface section,
but in the pdb.pdf it is SDATA next to RESET.
When I follow the tracks on the red layer of the pcb.pdf, and see the pinnumbers in
RT3530.pdf Table 1-2 196-Pin BGA Package Diagram Top View (right portion)
I see that sch.pdf seems to be right and pcb.pdf seems to be wrong.
- Code: Select all
i2c@900 {
compatible = "link,rt5350-i2c", "ralink,rt2880-i2c";
reg = <0x900 0x100>;
resets = <&rstctrl 16>;
reset-names = "i2c";
#address-cells = <1>;
#size-cells = <0>;
pinctrl-names = "default";
pinctrl-0 = <&i2c_pins>;
status = "okay";
};
I did not add i2c support in kernel_menuconfig
In make menuconfig I added kernelmodules:
- Code: Select all
kmod-i2c-core
kmod-i2c-ralink
(I think they were already present btw)
I added Makefile (https://dev.openwrt.org/browser/package ... s/Makefile) to
package/i2c-tools/Makefile
Then I did
- Code: Select all
make menuconfig
Utils
i2c-tools
after flash and reboot, I do
- Code: Select all
insmod i2c-dev
Then I connected a YL-40 (https://brainfyre.wordpress.com/2012/10 ... le-review/) module
to 3v3 on pin PB18 (lower right corner, marked 3v3), GND, DATA, and SCLK
Then when you do
- Code: Select all
i2cdetect 0
you expect only 0x48 to be present, but almost all adresses are present.
It seems something to do with pull-up, so:
Added a 4K7 pull up parallel to the 10K on YL-40, but that did not give any improvement.
Lowered VCC for YL-40 by putting diode inline, did not help too.
Any ideas?
Is there a second function of the pins that need to be disabled?
Is there more that I can check?
Concerning my thoughts about SDATA/SCLK swap:
The sch.pdf shows SCLK next to RESET in the black interface section,
but in the pdb.pdf it is SDATA next to RESET.
When I follow the tracks on the red layer of the pcb.pdf, and see the pinnumbers in
RT3530.pdf Table 1-2 196-Pin BGA Package Diagram Top View (right portion)
I see that sch.pdf seems to be right and pcb.pdf seems to be wrong.
- silviop
- Posts: 17
- Joined: Mon Oct 20, 2014 11:51 am
Re: I2C
i2cdetect not work very well on i2c-ralink driver,
read this thread:
https://forum.openwrt.org/viewtopic.php?id=52191
read this thread:
https://forum.openwrt.org/viewtopic.php?id=52191
- Ton
- Posts: 22
- Joined: Sun Nov 16, 2014 4:35 pm
Re: I2C
Thanks, good information.
YL-40 is working now. Pins are swapped on pdf.
This is testsoftware:
YL-40 is working now. Pins are swapped on pdf.
This is testsoftware:
- Code: Select all
/* ------------------------------------------------------------------------ *
* 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);
}
- romeo_bbb
- Posts: 4
- Joined: Tue May 05, 2015 12:28 am
Re: I2C
I get a byte on every single place so 00 01 02 03 04 05 ... etc. Did that happen to anybody? Never used I2C or anything similar before.
- romeo_bbb
- Posts: 4
- Joined: Tue May 05, 2015 12:28 am
Re: I2C
I am getting
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
10: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
20: 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f
30: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f
40: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f
50: 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f
60: 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f
70: 70 71 72 73 74 75 76 77
Did anybody get this? What am I doing wrong?
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
10: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
20: 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f
30: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f
40: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f
50: 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f
60: 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f
70: 70 71 72 73 74 75 76 77
Did anybody get this? What am I doing wrong?
- Vonger
- Posts: 897
- Joined: Sun Oct 19, 2014 6:00 am
Re: I2C
1. Check if you have 4.7K pull up resistors on both SCL and SDA.
2. i2cdetect should be called with parameter "-r"
2. i2cdetect should be called with parameter "-r"
- romeo_bbb
- Posts: 4
- Joined: Tue May 05, 2015 12:28 am
Re: I2C
I am using -r. And I am using YL-40 . It has the resistors on the board, no?
- Vonger
- Posts: 897
- Joined: Sun Oct 19, 2014 6:00 am
Re: I2C
I think you might use old openwrt version. In old openwrt, i2c-ralink driver has bug. Latest openwrt version will fix such issue.
and download i2c-tools from 14.04 barrier breaker/oldpackages then install manually.
and download i2c-tools from 14.04 barrier breaker/oldpackages then install manually.
Who is online
Users browsing this forum: No registered users and 9 guests