PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1682
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Sun Oct 04, 2015 7:48 pm

Take a look a bit further up this thread - this is a FAQ: viewtopic.php?p=751252#p751252

User avatar
bonzadog
Posts: 187
Joined: Wed Apr 25, 2012 9:40 am
Location: Rietberg/Germany

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Mon Oct 05, 2015 2:33 pm

I am afraid that I cannot recognise anything there that would help me.

I am using Wheezy on a Raspberry Pi B that previously worked with i2c.
The old SD card was no longer working so I installed wheezy etc on a new SD card with the camera enabled - no device tree- i2c enables and i2ctools and python-smbus installed. . Please note that I do not use the device tree.

My previous comment:

I have just installed Openelectrons Pan - Tilt software.
The Pan / Tilt tests work. So I want to use the Web Cam interface to show the video AND manual set the pan/tilt angles.

On boot a python programs fails Problem and shows that
smbus.SMBus(1) causes a "no such file" condition
I2Ctools and smbus are installed, I2C enabled.

/boot/config.txt contains
.....
start_x=1
gpu_mem=128
dtparam=i2c_arm=on


sudo i2cdetect -y 0 shows the following
Error: Could not open file `/dev/i2c-0' or `/dev/i2c/0': No such file or directory

A small python programme shows this

Type "help", "copyright", "credits" or "license" for more information.
>>> import smbus
>>> bus = smbus.SMBus(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 2] No such file or directory
>>> bus = smbus.SMBus(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 2] No such file or directory


I would be most grateful for any further pointers.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1682
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Mon Oct 05, 2015 2:35 pm

In order for the user-space interfaces (/dev/i2c*) to exist, you need to load module i2c-dev. Put i2c-dev into /etc/modules and reboot (or modprobe i2c-dev to avoid the need to reboot).

User avatar
bonzadog
Posts: 187
Joined: Wed Apr 25, 2012 9:40 am
Location: Rietberg/Germany

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Mon Oct 05, 2015 2:43 pm

I had already tried loading i2c-dev via apt-get install i2c-dev
- error message unknown programme.

I am a bit puzzled why I am having trouble now when ca. 1 months ago I had absolutely no problems. I can only assume a new updates have caused this.

Thank you for your help

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1682
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Mon Oct 05, 2015 2:46 pm

i2c-dev isn't something you apt-get - it is a module that is built as part of the kernel.

Type this:

Code: Select all

sudo modprobe i2c-dev
Does it appear to succeed? Does /dev/i2c-0 now exist? Great - now edit /etc/modules (sudo nano /etc/modules or sudo vi /etc/modules) and add i2c-dev on a line of its own. That's it.

User avatar
bonzadog
Posts: 187
Joined: Wed Apr 25, 2012 9:40 am
Location: Rietberg/Germany

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Tue Oct 06, 2015 7:52 am

@PhilE

Thank you, that did work and now all is running.

I had the system up and running previously - about a month or so ago -
without the need for the modprobe i2c-dev etc. I assume that the
raspi-config --> Advanced Options -->I2C install took care of that.
I am now wondering why it now doesn't...

Can you point me to some good reading material on I2C ... I've duckduckgo'd
for information and there is a lot but mostly seems outdated ie pre-2014

I assume that I must also adopt this procedure for Jessie.

Thank you again.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1682
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Tue Oct 06, 2015 7:59 am

The latest raspi-config - the one shipping with Jessie - will automatically add i2c-dev to /etc/modules when you enable the I2C interface, so you shouldn't need to do this step yourself provided you use raspi-config. But, unless we start (slightly) abusing Device Tree, it will always be necessary to load i2c-dev explicitly like this. That may sound strange, but i2c-dev only provides the user-space interface to I2C. There are lots of kernel drivers that use I2C, and they don't need i2c-dev to be loaded, so it seems wrong to make it compulsory to load it.

For general I2C reading materials, I suggest starting a new Forum post.

User avatar
jackokring
Posts: 815
Joined: Tue Jul 31, 2012 8:27 am
Location: London, UK
Contact: ICQ

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Sun Jan 03, 2016 12:56 am

A few changes on the SPI as follows, but I know there are errors.

Code: Select all

