MonsieurDavid
Posts: 7
Joined: Fri Feb 01, 2013 3:53 am

Gertduino and I2C

Wed Jan 15, 2014 2:01 am

Hello everyone,

I just got the Gertduino. I configured my Pi/Gertduino by following instructions on the User Manual as well as on https://projects.drogon.net/raspberry-p ... ega-setup/

I am now trying to set the RTC on the Gertduino. I've tried running the script that came with Gordon's modified avrdude and things are not going as smoothly as I'd hope. Following http://www.raspberrypi.org/forums/viewt ... 55#p461055, I get the 'echo: write error: Invalid argument' when trying to write

Code: Select all

sudo /bin/bash -c "echo ds1374 0x68 > /sys/class/i2c-adapter/i2c-1/new_device"
I note that i2cdetect does not see the Gertduino. Am I supposed to do something to help the Pi 'see' the Gertduino in I2C?

Thanks!


Linux raspberrypi 3.10.25+ #622 PREEMPT Fri Jan 3 18:41:00 GMT 2014 armv6l GNU/Linux
("Occidentalis")

User avatar
AndyD
Posts: 2327
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Gertduino and I2C

Wed Jan 15, 2014 2:39 am

Is there any chance that your Raspberry Pi is a 256Mb Model B? If so the earlier Raspberry Pi's you need to use i2c bus 0.

Code: Select all

sudo /bin/bash -c "echo ds1374 0x68 > /sys/class/i2c-adapter/i2c-0/new_device"

MonsieurDavid
Posts: 7
Joined: Fri Feb 01, 2013 3:53 am

Re: Gertduino and I2C

Wed Jan 15, 2014 2:57 am

It's a brand new Raspberry Pi. In any case bus 0 and bus 1 are returning empty matrices.
Do I need to set jumpers in any special way (as shown on p. 5 to 7 on the Gertduino user manual)?

Also, could it be something to do with the Occidentalis distro?

I am currently download the latest Raspbian to check this hypothesis.
Update: Same issue with Raspbian.

Code: Select all

sudo i2cdetect -y 1
returns an empty matrix with the Gertduino but returns something else when the Raspberry Pi is connected to a MCP23017

User avatar
AndyD
Posts: 2327
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Gertduino and I2C

Wed Jan 15, 2014 5:43 am

Have you loaded the RTC software on to the AVR48 on the Gertduino?

MonsieurDavid
Posts: 7
Joined: Fri Feb 01, 2013 3:53 am

Re: Gertduino and I2C

Wed Jan 15, 2014 6:02 am

Will the RTC software enable I2C on the Gertduino?

I am a bit confused here. Would you please outline the steps I should follow in order to upload the RTC software.

User avatar
AndyD
Posts: 2327
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Gertduino and I2C

Wed Jan 15, 2014 11:48 am

MonsieurDavid wrote:Will the RTC software enable I2C on the Gertduino?
I think so. The GertDuino is only emulating a DS1374 using the ATmega48p.
MonsieurDavid wrote:I am a bit confused here. Would you please outline the steps I should follow in order to upload the RTC software.
First, follow Gordon's instructions from here.
The code that you download will be in a directory called gertduino. In this directory you will find a directory called m48.
You will need to make the m48.hex file. There is a Makefile in this directory, so just use the make command to build it.
Now you will need to upload the m48.hex file to the ATmega48p. To do this set the jumpers on the GertDuino J13 jumper as shown in the manual (4.2 Program the Atmega-48).
Now use avrdude to upload the code to the m48.

Code: Select all

/usr/bin/avrdude -c gpio -p m48pa m48.hex -Uflash:w:m48.hex

MonsieurDavid
Posts: 7
Joined: Fri Feb 01, 2013 3:53 am

Re: Gertduino and I2C [SOLVED]

Wed Jan 15, 2014 10:14 pm

Thanks Andy!

You were right: compiling and uploading the m48 script enabled I2C on the Atmega48.
This solved my problem and got the RTC working.

User avatar
Jednorozec
Posts: 809
Joined: Sun Nov 24, 2013 2:17 pm
Location: Deposit, NY

Re: Gertduino and I2C

Tue Jan 21, 2014 5:19 pm

