element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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 Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum has anyone got a linux kernel driver for mcp79410 rtc  -solved
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 13 replies
  • Subscribers 663 subscribers
  • Views 4190 views
  • Users 0 members are here
  • mcp79410
  • rtc
  • raspberry_pi
  • rtcc
  • raspberrypi
  • kernel
  • linux
Related

has anyone got a linux kernel driver for mcp79410 rtc  -solved

Former Member
Former Member over 13 years ago

I originally ordered a BQ320000DR from farnell to make a rtc module for my raspberrypi. there is a kernel driver for this rtc i2c chip.

unfortunately, the chip still hasn't arrived, and in the mean-time I ordered a MCP79410-I/SN RTCC (i2c).

I can see this on the i2c bus (address 6F) but there doesn't appear to be kernel drivers for this device (mcp7941x series)

If there was another chip which was functionally the same, but with a kernel driver, I could just copy it's driver and change the chip name throughout the code.

 

does anyone know of a i2c chip for which there is kernel support, which is similar to the mcp79410?

 

I have the list of currently supported rtc chips (see drivers/rtc in the kernel source)

 

88pm80x,88pm860x,ab3100,ab8500,at32ap700x,at91rm9200,at91sam9,au1xxx,bfin,bq32k,bq4802,cmos,coh901331,core,da9052,davinci,dev,dm355evm,

ds1216,ds1286,ds1302,ds1305,ds1307,ds1374,ds1390,ds1511,ds1553,ds1672,ds1742,ds3232,ds3234,efi,em3027,ep93xx,fm3130,generic,imxdi,isl12022,

isl1208,jz4740,lib,lpc32xx,ls1x,m41t80,m41t93,m41t94,m48t35,m48t59,m48t86,max6900,max6902,max8925,max8998,mc13xxx,mpc5121,mrst,msm6242,

mv,mxc,nuc900,omap,pcap,pcf2123,pcf50633,pcf8563,pcf8583,pl030,pl031,pm8xxx,proc,ps3,puv3,pxa,r9701,rp5c01,rs5c313,rs5c348,rs5c372,rv3029c2,

rx8025,rx8581,s35390a,s3c,sa1100,sh,spear,starfire,stk17ta8,stmp3xxx,sun4v,sysfs,tegra,test,tile,twl,tx4939,v3020,vr41xx,vt8500,wm831x,wm8350,x1205

 

