0
\$\begingroup\$

I want to interface a DS3231 RTC module with my Raspberry Pi 3b model in a project. As we all know this RTC module supports only I2C communication, where pin no. 3 and 5 of the Raspberry Pi are used for I2C communication.

I've already designed my PCB and used those pins reserved for GPIO purposes to control relays, but the UART pins are exposed (not used).

So is there any method to interface RTC via UART or any alternative solution?

\$\endgroup\$

3 Answers 3

0
\$\begingroup\$

Method 1: Bitbang the UART pins as GPIO

This will work, albeit much more slowly than hardware I2C.

Method 2: Put a dedicated microcontroller in between

You could put a little microcontroller, perhaps like the ATtiny25, to drive the RTC chip and communicate over serial through the UART.

\$\endgroup\$
7
  • \$\begingroup\$ method 2 can be considered but not a cost-effective solution \$\endgroup\$
    – John Mist
    Dec 30, 2022 at 11:34
  • \$\begingroup\$ At under a euro for many MCU, it might be. If's very helpful if you put your constraints in your question: do you have a budget in mind? What quantity of units are you making? \$\endgroup\$
    – jonathanjo
    Dec 30, 2022 at 11:40
  • \$\begingroup\$ I've already ordered 20 PCBs so redesigning and further modification are not possible. \$\endgroup\$
    – John Mist
    Dec 30, 2022 at 11:47
  • \$\begingroup\$ How is the RTC connected? \$\endgroup\$
    – jonathanjo
    Dec 30, 2022 at 12:02
  • \$\begingroup\$ there is no RTC on PCB that's why I want to interface a module but I2C pins are reserved \$\endgroup\$
    – John Mist
    Dec 30, 2022 at 12:22
1
\$\begingroup\$

There is a 2nd I2C interface available using GPIO23 as SDA and GPIO24 as SCL. The INT pin can e.g. be connected to GPIO27. The existing RTC drivers can be configured to use this port. I implemented this using a PCF8523T RTC, but I assume using DS3231 is similar.

My entry in "/boot/config.txt" was like this: dtoverlay=i2c-rtc-gpio,pcf8523,i2c_gpio_sda=23,i2c_gpio_scl=24

\$\endgroup\$
0
\$\begingroup\$

No. You cannot interface DS3231 using UART. Your 2 options are either re-design your board to leave I2C pins free (probably the best option) Or implement software I2C on free pins (which is basically triggering GPIO pins in a smart way to emulate I2C communication) There are soft I2C libraries available like this one for example.

\$\endgroup\$
2
  • \$\begingroup\$ Re-design is not possible cuz I've already ordered a bunch of PCB but I've to have a look on option 2 \$\endgroup\$
    – John Mist
    Dec 30, 2022 at 11:36
  • \$\begingroup\$ @JohnMist Well, that's the price you pay for taking up interface pins as GPIOs :) \$\endgroup\$
    – floppydisk
    Dec 30, 2022 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.