pgman
Posts: 22
Joined: Sun Jan 06, 2013 8:34 pm

RTC using P5 header

Sun Jan 06, 2013 10:19 pm

I'm trying to get a DS1307 RTC up and running on the new P5 header on a rev 2 board. According to posts about the rev 2 board, the P5 is meant to be used for things like 3rd party RTC boards.

I've followed various tutorials on using I2C using 5v devices with the RPi. I've got the IC2 tools installed, and its showing i2c-0 and i2c-1 as valid busses with nothing active on either.

I've got a DS1307 board from ebay, which I've previously tested on an Arduino mega, so I know it should be working. I've connected it to the I2C pins on P5 header (pins 3&4). The RTC board had 3k3 resistors pulling SDA and SCL up to the 5v rail, so I removed these, and connected them via 1k9 resistors to the 3v3 rail. I've checked the voltages on each pin I've wired up and all look ok (0v is at 0v, 5v is at 5v, and SDA/SCL are high at 3.3v).

When I run i2cdetect -y 0 and ic2detect -y 1 I still get no devices showing (the DS1307 should be address 68 and theres also a AT24C32, but not sure what its address is). I've not yet tried the board on the P1 header, as its soldered direct to the P5 holes.

Any thoughts on what I may be missing.

What is a bit confusing to me is that the documentation on the eLinux wiki, that shows GPIO28 and GPIO29 as the I2C0 bus, (P5 pins 3&4). And it also says GPIO0 and GPIO1 are the I2C0 bus (present on the S5 connector). This applies since the rev 2 board, and that is what I am using.

User avatar
aTao
Posts: 1086
Joined: Wed Dec 12, 2012 10:41 am
Location: Howlin Eigg

Re: RTC using P5 header

Sun Jan 06, 2013 10:53 pm

