Using Raspberry Pi 3 with Python IDLE 3.
I have hooked up a DS1307 to the 40 way connector and connected the 2 pull-ups to 3V3. When I run i2cdetect, I can see it at address 68. I can write to the device with hwclock -w and I read the time back using hwclock -r. It seems to work. If I remove the DS1307 from the board, nothing works. That is my test that all is ok.
1) The data sheet shows the DS1307 to have 0xd0 as it's i2c address. The RPi shows it to be 0x68. How does that work? That is confusing me.
2) I want to enable the DS1307 so that pin7 flashes an LED. I know I have to write to register 7 and send 0x40. This enable the SW output for 1Hz. I know this because I have done it on PIC devices many time.
I have tried i2cset -y 1 0x68 0x07 0x40 and a few other variations but it doesn't work. I want to flash the led so that I know for sure the i2c system is working properly. I am going small steps at a time and ultimately want to use many remote stations that I can address on the i2c bus.
In my PIC code, I send a 0xD0 because I am adding the read bit at the end. 7 bits for the address code and 1 bit for R/w.
7 bit address code gives 68 which is correct!
Wow! That was crazy. Took a while to see that!
Now to work out why I can't turn the LED on. Bet it is easy.
Adco wrote: I have hooked up a DS1307 to the 40 way connector and connected the 2 pull-ups to 3V3.
I2C-1 on header pins 3&5 already has pull ups installed.
Adco wrote: When I run i2cdetect, I can see it at address 68. I can write to the device with hwclock -w and I read the time back using hwclock -r. It seems to work. If I remove the DS1307 from the board, nothing works. That is my test that all is ok.
hwclock working implies to me that you've added a dtoverlay line to config.txt. You haven't mentioned that if you have.
Define "nothing". The Pi doesn't boot?
Adco wrote: 1) The data sheet shows the DS1307 to have 0xd0 as it's i2c address. The RPi shows it to be 0x68. How does that work? That is confusing me.
I2C uses 7 bits of address and 1 bit of direction. Some device spec sheets quote both together, so technically DS1307 it should be addressed as 0xD0 and 0xD1. Linux (and others) specify just the 7bits of address, which is 0x68.
Adco wrote: 2) I want to enable the DS1307 so that pin7 flashes an LED. I know I have to write to register 7 and send 0x40. This enable the SW output for 1Hz. I know this because I have done it on PIC devices many time.
So BIT 4 needs to be set, and that would be 0x10.
I have hooked up a DS1307 to the 40 way connector and connected the 2 pull-ups to 3V3.
When I run i2cdetect, I can see it at address 68. I can write to the device with hwclock -w and I read the time back using hwclock -r. It seems to work. If I remove the DS1307 from the board, nothing works. That is my test that all is ok.
"Nothing" means I can't access the RTC when it is removed (obviously) so it tells me that I was addressing it and now that's it's out, I'm not. A test to say I was seeing it.
Yeh, I worked that out. See my next post.
A typo. I did mean 0x10. I have that in my code. Still no response.
Tomorrow is another day. Thanks for the reply.
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 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.
Adco wrote: 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.
Post the results of i2cdetect.
As I commented earlier, it sounds like you have loaded the kernel driver for ds1307, which will then show up as UU, not 0x68. If you have a kernel driver bound to an address, then I believe all other accesses to it will be blocked, hence it is busy.
I can't post pic of i2cdetect result. It is on another machine. I can tell you that address 68 shows UU. Must I remove the DS1307 driver? Where is it?
(This is why we get annoyed at cross-posting - the multiple threads end up covering the same ground).
I do understand. I am only going to talk to you guys via the other thread.