This command

Code: Select all

/usr/bin/avrdude -c gpio -p m48pa m48.hex -Uflash:w:m48.hex
doesn't work for me because there is no m48pa in the avrdude.conf file. There is, however, a m48p and it seems to work if I use that in the command.
The most important leg of a three legged stool is the one that's missing.
It's called thinking. Why don't you try it sometime?

zainulcharbiwala
Posts: 1
Joined: Sun Apr 12, 2015 1:42 pm

Re: Gertduino and I2C

Sun Apr 12, 2015 2:42 pm

Thanks for all the info on the Gertboard and the DS1374 emulation. I've been playing with this myself and wanted to add wakealarm support on a custom board to wake the Pi up at a specific time. I hope the following helps someone.

First, thanks to this post for pointing me in the right direction viewtopic.php?p=692662#p692662 ( i.e. you need to use the DeviceTree system to get this to work). To get wakealarm support, you need to tell the ds1374 driver to use an interrupt line. For my board, its hooked up as an active high to GPIO25.

To do this, add the following lines to [email protected] of i2-rtc-overlay.dts from https://github.com/raspberrypi/linux/bl ... verlay.dts

Code: Select all

ds1374: [email protected] {
  compatible = "maxim,ds1374";
  pinctrl-names = "default";
  pinctrl-0 = <&ds1374_pins>;
  reg = <0x68>;
  interrupts = <25 1>;
  interrupt-parent = <&gpio>;
  status = "disable";
};
This section adds a new parameter that tells DeviceTree to enable the ds1374 rtc driver (if asked for in config.txt). Notice also that it is requesting an interrupt on GPIO25. The 1 means its positive edge triggered. See this: https://www.kernel.org/doc/Documentatio ... 5-gpio.txt. Now connect up the pins by telling the GPIO driver what to do by adding [email protected] to the same file:

Code: Select all

[email protected] {
  target = <&gpio>;
  __overlay__ {
    ds1374_pins: ds1374_pins {
      brcm,pins = <25>;
      brcm,function = <0>;
      brcm,pull = <0>;
    };
  };
};
Last, add the following line to the __overrides__ section

Code: Select all

ds1374 = <&ds1374>,"status";
Here's the final patch:

Code: Select all

--- i2c-rtc-overlay.dts	2015-04-12 19:55:16.048129926 +0530
+++ i2-rtc-overlay.dts	1970-01-01 16:13:18.735590852 +0530
@@ -37,13 +37,34 @@
 				reg = <0x51>;
 				status = "disable";
 			};
+			ds1374: [email protected] {
+				compatible = "maxim,ds1374";
+                                pinctrl-names = "default";
+                                pinctrl-0 = <&ds1374_pins>;
+				reg = <0x68>;
+                                interrupts = <25 1>;
+                                interrupt-parent = <&gpio>;
+				status = "disable";
+			};
 		};
 	};
+
+	[email protected] {
+		target = <&gpio>;
+		__overlay__ {
+			ds1374_pins: ds1374_pins {
+				brcm,pins = <25>;
+				brcm,function = <0>;
+				brcm,pull = <0>;
+			};
+		};
+        };
 	__overrides__ {
 		ds1307 = <&ds1307>,"status";
 		ds3231 = <&ds3231>,"status";
 		pcf2127 = <&pcf2127>,"status";
 		pcf8523 = <&pcf8523>,"status";
 		pcf8563 = <&pcf8563>,"status";
+		ds1374 = <&ds1374>,"status";
 	};
 };
Now, recompile the dts using:

Code: Select all

dtc [email protected] -I dts -O dtb /boot/overlays/i2c-rtc-overlay.dtb i2c-rtc-overlay.dts
See https://www.raspberrypi.org/documentati ... ce-tree.md for an excellent explanation of the above command.
Then, enable the driver by adding this to /boot/config.txt

Code: Select all

dtoverlay=i2c-rtc,ds1374
That's it. Reboot now and you should have /sys/class/rtc/rt0/wakealarm that you can use to set the alarm in the usual way. https://www.mythtv.org/wiki/ACPI_Wakeup

Z.

Return to “Add-ons”

Who is online

Users browsing this forum: No registered users and 6 guests