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 ?
QtWS25 Last Chance

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 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;
     }
    
    Pablo J. RoginaP 1 Reply Last reply
    0
    • S SHUBHAM SINGH RAO

      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;
       }
      
      Pablo J. RoginaP Offline
      Pablo J. RoginaP Offline
      Pablo J. Rogina
      wrote on 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
      2
      • Pablo J. RoginaP Pablo J. Rogina

        @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 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

        Pablo J. RoginaP 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on 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

            @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

            Pablo J. RoginaP Offline
            Pablo J. RoginaP Offline
            Pablo J. Rogina
            wrote on 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
            • tomasz3dkT Offline
              tomasz3dkT Offline
              tomasz3dk
              wrote on 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

              aha_1980A 1 Reply Last reply
              3
              • tomasz3dkT tomasz3dk

                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

                aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on 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

                • Login

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