/dts-v1/;
/plugin/;

/ {
   compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";

   fragment@0 {
      target = <&spi0>;
      frag0: __overlay__ {
         #address-cells = <1>;
         #size-cells = <0>;
         pinctrl-0 = <&spi0_pins &spi0_cs_pins>;
         status = "okay";
         cs-gpios = <&gpio 22 1>, <&gpio 23 1>, <0>, <0>;

         spidev@2{
            compatible = "spidev";
            reg = <2>;   /* CE2 */
            #address-cells = <1>;
            #size-cells = <0>;
            spi-max-frequency = <500000>;
         };

         spidev@3{
            compatible = "spidev";
            reg = <3>;   /* CE3 */
            #address-cells = <1>;
            #size-cells = <0>;
            spi-max-frequency = <500000>;
         };
      };
   };

   fragment@1 {
      target = <&gpio>;
      __overlay__ {
         spi0_cs_pins: spi0_cs_pins {
            brcm,pins = <22 23>;
            brcm,function = <1>; /* out */
         };
      };
   };

   __overrides__ {
      cs0_pin = <&frag0>,"cs-gpios:12", <&spi0_cs_pins>,"brcm,pins:0";
      cs1_pin = <&frag0>,"cs-gpios:24", <&spi0_cs_pins>,"brcm,pins:4";
   };
};
I think

Code: Select all

   __overrides__ {
      cs0_pin = <&frag0>,"cs-gpios:12", <&spi0_cs_pins>,"brcm,pins:0";
      cs1_pin = <&frag0>,"cs-gpios:24", <&spi0_cs_pins>,"brcm,pins:4";
   };
has the wrong

Code: Select all

"cs-gpios:12"
"cs-gpios:24"
Is it possible?
Pi[NFA]=B256R0USB CL4SD8GB Raspbian Stock.
Pi[Work]=A+256 CL4SD8GB Raspbian Stock.
My favourite constant 1.65056745028

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1682
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Sun Jan 03, 2016 2:45 pm

Yes, the byte offsets are wrong - for the cs-gpios property as you have it then the offsets to the pin numbers are 4 and 16. What you have written should use GPIOs 22 & 23 as chip selects for SPI 0.0 and 0.1, then attempt to use native chip selects for SPI 0.2 and 0.3 - but they don't exist.

Why did you change the order of cs-gpios - what are you trying to achieve?

User avatar
jackokring
Posts: 815
Joined: Tue Jul 31, 2012 8:27 am
Location: London, UK
Contact: ICQ

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Sun Jan 03, 2016 3:02 pm

I have a bugblat fpga, and want to put a waveshare lcd on the extra header. I can route gpio cs to cs pin positions on the expansion connector.

Code: Select all

/dts-v1/;
/plugin/;

