Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. India
  4. How to use I2C functions to interface DS1307 with qt ?

How to use I2C functions to interface DS1307 with qt ?

Scheduled Pinned Locked Moved Unsolved India
7 Posts 5 Posters 3.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SHUBHAM SINGH RAO
    wrote on 20 May 2019, 04:27 last edited by VRonin
    #1

    Hello
    Problem Statement : To read data (calendar/time data) from DS 1307 in Qt
    My approach: I am using wiring-pi serial functions (digitalwrite, digital read, pinmode) to interface DS1307 by suitably turning on / off the pins of my hardware board and reading the data

    Problem Encountered so far: While using serial functions I m not able to read correct data from DS1307 everytime. Sometimes I read FF instead of correct data.

    Question - Is there any other way of reading correct data from DS1307 (using I2C functions or others)?

    Relevant Code of read function-

    unsigned char I2C_READ(void)
    {
        unsigned char read=0,kk=0;
        digitalWrite(2,HIGH);
        delay(1);
        for(int u=0;u<8;u++)
        {
        read<<=1;
        pinMode(2,INPUT);
        digitalWrite(3,HIGH);
        delay(1);
        kk=digitalRead(2);
        int fd= 1;
        int x= wiringPiI2CRead(fd);
      
     if((kk)==1)
        {
        read = (read | 1);
        }
        else
        {
        read=(read | 0);
        }
        digitalWrite(3,LOW);
        delay(1);
        }
        pinMode(2,OUTPUT);
         delay(1);
        return read;
     }
    
    P 1 Reply Last reply 20 May 2019, 12:53
    0
    • S SHUBHAM SINGH RAO
      20 May 2019, 04:27

      Hello
      Problem Statement : To read data (calendar/time data) from DS 1307 in Qt
      My approach: I am using wiring-pi serial functions (digitalwrite, digital read, pinmode) to interface DS1307 by suitably turning on / off the pins of my hardware board and reading the data

      Problem Encountered so far: While using serial functions I m not able to read correct data from DS1307 everytime. Sometimes I read FF instead of correct data.

      Question - Is there any other way of reading correct data from DS1307 (using I2C functions or others)?

      Relevant Code of read function-

      unsigned char I2C_READ(void)
      {
          unsigned char read=0,kk=0;
          digitalWrite(2,HIGH);
          delay(1);
          for(int u=0;u<8;u++)
          {
          read<<=1;
          pinMode(2,INPUT);
          digitalWrite(3,HIGH);
          delay(1);
          kk=digitalRead(2);
          int fd= 1;
          int x= wiringPiI2CRead(fd);
        
       if((kk)==1)
          {
          read = (read | 1);
          }
          else
          {
          read=(read | 0);
          }
          digitalWrite(3,LOW);
          delay(1);
          }
          pinMode(2,OUTPUT);
           delay(1);
          return read;
       }
      
      P Offline
      P Offline
      Pablo J. Rogina
      wrote on 20 May 2019, 12:53 last edited by
      #2

      @SHUBHAM-SINGH-RAO said in How to use I2C functions to interface DS1307 with qt ?:

      reading correct data from DS1307 (using I2C functions

      is there any reason you're not using the built-in I2C library from wiringPi?

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      S 1 Reply Last reply 25 May 2019, 11:08
      2
      • P Pablo J. Rogina
        20 May 2019, 12:53

        @SHUBHAM-SINGH-RAO said in How to use I2C functions to interface DS1307 with qt ?:

        reading correct data from DS1307 (using I2C functions

        is there any reason you're not using the built-in I2C library from wiringPi?

        S Offline
        S Offline
        SHUBHAM SINGH RAO
        wrote on 25 May 2019, 11:08 last edited by SHUBHAM SINGH RAO
        #3

        @Pablo-J.-Rogina
        Sorry for late response
        After your reply, I have been trying to implement I2C functions but I m unable to get read any data from DS 1307.
        Here my code goes:

         ReadI2C_function()
          { int fd;
            wiringPiSetup();
            ui->setupUi(this);
            fd = wiringPiI2CSetup(0X68);  //0X68 is the address of     DS1307
             
          wiringPiI2CWriteReg8 ( fd, 0xD0, 0xD0) ;  //address of register is 0XD0
         delay(500);
         wiringPiI2CWriteReg8 ( fd, 0X00, 0X00) ;  //address of register is 0X00
          delay(500);
          int returnValue= wiringPiI2CReadReg8 (fd, 0X00) ;
        

        }

        Response : I m getting -1 as return value which imply I m unable to read the register

        P 1 Reply Last reply 25 May 2019, 22:51
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 25 May 2019, 20:41 last edited by
          #4

          Hi,

          Did you check that the user on your device has proper access privilege for the I2C device ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • S SHUBHAM SINGH RAO
            25 May 2019, 11:08

            @Pablo-J.-Rogina
            Sorry for late response
            After your reply, I have been trying to implement I2C functions but I m unable to get read any data from DS 1307.
            Here my code goes:

             ReadI2C_function()
              { int fd;
                wiringPiSetup();
                ui->setupUi(this);
                fd = wiringPiI2CSetup(0X68);  //0X68 is the address of     DS1307
                 
              wiringPiI2CWriteReg8 ( fd, 0xD0, 0xD0) ;  //address of register is 0XD0
             delay(500);
             wiringPiI2CWriteReg8 ( fd, 0X00, 0X00) ;  //address of register is 0X00
              delay(500);
              int returnValue= wiringPiI2CReadReg8 (fd, 0X00) ;
            

            }

            Response : I m getting -1 as return value which imply I m unable to read the register

            P Offline
            P Offline
            Pablo J. Rogina
            wrote on 25 May 2019, 22:51 last edited by
            #5

            @SHUBHAM-SINGH-RAO have you tried reading the device with another program (not using Qt) I found this example just in case.

            Once you confirm that you can access the device (and that wiring is Ok) you can then jump into the task of integrating the wiringPi functions with the Qt framework.

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            1
            • T Offline
              T Offline
              tomasz3dk
              wrote on 27 May 2019, 06:38 last edited by
              #6

              I'm aware that this is not actually direct answer for your question, but isn't it better to have this RTC support on system a have proper time in whole system rather than control it only in your application?
              Check out this link

              A 1 Reply Last reply 27 May 2019, 06:59
              3
              • T tomasz3dk
                27 May 2019, 06:38

                I'm aware that this is not actually direct answer for your question, but isn't it better to have this RTC support on system a have proper time in whole system rather than control it only in your application?
                Check out this link

                A Offline
                A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on 27 May 2019, 06:59 last edited by
                #7

                @tomasz3dk This should be the correct and accepted answer :)

                Qt has to stay free or it will die.

                1 Reply Last reply
                0

                3/7

                25 May 2019, 11:08

                • Login

                • Login or register to search.
                3 out of 7
                • First post
                  3/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved