Loading ...
Sorry, an error occurred while loading the content.

RE: [nslu2-general] RTC adress?

Expand Messages
  • Paul Hutchinson
    The wiki shows two possible RTC chips used in NSLU2 s, Xicor X1205 or,ST Microelectronics M41T11. The manufacturers data sheets give the addresses as: X1205 =
    Message 1 of 9 , Sep 5 12:15 PM
    • 0 Attachment
      The wiki shows two possible RTC chips used in NSLU2's, Xicor X1205 or,ST
      Microelectronics M41T11. The manufacturers data sheets give the addresses
      as:

      X1205 = 1101111X (binary, X= R/W bit)
      M41T11 = 1101000X (binary, X= R/W bit)

      Paul

      > -----Original Message-----
      > From: nslu2-general@yahoogroups.com On Behalf Of joakimmaartensson
      > Sent: Monday, September 03, 2007 4:10 PM
      >
      > Does anybody know the adress of the RTC? I'm going to try to hook up a
      > Maxim DS2482 1-Wire master to the slug, but I don't want the adress to
      > conflict with the RTC...
      >
      > Does anybody know if the device will show up automatically under /dev/ ?
      >
      > Thanks!
    • Greg Holdren
      ... From: joakimmaartensson To: Sent: Monday, September 03, 2007 1:09 PM Subject:
      Message 2 of 9 , Sep 6 1:31 AM
      • 0 Attachment
        ----- Original Message -----
        From: "joakimmaartensson" <stampedehockey@...>
        To: <nslu2-general@yahoogroups.com>
        Sent: Monday, September 03, 2007 1:09 PM
        Subject: [nslu2-general] RTC adress?


        > Does anybody know the adress of the RTC? I'm going to try to hook up a
        > Maxim DS2482 1-Wire master to the slug, but I don't want the adress to
        > conflict with the RTC...
        >
        > Does anybody know if the device will show up automatically under /dev/ ?
        >
        > Thanks!
        >

        It appears that the i2c address question was answered already.

        The device wont show up automaticlly in /dev. Make a /dev/i2c[number] for
        each i2c device used. i.e. for i2c0,

        mknod -m 666 /dev/i2c[number] c 89 [number] where [number] is 0, 1,
        2, etc.

        In your code attach the i2c address (dev_addr) to the /dev/i2c0 device.
        Assuming C, for example:

        int openi2c(int dev_addr){

        if ((file = open("/dev/i2c0", O_RDWR)) < 0) {
        printf("open error!\n");
        return(-1);
        }

        if (ioctl(file,I2C_SLAVE_FORCE,dev_addr) < 0) {
        printf("address error!\n");
        return(-2);
        }
        return(file);
        }

        I actually created i2c0 and set it to the RTC i2c address and was able to
        read and write to the RTC. I have not connected another i2c device to the
        nslu2 yet.

        Internal reg. addresses 0x30 to 0x37 on the X1205. (sec, min, hour, date,
        month, year lower, day offset, year upper)

        [root@slug i2c]# clock
        read: 0x17 0x21 0x81 0x6 0x9 0x7 0x5 0x20

        The following page got me going with the C code and i2c.

        http://www.staton.us/electronics/open_slug/i2c_interface.html (Ken Staton's
        page) linked from the wiki
        http://www.nslu2-linux.org/wiki/Info/PinoutOfI2CPort

        Greg
      • joakimmaartensson
        Thanks to both Greg and Paul. My first plan was to use an already existing program, but now I m thinking it could be nice to see if it works at all first! :-)
        Message 3 of 9 , Sep 7 8:29 AM
        • 0 Attachment
          Thanks to both Greg and Paul.
          My first plan was to use an already existing program, but now I'm
          thinking it could be nice to see if it works at all first! :-)

          However, I have no idea on what to install to be able to make a
          program. Any tips? Have programmed in C++ before, but C would also work...
          I'm using an Unslung NSLU2, however I only have a 512MB flashcard -
          can I install a development suite (if too big) to the attached HDD?

          Thanks!

          --- In nslu2-general@yahoogroups.com, "Greg Holdren" <greghol@...> wrote:
          >
          >
          > ----- Original Message -----
          > From: "joakimmaartensson" <stampedehockey@...>
          > To: <nslu2-general@yahoogroups.com>
          > Sent: Monday, September 03, 2007 1:09 PM
          > Subject: [nslu2-general] RTC adress?
          >
          >
          > > Does anybody know the adress of the RTC? I'm going to try to hook up a
          > > Maxim DS2482 1-Wire master to the slug, but I don't want the adress to
          > > conflict with the RTC...
          > >
          > > Does anybody know if the device will show up automatically under
          /dev/ ?
          > >
          > > Thanks!
          > >
          >
          > It appears that the i2c address question was answered already.
          >
          > The device wont show up automaticlly in /dev. Make a
          /dev/i2c[number] for
          > each i2c device used. i.e. for i2c0,
          >
          > mknod -m 666 /dev/i2c[number] c 89 [number] where [number] is
          0, 1,
          > 2, etc.
          >
          > In your code attach the i2c address (dev_addr) to the /dev/i2c0 device.
          > Assuming C, for example:
          >
          > int openi2c(int dev_addr){
          >
          > if ((file = open("/dev/i2c0", O_RDWR)) < 0) {
          > printf("open error!\n");
          > return(-1);
          > }
          >
          > if (ioctl(file,I2C_SLAVE_FORCE,dev_addr) < 0) {
          > printf("address error!\n");
          > return(-2);
          > }
          > return(file);
          > }
          >
          > I actually created i2c0 and set it to the RTC i2c address and was
          able to
          > read and write to the RTC. I have not connected another i2c device
          to the
          > nslu2 yet.
          >
          > Internal reg. addresses 0x30 to 0x37 on the X1205. (sec, min, hour,
          date,
          > month, year lower, day offset, year upper)
          >
          > [root@slug i2c]# clock
          > read: 0x17 0x21 0x81 0x6 0x9 0x7 0x5 0x20
          >
          > The following page got me going with the C code and i2c.
          >
          > http://www.staton.us/electronics/open_slug/i2c_interface.html (Ken
          Staton's
          > page) linked from the wiki
          > http://www.nslu2-linux.org/wiki/Info/PinoutOfI2CPort
          >
          > Greg
          >
        • Marcel Nijenhof
          ... The best solution is a cross build environment. In that case you can use a normal pc as compile system and run the compiled packages on the slug. Most off
          Message 4 of 9 , Sep 7 10:07 AM
          • 0 Attachment
            On Fri, 2007-09-07 at 15:29 +0000, joakimmaartensson wrote:
            > However, I have no idea on what to install to be able to make a
            > program. Any tips? Have programmed in C++ before, but C would also
            > work...
            > I'm using an Unslung NSLU2, however I only have a 512MB flashcard -
            > can I install a development suite (if too big) to the attached HDD?

            The best solution is a cross build environment. In that case you
            can use a normal pc as compile system and run the compiled packages
            on the slug.

            Most off the optware packages are build that way. For unslung and
            probably also for openslug it is possible to use the optware environment
            to compile code for the slug.

            See:
            http://www.nslu2-linux.org/wiki/Optware/AddAPackageToOptware

            It is also possible to use the openembed tools to create the toolchain
            and use that.

            --
            marceln
          • joakimmaartensson
            ... The reason for building it on the slug is that I m using Windows on the PC. I m not planning on alot of programming, basicly all I want to do is test to
            Message 5 of 9 , Sep 7 10:34 AM
            • 0 Attachment
              > The best solution is a cross build environment. In that case you
              > can use a normal pc as compile system and run the compiled packages
              > on the slug.
              >
              > Most off the optware packages are build that way. For unslung and
              > probably also for openslug it is possible to use the optware environment
              > to compile code for the slug.
              >
              > See:
              > http://www.nslu2-linux.org/wiki/Optware/AddAPackageToOptware
              >
              > It is also possible to use the openembed tools to create the toolchain
              > and use that.
              >
              > --
              > marceln
              >

              The reason for building it on the slug is that I'm using Windows on
              the PC.
              I'm not planning on alot of programming, basicly all I want to do is
              test to see if the device is hooked up correctly... For example
              reading the Status Register of my Maxim DS2482-800, and see if it
              responds!
            • joakimmaartensson
              Greg: You wouldn t mind sharing your test application? Or is the i2c-device address hard-coded, instead of passed as an argument?
              Message 6 of 9 , Sep 7 11:35 AM
              • 0 Attachment
                Greg: You wouldn't mind sharing your test application? Or is the
                i2c-device address hard-coded, instead of passed as an argument?
              • Greg Holdren
                ... From: joakimmaartensson To: Sent: Friday, September 07, 2007 11:35 AM Subject:
                Message 7 of 9 , Sep 7 10:21 PM
                • 0 Attachment
                  ----- Original Message -----
                  From: "joakimmaartensson" <stampedehockey@...>
                  To: <nslu2-general@yahoogroups.com>
                  Sent: Friday, September 07, 2007 11:35 AM
                  Subject: [nslu2-general] Re: RTC adress?


                  > Greg: You wouldn't mind sharing your test application? Or is the
                  > i2c-device address hard-coded, instead of passed as an argument?
                  >

                  I have a 2.5" 10gig drive on my nslu2.

                  The i2c address is hardcoded in the program along with the offset of 0x30 to
                  get to the data regesters of the clock. You can change these for the 1 wire
                  i2c device when you get an environment set up for compiling (native or
                  cross). I used the native compiler that I set up a few years ago.

                  crosstool-native - 0.28-rc37-5 -
                  crosstool-native-arch-bin - 0.28-rc37-5 -
                  crosstool-native-arch-inc - 0.28-rc37-5 -
                  crosstool-native-arch-lib - 0.28-rc37-5 -
                  crosstool-native-bin - 0.28-rc37-5 -
                  crosstool-native-inc - 0.28-rc37-5 -
                  crosstool-native-lib - 0.28-rc37-5 -

                  I just followed the wiki native compile instructions to get on my system
                  with ipkg. I would recommend a small harddrive, it will speed up the
                  development.

                  I tared up my i2c directory and placed it here:
                  http://pages.sbcglobal.net/greghol/nslu2/nslu2_i2c.tar

                  Make the i2c device as mentioned in the previous email and try the clock and
                  i2ctest program. (I think it is staticly linked so it should run??) Clock
                  just dumps the time and date in raw format. i2ctest writes 0 to the seconds
                  reg and then dumps it like the clock program. (ignore the write values
                  displayed, its just debug showing that it is putting the rtc in write mode)

                  make will compile the clock prog from clock.c and makei2ctest will compile
                  the i2ctest using i2clib.c.

                  In any case you can just change the i2c address (addr) and then the internal
                  register (reg)to what you want to read and/or write to the regs of the 1wire
                  device. Read your datasheet good. I had problems in wrting to the clock. I
                  guess I glazed over the part where I needed to write a 0x02 and then a 0x06
                  to the base reg first. I had the logic analyzer out debugging it for a few
                  nights.
                  Re-read the datasheet and bingo it worked. :)

                  Greg
                • joakimmaartensson
                  Thanks for sharing the code! Unfortunatly my attempts on installing optware-devel whent haywire... Guess I ll have to go buy a small HDD instead of a
                  Message 8 of 9 , Sep 9 7:07 AM
                  • 0 Attachment
                    Thanks for sharing the code!
                    Unfortunatly my attempts on installing optware-devel whent haywire...
                    Guess I'll have to go buy a small HDD instead of a thumbdrive!

                    Still rewrote the code however! ;-)

                    A few questions first.. In clock.c, is buf[0] = 0x00 the first of two
                    bytes to get to the timetable?

                    Second, doesn't ioctl() care about the last bit (R/W) in the address or
                    is it added when it gets a write() or read()?

                    If someone feels like compiling this code, feel free to do so (and
                    please post the resulting files ;) )

                    ds2482.c
                    #include <stdio.h>
                    #include <sys/types.h>
                    #include <fcntl.h>
                    #include <linux/i2c-dev.h>


                    int main(){

                    int file;
                    int addr = 0x18; /* DS2482-800 address (hopefully)*/
                    unsigned short reg = 0xf0; /* Status Register */
                    char buf[10];
                    int n;


                    buf[0] = 0xe1; /* Set Read Pointer */
                    buf[1] = reg; /* Status Register */

                    file = openi2c(addr);
                    if(file < 0)
                    exit(0);

                    printf("Set Read Pointer (E1h), and select Status Register (F0h)... ");
                    n = writei2cbuf(file, buf, 2);
                    if (n < 0)
                    exit(1);

                    printf("Reading Status Register: ");
                    n = readi2cbuf(file, buf, 1);
                    if (n < 0) {
                    exit(1);
                    } else {
                    printf("0x%x",buf[0]);
                    }

                    closei2c(file);
                    }
                    i2clib.c

                    #include <stdio.h>
                    #include <sys/types.h>
                    #include <fcntl.h>
                    #include <linux/i2c-dev.h>

                    int file;

                    int openi2c(int dev_addr){

                    if ((file = open("/dev/i2c0", O_RDWR)) < 0) {
                    printf("open error!\n");
                    return(-1);
                    }

                    if (ioctl(file,I2C_SLAVE_FORCE,dev_addr) < 0) {
                    printf("address error!\n");
                    return(-2);
                    }
                    return(file);
                    }

                    int writei2cbuf(int file, char *buffer, int count){

                    int n;

                    n=write(file, buffer, count);
                    if (n != count) {
                    printf("write error! %d\n",n);
                    return(-1);
                    }
                    return(0);
                    }

                    int writei2cchar(int addr, char data){

                    int n;
                    char databuf[8];
                    databuf[0]=(addr>>8 & 0xff);
                    databuf[1]=(addr&0xff);
                    databuf[2]=data;

                    n=write(file,databuf,3);
                    if (n != 3) {
                    printf("write error! %d\n",n);
                    return(-1);
                    }
                    return(data);
                    }

                    int readi2cbuf(int file, char *buffer, int count){

                    int n;

                    n = read(file, buffer, count);
                    if (n != count) {
                    printf("read error! %d\n",n);
                    return(-2);
                    } else {
                    return(n);
                    }
                    }

                    int readi2cchar(int addr){

                    int n;
                    char databuf[8];
                    databuf[0]=(addr>>8 & 0xff);
                    databuf[1]=(addr&0xff);

                    n=write(file,databuf,2); /* set address for random read */
                    if (n != 2) {
                    printf("addr write error! %d\n",n);
                    return(-1);
                    }

                    n=read(file,databuf,1);
                    if (n != 1) {
                    printf("read error! %d\n",n);
                    return(-2);
                    } else {
                    return(databuf[0]);
                    }
                    }


                    int closei2c(){

                    close(file);
                    }

                    Am I assuming correctly that read/writei2cchar() isn't needed for my
                    source? Didn't wan't to remove it just in case..

                    make
                    gcc -c i2clib.c -fpic
                    #gcc -shared i2clib.o -Xlinker -export-dynamic -o i2c.so
                    gcc clock.c i2clib.o -o clock





                    [Non-text portions of this message have been removed]
                  Your message has been successfully submitted and would be delivered to recipients shortly.