/ {
   compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";

   fragment@0 {
      target = <&spi0>;
      frag0: __overlay__ {
         #address-cells = <1>;
         #size-cells = <0>;
         pinctrl-0 = <&spi0_pins &spi0_cs_pins>;
         status = "okay";
         cs-gpios = <0>, <0>, <&gpio 22 1>, <&gpio 23 1>;

         spidev@2{
            compatible = "spidev";
            reg = <2>;   /* CE2 */
            #address-cells = <1>;
            #size-cells = <0>;
            spi-max-frequency = <500000>;
         };

         spidev@3{
            compatible = "spidev";
            reg = <3>;   /* CE3 */
            #address-cells = <1>;
            #size-cells = <0>;
            spi-max-frequency = <500000>;
         };
      };
   };

   fragment@1 {
      target = <&gpio>;
      __overlay__ {
         spi0_cs_pins: spi0_cs_pins {
            brcm,pins = <22 23>;
            brcm,function = <1>; /* out */
         };
      };
   };

	fragment@2 {
		target = <&spi0>;
		__overlay__ {
			status = "okay";

			spidev@2{
				status = "disabled";
			};

			spidev@3{
				status = "disabled";
			};
		};
	};

	fragment@3 {
		target = <&gpio>;
		__overlay__ {
			waveshare35a_pins: waveshare35a_pins {
				brcm,pins = <17 25 24>;
				brcm,function = <0 0 0>; /* in in in */
			};
		};
	};

	fragment@4 {
		target = <&spi0>;
		__overlay__ {
			/* needed to avoid dtc warning */
			#address-cells = <1>;
			#size-cells = <0>;

			waveshare35a: waveshare35a@0{
				compatible = "ilitek,ili9486";
				reg = <2>;
				pinctrl-names = "default";
				pinctrl-0 = <&waveshare35a_pins>;

				spi-max-frequency = <16000000>;
				rotate = <90>;
				bgr;
				fps = <30>;
				buswidth = <8>;
				regwidth = <16>;
				reset-gpios = <&gpio 25 0>;
				dc-gpios = <&gpio 24 0>;
				debug = <0>;

				init = <0x10000b0 0x00
				        0x1000011
					0x20000ff
					0x100003a 0x55
					0x1000036 0x28
					0x10000c2 0x44
					0x10000c5 0x00 0x00 0x00 0x00
					0x10000e0 0x0f 0x1f 0x1c 0x0c 0x0f 0x08 0x48 0x98 0x37 0x0a 0x13 0x04 0x11 0x0d 0x00
					0x10000e1 0x0f 0x32 0x2e 0x0b 0x0d 0x05 0x47 0x75 0x37 0x06 0x10 0x03 0x24 0x20 0x00
					0x10000e2 0x0f 0x32 0x2e 0x0b 0x0d 0x05 0x47 0x75 0x37 0x06 0x10 0x03 0x24 0x20 0x00
					/* piscreen -> waveshare35a */
					0x1000036 0x28
					0x1000011
					0x1000029>;
			};

			waveshare35a_ts: waveshare35a-ts@1 {
				compatible = "ti,ads7846";
				reg = <3>;

				spi-max-frequency = <2000000>;
				interrupts = <17 2>; /* high-to-low edge triggered */
				interrupt-parent = <&gpio>;
				pendown-gpio = <&gpio 17 0>;
				ti,x-plate-ohms = /bits/ 16 <60>;
				ti,pressure-max = /bits/ 16 <255>;
			};
		};
	};
	__overrides__ {
		speed =		<&waveshare35a>,"spi-max-frequency:0";
		rotate =	<&waveshare35a>,"rotate:0";
		fps =		<&waveshare35a>,"fps:0";
		debug =		<&waveshare35a>,"debug:0";
		swapxy =	<&waveshare35a_ts>,"ti,swap-xy?";

      cs2_pin = <&frag0>,"cs-gpios:12", <&spi0_cs_pins>,"brcm,pins:0";
      cs3_pin = <&frag0>,"cs-gpios:24", <&spi0_cs_pins>,"brcm,pins:4";
   };
};
?
Pi[NFA]=B256R0USB CL4SD8GB Raspbian Stock.
Pi[Work]=A+256 CL4SD8GB Raspbian Stock.
My favourite constant 1.65056745028

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1682
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Sun Jan 03, 2016 4:36 pm

That overlay looks too complicated, but it is almost correct. Here's my reading:

* Fragment 0 enables spi0, adds two chip GPIO selects for 0.2 and 0.3, leaving 0.0 and 0.1 using native chip selects (which are changed to GPIO chip selects on the same pins), and creates spidev 0.2 and 0.3 to use them.
* Fragment 1 allocates GPIOs 22 and 23 for spi0, to prevent others from using them.
* Fragment 2 disables spidev 0.2 and 0.3.
* Fragment 3 declares pins to be used by the waveshare device.
* Fragment 4 configures the waveshare display on spi 0.2 (node "waveshare35a@0" should really be called "waveshare35a@2" to match "reg = <2>"). It also configures the touchscreen device on spi 0.3 (again, this should really be called waveshare35a-ts@3 to match "reg = <3>".
* The "__overrides__" node declares the familiar display parameters, and correctly allows the GPIO pins to be changed.

There is a simplification that can be applied, which is to never create spidev 0.2 and 0.3 in the first place, in which case you don't need to disable them. spidev makes it possible to control arbitrary SPI devices from user-space code, which can be useful if there isn't a suitable kernel driver, but that isn't necessary in this case.

A final thought: it isn't necessary to use CS 2 & 3 - CS 0 & 1 could be moved to arbitrary pins (as your first overlay almost did) but this overlay would make a nice illustration of how to use GPIO chip selects for applications where the existing CSs are already used.

User avatar
jackokring
Posts: 815
Joined: Tue Jul 31, 2012 8:27 am
Location: London, UK
Contact: ICQ

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Sun Jan 03, 2016 5:05 pm

Excellent, a GPIO27 select muxed UART should be easy, as the protocols can be ACK/NAK based, and switching is easy without adapting the driver. :D
Pi[NFA]=B256R0USB CL4SD8GB Raspbian Stock.
Pi[Work]=A+256 CL4SD8GB Raspbian Stock.
My favourite constant 1.65056745028

beemins
Posts: 6
Joined: Thu Jan 21, 2016 5:33 pm

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Thu Jan 21, 2016 5:47 pm

PhilE wrote:You are in luck. The current RPi SPI driver, spi-bcm2835, support GPIO chip-selects. This means that any free GPIO line can be used as another chip select. In fact, as a result of some driver performance optimisations causing the hardware ("native") chip-selects to glitch, the driver will automatically convert native CS's to GPIO CS's.
Hi PhilE,

I followed your instruction in order to use more SPI chip select pins from GPIO but i got doubtful result which allow me to use only spidev0.2 and 0.3 (you can see from the picture) and I cannot even use any chip select (0 to 3) so how to fix this to use all chip select pins properly (0 (GPIO8), 1 (GPIO7), 2 (GPIO20), 3 (GPIO21)).

Thank you very much
Attachments
Problem.PNG
Problem.PNG (29.59 KiB) Viewed 5815 times

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1682
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Thu Jan 21, 2016 8:58 pm

Tell me exactly what you did and I'll tell you where you went wrong.

beemins
Posts: 6
Joined: Thu Jan 21, 2016 5:33 pm

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Fri Jan 22, 2016 3:20 am

Ok first I have TFT LCD with SPI interfaces and it already occupied CE0 and CE1 and it works well (I followed this link: viewtopic.php?f=45&t=105797)

Then I need to use Dot Matrix with MAX7219 (with this link: https://github.com/rm-hull/max7219)which also SPI interface so I need to use more chip select pins

So I removed my TFT LCD to test only MAX7219 with my pi and I cannot enable SPI
it shows

Code: Select all

ERROR: could not insert 'spi_bcm2708': No such device
and someone told me to disable Device Tree first and enable SPI again so I can use it

then I found this forum that allow me to use more chip selects

and I followed your instruction below

Code: Select all

/dts-v1/;
/plugin/;

/ {
	compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";

	fragment@0 {
		target = <&spi0>;
		frag0: __overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;
			pinctrl-0 = <&spi0_pins &spi0_cs_pins>;
			status = "okay";
			cs-gpios = <0>, <0>, <&gpio 20 1>, <&gpio 21 1>;

			spidev@2{
				compatible = "spidev";
				reg = <2>;	/* CE2 */
				#address-cells = <1>;
				#size-cells = <0>;
				spi-max-frequency = <500000>;
			};

			spidev@3{
				compatible = "spidev";
				reg = <3>;	/* CE3 */
				#address-cells = <1>;
				#size-cells = <0>;
				spi-max-frequency = <500000>;
			};
		};
	};

	fragment@1 {
		target = <&gpio>;
		__overlay__ {
			spi0_cs_pins: spi0_cs_pins {
				brcm,pins = <20 21>;
				brcm,function = <1>; /* out */
			};
		};
	};

	__overrides__ {
		cs2_pin = <&frag0>,"cs-gpios:12", <&spi0_cs_pins>,"brcm,pins:0";
		cs3_pin = <&frag0>,"cs-gpios:24", <&spi0_cs_pins>,"brcm,pins:4";
	};
};
then I

Code: Select all

sudo apt-get install device-tree-compiler
dtc -@ -I dts -O dtb -o spi-gpio-cs-overlay.dtb spi-gpio-cs-overlay.dts
sudo cp spi-gpio-cs-overlay.dtb /boot/overlays

Code: Select all

dtoverlay=spi-gpio-cs,cs2_pin=5,cs3_pin=6
***Note that before I reboot I enable Device Tree in raspi-config already

I have some questions, I don't understand why we need to override gpio pin 12 and 14.
And in dtoverlay why ics2_pin=5,cs3_pin=6 which we did not set before or I missed something?

Thank you very much

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1682
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Fri Jan 22, 2016 9:53 am

I assume you are using the ads7846 overlay? That overlay disables spidev0.0 and spidev0.1, and the ads7846 driver uses spi0.1 instead.

spidev is a user-space interface to the SPI bus. It allows you to send and receive arbitrary data, effectively allowing you to write a device driver in user-space (a bit like i2c-dev and libusb). This can be useful if you don't have a dedicated kernel driver for a device, or if you want to tinker.

SPI addresses a device using the chip select lines, with only one device per CS, and spidev assigns each CS an entry in /dev, but since you only get one device per CS it isn't possible to use a dedicated driver and spidev on the same CS, which is why overlays that add specific drivers also disable the corresponding spidev node. I don't know why the ads7846 overlay disables both spidev0.0 and spidev0.1 since it only uses the CS for spi0.1, but I've asked the author.

So dtoverlay=spi-gpio-cs adds CS 2 & 3 and tells spidev to use them, giving you spidev0.2 and spidev0.3. dtoverlay=ads7846 disables spidev0.1 (and spidev0.0, rightly or wrongly) and causes the kernel driver to be loaded and use CS 1. The screenshot above looks correct, based on that information.

If you think something isn't working correctly, explain what you would expect to see and what actually happens. It might also help if you temporarily disable the ad7846 overlay and compare the behaviour.

[ The ads7846 author says that it disables both spidevs because there is a DT parameter that allows you to select which CS to use. This would allow it to coexist with another SPI device with a dedicated driver. ]

beemins
Posts: 6
Joined: Thu Jan 21, 2016 5:33 pm

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Fri Jan 22, 2016 10:58 am

Yes I'm using ads7846 as a driver for HY28B LCD screen

I tried to disable ads7846 driver by comment out in config.txt

Code: Select all

#dtoverlay=hy28b, rotate=90
The result seems to be worked as it shows all spidev 0.0, 0.1, 0.2, 0.3
but when I drive my Dot Matrix with MAX7219 it worked perfectly either CE0 and CE1
but it still cannot use with CE2 (gpio 20) and CE3 (gpio 21).

What should I do? and are there any way that I can use ads7846 with MAX7219 together?
Attachments
ls-dev.PNG
ls-dev.PNG (10.18 KiB) Viewed 5743 times

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1682
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Fri Jan 22, 2016 11:06 am

Code: Select all

dtoverlay=spi-gpio-cs,cs2_pin=5,cs3_pin=6
says to use pins 5 and 6 for CS 2 and 3. If that line is in your config.txt then it should be no surprise that GPIO pins 20 and 21 don't function as chip selects.

beemins
Posts: 6
Joined: Thu Jan 21, 2016 5:33 pm

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Fri Jan 22, 2016 11:32 am

OK I got it, first I thought pins 5 and 6 are physical pins then I tried to use with GPIO5 pin and it works!

next I will tried to use MAX7219 with ads7846 together

EDIT**
Now I can work with all modules

Thank you very much PhilE :D

bsebse
Posts: 4
Joined: Mon Aug 27, 2012 3:52 pm

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Thu Feb 18, 2016 4:09 pm

beemins wrote:OK I got it, first I thought pins 5 and 6 are physical pins then I tried to use with GPIO5 pin and it works!

next I will tried to use MAX7219 with ads7846 together

EDIT**
Now I can work with all modules

Thank you very much PhilE :D

I have tried to get more than two SPI select lines, but with no success.
I have a touch screen that takes two selects, and want to add a rc522 RFID reader.
By following the discussion on how to use spi-bcm2835 to get multiple lines, I get entries /dev/spidev0.? but only /dev/spidev0.0 and /dev/spidev0.1 works.

Current kernel is, used because that is what is deliverd with the touch screen:
Linux raspberrypi 3.18.13-v7+ #784 SMP PREEMPT Sat May 9 15:57:36 BST 2015 armv7l GNU/Linux

Should it work with this kernel, or must I upgrade?
I also have the possibility to use I2C for the rc522. Has anybody had any success with doing that?

Thanks in advance for any pointers!

JackWoot
Posts: 2
Joined: Wed Mar 02, 2016 11:11 am

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Wed Mar 02, 2016 11:33 am

I'm having trouble getting I2C to detect my sensor, and I'm unsure if it's the Pi or the sensor which is at fault. I'm using a Raspberry Pi 2 B with 2016-02-09 Raspbian image (4.1.17-v7+ kernel).

I enabled I2C through raspi-config, and have dtparam=i2c_arm=on in /boot/config.txt, and i2c-dev in /etc/modules. /etc/modprobe.d/raspi-blacklist.conf is empty. lsmod shows both i2c_dev and i2c_bcm2708 are present. My user (pi) is also in the i2c group by default.

dmesg | grep i2c shows:

Code: Select all

[    4.201386] i2c /dev entries driver
[    6.395564] bcm2708_i2c 3f804000.i2c: BSC1 Controller at 0x3f804000 (irq 79) (baudrate 100000) 
and ls /dev/i2c* shows: /dev/i2c-1.

I'm using a Grove humidity/temperature sensor as shown in this tutorial: http://iot.eclipse.org/java/tutorial/, and am using the same wiring that is specified.

i2cdetect -y 1 shows:

Code: Select all

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --  
Would appreciate any help at all. I've been battling this a few days now and have read countless forum posts about this issue.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1682
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Wed Mar 02, 2016 12:08 pm

The fact that /dev/i2c-1 is present shows that your software configuration is correct. You can confirm using raspi-gpio:

Code: Select all

sudo apt-get install raspi-gpio    (if you don't have it already)
raspi-gpio get
You should see output that includes:

Code: Select all

  GPIO 02: level=1 fsel=4 alt=0 func=SDA1
  GPIO 03: level=1 fsel=4 alt=0 func=SCL1
If you do then it sounds like a wiring/hardware problem. Do you have any other I2C devices you can test with?

JackWoot
Posts: 2
Joined: Wed Mar 02, 2016 11:11 am

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Wed Mar 02, 2016 12:51 pm

Thanks for the reply.

raspi-gpio get provides the same output that you just mentioned.

I've managed to get the Grove LED to work, so it must just be a problem with the humidity sensor. I'll try asking around my colleagues to see if they have any I2C compatible devices lying around.

Adco
Posts: 42
Joined: Fri Mar 11, 2016 3:01 pm

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Thu Apr 07, 2016 8:57 am

I can read from the DS1307 using hwclock and i2cdetect but cannot write my own commands to it.

I placed 2 LEDs, in series with the pull-ups, on the SDA and SCL lines on the I2C bus. When I do I2Cdetect, the leds flash briefly as they should. That is when the DS1307 gets read and identified. All good.

When I try and read or write to the DS1307, no flashing. Tells me the I2Cset command is incorrect.

I am entering the following: sudo i2cset -y 1 0x68 0x07 0x10 (I am trying to get the SW output to toggle at 1Hz)
I have tried b and w at the end just in case. No use. The b mode is the default for byte mode so I have left it off. There must be something missing from my above string. Just not sure what.

The error I get back is "Could not set address to 0x68: Device or resource busy". The device can't be busy because both SDA and SCL is high. The LEDs are off. The resource must be busy because my command is incomplete.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1682
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Optional interfaces (I2C, I2S, SPI) and Device Tree

Thu Apr 07, 2016 9:06 am

I'm guessing you are using the i2c-rtc overlay? By doing so you are telling the I2C subsystem that the device at 0x68 is owned by the ds1307 driver. If you run "i2cdetect -y 1" you will see that the slot for the 68 address contains "UU" - used.

What you are trying to do is interfere with that device under the feet of the driver, which is not allowed. I think you would get the same result if you took the non-DT route - keep (or add) dtparam=i2c_arm=on, remove dtoverlay=i2c-rtc, reboot then run:

Code: Select all

sudo sh -c "echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device"

Return to “Interfacing (DSI, CSI, I2C, etc.)”

Who is online

Users browsing this forum: No registered users and 6 guests