thanks

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

    creates the /dev/rtc0 device, and after a bit of prodding*, hwclock -w set the time on the rtc, and hwclock -s can now be used in /etc/rc.d/rc.local to set the system time from the rtc (and hwclock -r shows the rtc time and date)

    *(to explain the prodding. initially after running above, I got ioctl errors when running hwclock. I then did

    There's a bit in one of the registers needs setting to start the oscillator running, probably you'll have problems until the oscilaltor is running and the initial date/time is set. Theoretically you only need to do it once - or at least until you loose both main power and battery.

     

    I'd imagine you could do it properly with i2cset having read the datasheet to find the right bit.

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

    i've looked at the datasheet, and according to it, one should set the highest bit (bit7 if you start at bit0) to 1 to start the oscillator. because the ports are not symetrical (you read from control address 0x6f for the rtc registers, but write to 0x6e) you have to do things a little more manually. -update: following tests, it would appear that dispite what the datasheet says, you can only write using the same control address as the read address.

    get byte from location 0 and i2c0 location 0x6f.

    HEXVAL=`i2cdump -f -r 0-0 -y 0 0x6f b|tail -n1|awk '{printf("%#x\n",$2)}'`  

    then or the value with 0x80 to turn on the oscillator bit

     

    NEWHEX=`echo $HEXVAL|awk '{printf("%#x\n", or($1,0x80)) }'`

     

    then write the new value back to the rtc . note: the rtc driver must be unloaded to sucessfully run i2cset on the rtc. even with -f it will not write unless you   rmmod rtc_ds1307

    i2cset -f -y 0 0x6f 0 $NEWHEX

     

    you can now reload the driver  modprobe i2c:mcp7941x

    and if it hasn't been configured, echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-0/device/new_device

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

    below is a sample script I wrote which does the turning on/off of the oscillator on the mcp79410 rtc usual disclaimer. it works for me. try it at your own peril. i release it public domain. it probably works on all sorts of distributions, but is only tested on slackware 14.0 with custom 3.6.1 kernel with rtc support compiled in and rtc-ds1307 compiled as a module. (and it requires i2c-tools to be installed, and i2c-dev module to be loaded.)

     

    #!/bin/sh
    #this must be run as root.
    if [ "`id -u`" != 0 ]; then
      echo "this script must be run with root priviledges to access the hardware"
      exit 1
    fi
    #and i2c-dev needs to be installed
    if [ ! -e /usr/sbin/i2cdetect ]; then
      echo "you must install i2c-tools package to be able to configure"
      echo "devices on the i2c buses."
      if [ -e /etc/slackware-version ]; then
        echo "you can build a package using the slackbuild from www.slackbuilds.org"
        echo "or by using sbopkg, or your method of choice"
      fi
      exit 1
    fi
    FORCEFLAG=""
    if [ -e /dev/rtc0 ]; then
      echo "warning. the kernel has already got the rtc driver loaded"
      echo "you will need to unload it with   rmmod rtc_ds1307"
      echo "then reload it with               modprobe i2c:mcp7941x"
      echo "when you have set the oscillator."
      exit 1
    fi
    #make sure we have a mcp7941x rtc present on the i2c bus
    RTC_READ_PORT="0x6f"
    #RTC_WRITE_PORT="0x6e"
    #write port doesn't seem to work but you can write to the read port!
    I2CBUS=""
    if [ -e /dev/i2c-0 ]; then
      #we have an i2c-0 bus so lets see if the rtc is here
      ISRTC_HERE=`i2cdetect -y 0|grep "60:"|cut -c50|awk '($1!="--") {print "YES"}'`
      if [ "$ISRTC_HERE" = "YES" ]; then
        I2CBUS=0
      fi
    fi
    if [ "$I2CBUS" = "" ]&&[ -e /dev/i2c-1 ]; then
      #clock wasn't on i2c-0 but we have an i2c-1 so lets check it
      ISRTC_HERE=`i2cdetect -y 1|grep "60:"|cut -c50|awk '($1!="--") {print "YES"}'`
      if [ "$ISRTC_HERE" = "YES" ]; then
        I2CBUS=1
      fi
    fi
    if [ "$I2CBUS" = "" ]; then
      echo "no mcp7941x rtc detected."
      exit 1
    fi
    echo i2cbus is $I2CBUS
    #now get the current seconds (bcd with oscillator control flag in top bit)
    #and switch the oscillator bit on by or'ing the output with 0x80
    HEXBYTE=`i2cdump $FORCEFLAG -r 0-0 -y $I2CBUS $RTC_READ_PORT b |tail -n1|awk '{print "0x" $2 }'`
    echo "hexbyte is $HEXBYTE which is $(($HEXBYTE))"
    
    if [ `echo $(($HEXBYTE))` -lt 128 ]; then
      echo "oscillator is not running"
      NEWHEXBYTE=`echo $(($HEXBYTE))|awk '{oscon=or($1, 128);printf("%#x\n", oscon) }'`
      echo "new hexbyte is $NEWHEXBYTE"
      #now lets write the new value to the writable address for the rtc
      #the writable address is the same as the read one, but with the 0 bit cleared
      i2cset $FORCEFAG -y $I2CBUS $RTC_READ_PORT 0 $NEWHEXBYTE b
      echo "started the oscillator"
    else
      echo "oscillator is already running"
      echo "do you want to stop the oscillator y/n:"
      read i
      if [ "$i" = "y" ]||[ "$i" = "Y" ]; then
        #remove top bit from byte
        NEWHEXBYTE=`echo $((HEXBYTE))|awk '{oscoff=and($1,127);printf("%#x\n",oscoff) }'`
        echo "new hexbyte is $NEWHEXBYTE"
        i2cset $FORCEFLAG -y $I2CBUS $RTC_READ_PORT 0 $NEWHEXBYTE b
        echo "stopped the oscillator"
      fi
    fi
    

    have fun :-)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • 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