0

I am trying to control a real-time clock module PCF8563 with python. I connected the module to my Raspberry Pi and I am able to read the clock from the module. I would like to use the internal alarm functionality of the module and control this feature from python.

There are two Python libraries I know, one here and one here.

The first one works great but lacks the support for the alarm functionality. The second one cover most of the functions but rely on quick2wire library which I do not know and do not want to use. I actually would like to improve the first one.

I found also a good documented how-to related to this module, but sadly it is for Arduino.

My current problem is, how can I read and set specific bits from the bytes I get from the registries over the i2c bus. With:

import smbus

bus = smbus.SMBus(0)
returndata = bus.read_byte_data(0x51, 0x01)

I get one byte from registry 0x01. I need to translate the return vale from bcd to decimal, but how can I get the third bit of this byte ? And how can I change it.

Taken from the Arudino how-to:

... check bit 3 of the register at 0x01 (the “AF” alarm flag bit). If it’s 1 – it’s alarm time! Then you can turn the alarm off by setting that bit to zero. Using hardware, first set bit 1 of register 0x01 to 1 – then whenever an alarm occurs, current can flow into pin 3 of the PCF8563.

x29a
  • 1,761
  • 1
  • 24
  • 43
karlitos
  • 1,604
  • 3
  • 27
  • 59

1 Answers1

1

The short answer was: learning how to use the bit-masks and how bit-shifting works. The German Wikipedia site was quite helpful. After checking the data-sheet for the PCF8563 I was able to implement some of the missing functionality. For further progress see my GitHub repository.

I found probably an error in the Arduino related How-To, I noticed the author, see the comments under the linked article.

karlitos
  • 1,604
  • 3
  • 27
  • 59