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

Re: RTC adress?

Expand Messages
  • 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 1 of 9 , Sep 7, 2007
    • 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 2 of 9 , Sep 7, 2007
      • 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 3 of 9 , Sep 7, 2007
        • 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 4 of 9 , Sep 9, 2007
          • 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.