Olimex Support Forum

OLinuXino Android / Linux boards and System On Modules => A20 => Topic started by: Anushka on September 17, 2022, 09:27:11 AM

Title: I2C and RTC Communication
Post by: Anushka on September 17, 2022, 09:27:11 AM
I am using PCF8583 RTC with my A20-Olinuxino-Lime2 with I2C communication but my oimex doesn't detect rtc. I am using PB18(SCK) and PB19(SDA) as /dev/i2c-1 port pins.
The slave address of my rtc is A2h. This is my code:

from  pyA20Lime2 import i2c

i2c.init("/dev/i2c-1")
i2c.open(0xA2)
i2c.write([0x1A, 0x20])
i2c.close()

After running this code I get following error:
Traceback (most recent call last);
  File "/home/olimex/Desktop/i2c.py", line 4, in <module>
    i2c.open(0xA2)
OSError:  [Error 22] Invalid argument

I want to use rtc with my olimex for project what should I do for it to work???
Title: Re: I2C and RTC Communication
Post by: LubOlimex on September 19, 2022, 08:08:38 AM
What Linux image are you using? Check if that i2c you are trying to use free and enabled with "olinuxino-overlay". Not sure if the python modules work with latest images, maybe use the information we published in chapter "8.7. I2C" on page 31 from this guide:

https://github.com/OLIMEX/OLINUXINO/blob/master/DOCUMENTS/OLIMAGE/Olimage-guide.pdf
Title: Re: I2C and RTC Communication
Post by: Anushka on September 19, 2022, 02:30:58 PM
I am using A20-Olinuxino-bullseye-base-20211130-145129 Linux image. I have enabled my i2c by "olinuxino-overlay" already.
Above information is not sufficient. Can you please elaborate more on how to connect external devices through I2C ports. My device has address A0h,A2h.
Title: Re: I2C and RTC Communication
Post by: LubOlimex on September 22, 2022, 10:27:55 AM
Well probably the easiest way is using one of the ready Linux drivers for your RTC. Like this one:

https://github.com/torvalds/linux/blob/master/drivers/rtc/rtc-pcf8583.c