element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
STEM Academy
  • Learn
  • Learning Center
  • STEM Academy
  • More
  • Cancel
STEM Academy
Forum Rasp Pi - MCP23017  and RTC DS3231 in harmony
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join STEM Academy to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 4 replies
  • Subscribers 49 subscribers
  • Views 1174 views
  • Users 0 members are here
  • stem space
Related

Rasp Pi - MCP23017  and RTC DS3231 in harmony

Former Member
Former Member over 12 years ago

Hello there,

I've got three raspberry pis rev 2's (wheezy 12-2012) that have been purring away for over a year now performing simple logging tasks. Attached to each of them (SDA/SCL) is a chronodot DS3231 which has kept time accurately as glossy brochure assured.

Now I wish to expand the capabilities of each  PI using the MCP23017  port expander. I've found plenty of tutorials and I can make LED's blink as per bash or python script. What I havent found easy to get my head around is attaching an RTC to this chip. The current RTC does a wonderful job of keeping time around both warm and cold restarts which is important to the logging I analyse. I am not using NTP btw.

This is closest I have found

http://www.puzsar.hu/raspberry_ext/

but the original page/site has gone.

How do I wire the clock to the MCP23017?, Is that two GPA's to the RTC SDA/SCL? How does the raspi OS 'see' through MCP23017 at restart for the local clock to be set?

 

Thank you

Anthony

  • Sign in to reply
  • Cancel
Parents
  • Former Member
    0 Former Member over 12 years ago

    Thank you shabaz! Link was great.

    I think I'm getting a clearer picture. I thought the mcp23017 chip WAS the i2c bus that you attach devices to. Thanks for clearing up that inaccuracy.

     

    If I am using the chronodot DS3231 does it have a default address on the i2c bus? The MCP23017 has a 3 bit address (A0,A2,A2) while I2C handles 8 bit addresses. Is that the x068 address indicated here

    http://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi/set-rtc-time

    I messed a bit with i2cdetect and i2cdump, and found UU though that maybe because a driver has locked it(?). When I add the mpc23017 chip it's address will need to be different. Any idea how to determine it's (RTC) address?

    I better ask, are the 3 bit / 8 bit addresses related?

    Here's some output....

     

    pi@dev-x0a0003 ~ $ sudo i2cdetect -l

    i2c-0   i2c             bcm2708_i2c.0                           I2C adapter

    i2c-1   i2c             bcm2708_i2c.1                           I2C adapter

    and....

    pi@dev-x0a0003 ~ $ sudo i2cdetect 1

    WARNING! This program can confuse your I2C bus, cause data loss and worse!

    I will probe file /dev/i2c-1.

    I will probe address range 0x03-0x77.

    Continue? [Y/n]

         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f

    00:          -- -- -- -- -- -- -- -- -- -- -- -- --

    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

    60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --

    70: -- -- -- -- -- -- -- --

     

    Also

    How should you terminate the SDA/SCL bus? GND?

     

    I appreciate your time shabaz, thank you! I enjoy this stuff

     

    Anthony

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Former Member
    0 Former Member over 12 years ago

    Thank you shabaz! Link was great.

    I think I'm getting a clearer picture. I thought the mcp23017 chip WAS the i2c bus that you attach devices to. Thanks for clearing up that inaccuracy.

     

    If I am using the chronodot DS3231 does it have a default address on the i2c bus? The MCP23017 has a 3 bit address (A0,A2,A2) while I2C handles 8 bit addresses. Is that the x068 address indicated here

    http://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi/set-rtc-time

    I messed a bit with i2cdetect and i2cdump, and found UU though that maybe because a driver has locked it(?). When I add the mpc23017 chip it's address will need to be different. Any idea how to determine it's (RTC) address?

    I better ask, are the 3 bit / 8 bit addresses related?

    Here's some output....

     

    pi@dev-x0a0003 ~ $ sudo i2cdetect -l

    i2c-0   i2c             bcm2708_i2c.0                           I2C adapter

    i2c-1   i2c             bcm2708_i2c.1                           I2C adapter

    and....

    pi@dev-x0a0003 ~ $ sudo i2cdetect 1

    WARNING! This program can confuse your I2C bus, cause data loss and worse!

    I will probe file /dev/i2c-1.

    I will probe address range 0x03-0x77.

    Continue? [Y/n]

         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f

    00:          -- -- -- -- -- -- -- -- -- -- -- -- --

    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

    60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --

    70: -- -- -- -- -- -- -- --

     

    Also

    How should you terminate the SDA/SCL bus? GND?

     

    I appreciate your time shabaz, thank you! I enjoy this stuff

     

    Anthony

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • shabaz
    0 shabaz over 12 years ago in reply to Former Member

    Hi Anthony,

     

    The first byte of I2C transmission contains the address, and all devices have a 7-bit (or 8-bit depending on how you look at it) address. These are hard-coded in devices, but some device (like the MCP23017) have a few bits that are controlled by pins, for some address adjustment. Since the MCPxx has three pins (A0..2), this mean you could connect 2^3 (i.e. 8) of them on the same I2C bus, all with unique addresses. Figure 1-2 in the MCP datasheet shows the values of the remainder bits of the address which are hard-coded inside the device.

    In a similar way, the DSxxx device you refer to has a hard-coded address too - it cannot be changed. The DS device does not have any A0,etc pins, so there is no flexibility to modify the address slightly. You could only connect one to the bus. The 0x68 mentioned refers to the adafruit tutorial, which is using a different DS1307 device. The datasheet for the DS1307 shows (in figure 4) the address to be 0x68 (1101000, i.e. binary 110 representing 6, and 1000 representing 8). The DS3231 datasheet will have a similar diagram, with a different value.

    The bus doesn't actually use any termination, there will be a couple of resistors already on the Pi (I'm guessing), these create the bus default high state, and then any device on the bus is free to pull it low to begin toggling data on the wires. The pi is designated the master device, and the MCP and DS devices are slaves (they can only operate as slaves, they have no capability inside the chip to do anything else).

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
  • Former Member
    0 Former Member over 12 years ago in reply to shabaz

    Thank you shabaz, I understand now

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube