arajasek
Posts: 40
Joined: Fri Oct 06, 2017 2:17 pm

I2C issue connecting RTC to custom CM PCB

Fri Mar 23, 2018 4:50 pm

I'm trying to configure the PCF8523 RTC on my custom PCB to work with the compute module. I've used GPIO 44(SDA) and 45(SCL) for I2C as the other GPIO pins were already used. How would I go about enabling the ALT 1 functions on GPIO 44 and 45?
Attachments
Screen Shot 2018-03-23 at 12.45.26 PM.png
Screen Shot 2018-03-23 at 12.45.26 PM.png (90.5 KiB) Viewed 1018 times

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

Re: I2C issue connecting RTC to custom CM PCB

Fri Mar 23, 2018 5:01 pm

The confusingly named "i2c0-bcm2708" overlay should do what you need:

Code: Select all

Name:   i2c0-bcm2708

Info:   Enable the i2c_bcm2708 driver for the i2c0 bus. Not all pin combinations
        are usable on all platforms.

Usage:  dtoverlay=i2c0-bcm2708,<param>=<val>

Params: sda0_pin                GPIO pin for SDA0 (deprecated - use pins_*)
        scl0_pin                GPIO pin for SCL0 (deprecated - use pins_*)
        pins_0_1                Use pins 0 and 1 (default)
        pins_28_29              Use pins 28 and 29
        pins_44_45              Use pins 44 and 45
        pins_46_47              Use pins 46 and 47
Note that the README is now out of date - it no longer activates the old i2c_bcm2708 driver, but the pin selection still works.

To select I2C0 on pins 44 and 45 add the following to config.txt:

Code: Select all

dtoverlay=i2c0-bcm2708,pins_44_45

arajasek
Posts: 40
Joined: Fri Oct 06, 2017 2:17 pm

Re: I2C issue connecting RTC to custom CM PCB

Fri Mar 23, 2018 6:49 pm

Thank for the reply I can now recognize the device with address 68

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

Re: I2C issue connecting RTC to custom CM PCB

Fri Mar 23, 2018 10:55 pm

At this point you would normally be able to use the i2c-rtc overlay to load and configure the pcf8523 driver, but that overlay is expecting to use i2c1 (although it uses the other label - i2c_arm). As it is, you either need to create a custom version of the overlay or do it the old way.

To make a custom overlay:
1. copy the source from here,
2. change the "&i2c_arm"s to "&i2c0"s and save it as i2c0-rtc-overlay.dts,
3. compile with:

Code: Select all

dtc [email protected] -I dts -O dtb -o i2c0-rtc.dtbo i2c0-rtc-overlay.dts
and
4. load it with:

Code: Select all

dtoverlay=i2c0-rtc,pcf8523
The alternative is to add this line into one of the startup scripts - /etc/rc.local should work:

Code: Select all

echo pcf8523 0x68 > /sys/class/i2c-adapter/i2c-0/new_device

arajasek
Posts: 40
Joined: Fri Oct 06, 2017 2:17 pm

Re: I2C issue connecting RTC to custom CM PCB

Tue Mar 27, 2018 2:56 pm

PhilE wrote: At this point you would normally be able to use the i2c-rtc overlay to load and configure the pcf8523 driver, but that overlay is expecting to use i2c1 (although it uses the other label - i2c_arm). As it is, you either need to create a custom version of the overlay or do it the old way.

To make a custom overlay:
1. copy the source from here,
2. change the "&i2c_arm"s to "&i2c0"s and save it as i2c0-rtc-overlay.dts,
3. compile with:

Code: Select all

dtc [email protected] -I dts -O dtb -o i2c0-rtc.dtbo i2c0-rtc-overlay.dts
and
4. load it with:

Code: Select all

dtoverlay=i2c0-rtc,pcf8523
The alternative is to add this line into one of the startup scripts - /etc/rc.local should work:

Code: Select all

echo pcf8523 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
Thanks for your help again. Is there a specific location in the pi where this file needs to be saved?

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

Re: I2C issue connecting RTC to custom CM PCB

Tue Mar 27, 2018 3:05 pm

No, but depending on how you invoke it you may need to make it executable (chmod a+x filename). But I thought you could just paste that line directly into /etc/rc.local.

arajasek
Posts: 40
Joined: Fri Oct 06, 2017 2:17 pm

Re: I2C issue connecting RTC to custom CM PCB

Tue Mar 27, 2018 4:41 pm

When I compile the i2c0-rtc-overlay.dts i get warning messages saying but no reg property and when I load the overlay I don't get a UU sign on the RTC address(0x68) when I run i2c detect.

[email protected]:~ $ dtc [email protected] -I dts -O dtb -o i2c0-rtc.dtbo i2c0-rtc-overlay.dts

Warning (unit_address_vs_reg): Node /[email protected] has a unit name, but no reg property

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

Re: I2C issue connecting RTC to custom CM PCB

Tue Mar 27, 2018 4:45 pm

If you aren't using the overlay then you will also need to enable the ARMs' access to I2C0:

Code: Select all

dtparam=i2c0=on

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

Re: I2C issue connecting RTC to custom CM PCB

Tue Mar 27, 2018 4:47 pm

But you must have done that otherwise the bus device (/dev/i2c-0) wouldn't appear.

Have you tried running the command to enable the RTC device from the shell instead? Does the driver appear in the list when you run lsmod?

arajasek
Posts: 40
Joined: Fri Oct 06, 2017 2:17 pm

Re: I2C issue connecting RTC to custom CM PCB

Tue Mar 27, 2018 5:13 pm

Running the command from shell solved my problem. Thanks for your help

Return to “Compute Module”