GPIO pins 28 and 29 have SDA0 and SCL0 as alternative functions (alt 0), you will need to write 0b100 to bits 24..26 of GPIO atlernate function register 2 (address 0x20000000 [peripheral base] + 0x200000 [GPIO offset] + 0x08 [register offset]) to enable alt function0 on GPIO 28. similarly 0b100 to bits 27..29 of the same register for GPIO 29
>)))'><'(((<

pgman
Posts: 22
Joined: Sun Jan 06, 2013 8:34 pm

Re: RTC using P5 header

Sun Jan 06, 2013 11:21 pm

Cheers for the prompt reply. It makes sense that ALT0 functions need to be enabled.

Just to satisfy myself that the hardware was OK I've connected the board to P1 pins 3&5. Et voila - it shows up in I2Cdetect -y 1 at address 68.

Now according to the same wiki, these are GPIO02 and GPIO03, which have i2c1 on them as ALT0 functions. What I cant see it why GPIO 2&3 are already running as ALT0 yet 28&29 are just normal IO pins.

I'm just going to hack around with the board on I2C1 for a while, before getting to grips with writing bits to the alternate function registers.

Peter247
Posts: 56
Joined: Wed Nov 21, 2012 12:29 am

Re: RTC using P5 header

Tue Jan 08, 2013 1:25 am

From what I can workout the second i2c is configured with alt0 function at start up.
That's what webiopi says about it !!
But what you may be forgetting is p5 port i2c may not have the pull up resistor fitted .
So try adding the pull up resistors and see if it works ?
http://www.peter224722.blogspot.co.uk/

pgman
Posts: 22
Joined: Sun Jan 06, 2013 8:34 pm

Re: RTC using P5 header

Tue Jan 08, 2013 4:19 am

Hi Peter247
I did start with the 5v pull up resistors removed and had 1k9 resistors pulling up to the 3v3 rail. I think I said that in the post originally.

I've put using P5 on hold for now, and instead am using P1 in order to check the functioning of the board itself, and that threw up a whole host of issues, most of which are sorted now. But to help others, these are what I had to figure out.

First of all the packages need to be installed. Next there is a bug in hwclock.sh. Then there is a fake_hwclock running that needs to be disabled. Then the proper hwclock needs to be added to the startup and shutdown scripts. And then the hardware needs to be registered in the modules file.

So now, I can get set, and read the etc and use it to set the system clock. Only problem I've still not solved is how to get the system clock set during startup. I can see an error message about the etc not being ready some 5 seconds before the i2c busses are active, but I'm struggling on how to put it right.

Will post more soon.

pgman
Posts: 22
Joined: Sun Jan 06, 2013 8:34 pm

Re: RTC using P5 header

Tue Jan 08, 2013 4:22 am

Just to be clear in my prev post I meant to say RTC but spell checker changed it to etc.

Peter247
Posts: 56
Joined: Wed Nov 21, 2012 12:29 am

Re: RTC using P5 header

Tue Jan 08, 2013 10:59 am

oooh yes I know that one.
After I submitted my post I did a little recheck, I found my android tablet did a little word substitution.
How I love spell checker and word prediction software .
http://www.peter224722.blogspot.co.uk/

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: RTC using P5 header

Fri Jan 11, 2013 11:43 am

I'm trying the same, although I'm rather new to this so I don't know if I'll be of any help; maybe here are more ideas: http://www.raspberrypi.org/phpBB3/viewt ... 44&t=16218.

Anyway, I have this module:
Image

I take it that I need to desolder the two 3k3 resistors next to SCL and SDA and then add 1k9 pull up resistors to the 3V3 of the Pi (Pin1)? Not sure how to exactly solder them but I'll look up pull up resistors ;)

pgman
Posts: 22
Joined: Sun Jan 06, 2013 8:34 pm

Re: RTC using P5 header

Mon Jan 21, 2013 3:30 am

Yes, That is the module I've been using.

The 2 resistors are the ones next to the ICs labelled R2 and R3. If you trace from the SDA/SCL pins you'll find a path to these 2 resistors. The other side is to the 5v pin. I can't find an actual schematic for this board though.

I can read and set the clock, but am still struggling getting it to sync the internal clock at boot time. So I've started with a fresh image of raspbian, connected the board to the P1 header, and I'm going through the steps again.

Once I get it syncing, then I'll have a go at using the P5 header, which needs pull up resistors to 3v3. The whole thing looks quite neat, and the P1 header is still available for expansion.

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: RTC using P5 header

Sat Feb 16, 2013 3:13 pm

Still trying to get my head around this.

I removed the two resistors R2 and R3 and soldered wires to SCL,SDA,VCC and GN. I don't understand how I should add those 1K9 resistors, where to solder them. As in the Adafruit tutorial they were left out I just went ahead without them. But when I connect VCC to 5V, GN to ground, SCL to P1 pin 5 and SDA to P1 pin 3 (rev2 board) nothing happens.

In the documentation I read that P1 pin3 has an Alt-0 function of SDA. Do I need to do something to get it to work?

Sorry for the stupid questions, but this is all new to me.

Hi-Z
Posts: 29
Joined: Wed Jan 02, 2013 8:19 pm
Location: Canuckistan

Re: RTC using P5 header

Sun Feb 17, 2013 4:59 pm

pgman wrote:I can't find an actual schematic for this board though.
This should be what you are looking for
http://www.emartee.com/Attachment.php?name=42059.pdf

@poing
The RTC is a 5 volt device and the RPi is 3v3 on the GPIO pins. If you connect the RTC directly to GPIO pins then there is the possibility of causing damage to RPi. You will require a voltage level converter like the following:
http://www.ebay.com/itm/IIC-I2C-interfa ... 0950932765
You MUST have pull up resistors on the SDA, SCLK lines as shown in the above schematic as R2 & R3 .... However, the level converter already has them installed on both the 3v3 side and the 5V side, so there would be no need to have them duplicated on the RTC (but don't fret if they are already installed)

Hi-Z
Posts: 29
Joined: Wed Jan 02, 2013 8:19 pm
Location: Canuckistan

Re: RTC using P5 header

Sun Feb 17, 2013 5:06 pm

To clarify the previous post:

If the pull up resistors are connected to 5 volts then connecting directly to the (3v3) GPIO pins is bad.
If the pull up resistors are connected to 3v3 then connecting to the GPIO pins is ok.

A level converter is still recommended to prevent accidentally applying the wrong voltage.

pgman
Posts: 22
Joined: Sun Jan 06, 2013 8:34 pm

Re: RTC using P5 header

Sun Feb 17, 2013 5:26 pm

The pi already has 1k8 resistors to 3.3v on the I2C lines of the P1 header. Hence the reason for saying you need to remove R2 & R3 from this board. If you look in the original Adafruit tutorial it says that the 2k2 resistors should not be used.

On the P5 header there are no pull-ups as the I2C is not the default mode for those pins.

I2C chips are open collector so will do nothing if there are no pull-ups on the lines. Note that only one pull-up resistor is needed on each line.

Do agree though that the level convertor is the best approach if you are connecting decvices that may already have pull-ups on them. Make sure that it is a bi-directional converter, as the I2C data bus is bi-directional.

marosh123
Posts: 1
Joined: Thu Apr 04, 2013 6:36 am

Re: RTC using P5 header

Thu Apr 04, 2013 7:26 am

hi guys,
I was completely lost in the pull-up resistors, but I would like to ask somethink else.
Is there an easy way to set up alternative function Alt0 for P5 header? That's what aTao wrote.
Thank you for your reply.

pgman
Posts: 22
Joined: Sun Jan 06, 2013 8:34 pm

Re: RTC using P5 header

Thu Apr 04, 2013 1:12 pm

Try not to ignore the pull-up resistor issue. The ones on these board will pull the clock and data lines up to 5v. The GPIO pins are only meant to use 3.3v, so its important to remove any pull-up resistors that go to the 5v line, and instead connect new ones to the 3.3v supply (this isnt needed if using the P1 header as they are already in place).

As Tao indicated the default function of GPIO28 and GPIO29 are not the I2C0 bus, (P5 pins 3&4), so these will need some code creating to make the setting change. Have a root around the forums, I've seen it expained.

I never got round to implementing the I2C on the P5 pins though as I plan to use the camera module as soon as it is for sale, and setting GPIO28 & GPIO29 to I2C0 will remove that function from the S5 header (GPIO0 & GPIO1), and as I understand it, I2C0 is required to control the camera. It 'may' be possible to attach wires to the S5 header, but there are some pretty fine tracks going to it.

I did end up using the P1 header, with some very fine wire connected to the bottom of the pins, so that an expansion socket can still be insert on top of the header. I've still got some issues with it though but it may be due to a bad clock chip (it seems to drift an awfull lot more than it should).

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