DS1302 Compile error

Hi there,

I've been trying to understand the code to use with a DS1302. I've tried to set pins to use on Arduino nano as 2, 3, and 4. for CLK, DAT, and RST respectively. The code I use is
"DS1302 rtc(2, 3, 4);"
I receive a compile errors saying "no matching function for call to 'DS1302::DS1302(int, int, int).

I've googled to try and find a solution. I've searched this forum for an hour. Can some one help me out?

Here is the total code:

#include <DS1302.h>
#include <Wire.h>
#include <hardwareSerial.h>
#include "TM1637.h"
//#include <ReceiveOnlySoftwareSerial.h>
//#include <Arduino_FreeRTOS.h>

// define two tasks for UpdateClock & ReadSerial
void TaskUpdateClock(void *pvParameters);
void TaskReadSerial(void *pvParameters);

#define CLK 5 //pins definitions for TM1637 and can be changed to other ports
#define DIO 6

TM1637 tm1637(CLK, DIO);
DS1302 rtc(2, 3, 4);
//ReceiveOnlySoftwareSerial mySerial(10); // Software receive RX PIN

const byte numChars = 32;
char receivedChars[numChars];
boolean newData = false;

void setup()
{
Serial.begin(9600);
while (!Serial)
{
}

xTaskCreate(TaskUpdateClock, (const portCHAR *)"UpdateClock", 128, NULL, 2, NULL);
xTaskCreate(TaskReadSerial, (const portCHAR *)"ReadSerial", 128, NULL, 1, NULL);
}
void loop()
{
}

void TaskUpdateClock(void *pvParameters)
{
(void)pvParameters;

tm1637.init();
tm1637.set(BRIGHT_TYPICAL);
rtc.halt(false);
rtc.writeProtect(false);

// rtc.setDOW(SUNDAY); // Set Day-of-Week to FRIDAY
// rtc.setTime(22, 24, 00); // Set the time to 12:00:00 (24hr format)
// rtc.setDate(21, 04, 2019); // Set the date to August 6th, 2010
uint8_t u8arry[] = {0, 1, 2, 3};
boolean middlepoint = true;

for (;:wink:
{
rtc.getu8time(u8arry);
tm1637.display(0, u8arry[0]);
tm1637.display(1, u8arry[1]);
tm1637.point(middlepoint);
tm1637.display(2, u8arry[2]);
tm1637.display(3, u8arry[3]);
vTaskDelay(1000 / portTICK_PERIOD_MS); // wait for one second
}
}

void TaskReadSerial(void *pvParameters) // This is a task.
{
(void)pvParameters;

mySerial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);

for (;:wink:
{
recvWithStartEndMarkers();
showNewData();
vTaskDelay(1);
}
}

void recvWithStartEndMarkers()
{

static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '(';
char endMarker = ')';
char rc;

while (mySerial.available() > 0 && newData == false)
{
rc = mySerial.read();

if (recvInProgress == true)
{
  if (rc != endMarker)
  {
    receivedChars[ndx] = rc;
    ndx++;
    if (ndx >= numChars)
    {
      ndx = numChars - 1;
    }
  }
  else
  {
    receivedChars[ndx] = '\0'; // terminate the string
    recvInProgress = false;
    ndx = 0;
    newData = true;
  }
}

else if (rc == startMarker)
{
  recvInProgress = true;
}

}
}

void showNewData()
{
if (newData == true)
{
Serial.print("This just in ... ");
Serial.println(receivedChars);
bluetooth_updatetime(receivedChars);
newData = false;
}
}

// updatetime("13:00")
void bluetooth_updatetime(char input[])
{
char separator[] = ":";
char *token;
uint8_t times[] = {10, 10};
uint8_t i = 0;
token = strtok(input, separator);
while (token != NULL)
{
times[i] = (uint8_t)atoi(token);
i++;
token = strtok(NULL, separator);
}
rtc.setTime(times[0], times[1], 00);
}

Read the forum guidelines to see how to properly post code and some information on how to get the most from this forum.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

You can go back and fix your original post by highlighting the code and clicking the </> in the menu bar.
code tags new

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

Post a link to the DS1302 library that you are using. There seem to be more than one.

Hi
The DS1302 uses the I2C interface, which is just 2 pins.
When writingDS1302 rtc (2, 3, 4);
will generate an error as only 2 arguments are accepted.

Hi ruilviana!

Thanks so much for your reply, but I wonder why it is that this code works for others and not for me. I have 5 pins on my DS1302. VCC, GND, CLK, DAT, and RST. I'd imagine that I need to declare the pins for CLK and DAT, but what do I do with RST?

Let me know and many thanks again.

Thanks GroundFungus!

I am a noob! I appreciate your assistance and guidance. I'll repost properly.

Hi there,

This is a repost with, what I believe to be, correct formatting for this forum. I want to thank you all in advance for your help.

I've been trying to understand the code to use with a DS1302. I've tried to set pins to use on Arduino nano as 2, 3, and 4. for CLK, DAT, and RST respectively. The code I use is
"DS1302 rtc(2, 3, 4);"
I receive a compile errors saying "no matching function for call to 'DS1302::DS1302(int, int, int).

I've googled to try and find a solution. I've searched this forum for an hour. Can some one help me out?

Here is the total code:

#include <DS1302.h>
#include <Wire.h>
#include <hardwareSerial.h>
#include "TM1637.h"
//#include <ReceiveOnlySoftwareSerial.h>
//#include <Arduino_FreeRTOS.h>

// define two tasks for UpdateClock & ReadSerial
void TaskUpdateClock(void *pvParameters);
void TaskReadSerial(void *pvParameters);


#define CLK 5                           //pins definitions for TM1637 and can be changed to other ports
#define DIO 6

TM1637 tm1637(CLK, DIO);
DS1302 rtc(2, 3, 4);
//ReceiveOnlySoftwareSerial mySerial(10); //  Software receive RX PIN

const byte numChars = 32;
char receivedChars[numChars];
boolean newData = false;

void setup()
{
  Serial.begin(9600);
  while (!Serial)
  {
  }

  xTaskCreate(TaskUpdateClock, (const portCHAR *)"UpdateClock", 128, NULL, 2, NULL);
  xTaskCreate(TaskReadSerial, (const portCHAR *)"ReadSerial", 128, NULL, 1, NULL);
}
void loop()
{
}

void TaskUpdateClock(void *pvParameters)
{
  (void)pvParameters;

  tm1637.init();
  tm1637.set(BRIGHT_TYPICAL);
  rtc.halt(false);
  rtc.writeProtect(false);

  // rtc.setDOW(SUNDAY);        // Set Day-of-Week to FRIDAY
  // rtc.setTime(22, 24, 00);   // Set the time to 12:00:00 (24hr format)
  // rtc.setDate(21, 04, 2019); // Set the date to August 6th, 2010
  uint8_t u8arry[] = {0, 1, 2, 3};
  boolean middlepoint = true;

  for (;;)
  {
    rtc.getu8time(u8arry);
    tm1637.display(0, u8arry[0]);
    tm1637.display(1, u8arry[1]);
    tm1637.point(middlepoint);
    tm1637.display(2, u8arry[2]);
    tm1637.display(3, u8arry[3]);
    vTaskDelay(1000 / portTICK_PERIOD_MS); // wait for one second
  }
}

void TaskReadSerial(void *pvParameters) // This is a task.
{
  (void)pvParameters;

  mySerial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);

  for (;;)
  {
    recvWithStartEndMarkers();
    showNewData();
    vTaskDelay(1);
  }
}

void recvWithStartEndMarkers()
{

  static boolean recvInProgress = false;
  static byte ndx = 0;
  char startMarker = '(';
  char endMarker = ')';
  char rc;

  while (mySerial.available() > 0 && newData == false)
  {
    rc = mySerial.read();

    if (recvInProgress == true)
    {
      if (rc != endMarker)
      {
        receivedChars[ndx] = rc;
        ndx++;
        if (ndx >= numChars)
        {
          ndx = numChars - 1;
        }
      }
      else
      {
        receivedChars[ndx] = '\0'; // terminate the string
        recvInProgress = false;
        ndx = 0;
        newData = true;
      }
    }

    else if (rc == startMarker)
    {
      recvInProgress = true;
    }
  }
}

void showNewData()
{
  if (newData == true)
  {
    Serial.print("This just in ... ");
    Serial.println(receivedChars);
    bluetooth_updatetime(receivedChars);
    newData = false;
  }
}

// updatetime("13:00")
void bluetooth_updatetime(char input[])
{
  char separator[] = ":";
  char *token;
  uint8_t times[] = {10, 10};
  uint8_t i = 0;
  token = strtok(input, separator);
  while (token != NULL)
  {
    times[i] = (uint8_t)atoi(token);
    i++;
    token = strtok(NULL, separator);
  }
  rtc.setTime(times[0], times[1], 00);
}

Here is the complete error message:

Arduino: 1.8.15 (Mac OS X), Board: "Arduino Nano, ATmega328P"











clock_final:37:19: error: no matching function for call to 'DS1302::DS1302(int, int, int)'
 DS1302 rtc(2, 3, 4);
                   ^
In file included from /Users/stevebredschneider/Desktop/Arduino/Steve's Project/Time Clock/Clock3/Arduino_7_segment_clock_RTC-master/Clock_7_segment_RTC/clock_final/clock_final.ino:21:0:
/Users/stevebredschneider/Documents/Arduino/libraries/DS1302/DS1302.h:67:3: note: candidate: DS1302::DS1302()
   DS1302();
   ^~~~~~
/Users/stevebredschneider/Documents/Arduino/libraries/DS1302/DS1302.h:67:3: note:   candidate expects 0 arguments, 3 provided
/Users/stevebredschneider/Documents/Arduino/libraries/DS1302/DS1302.h:64:7: note: candidate: constexpr DS1302::DS1302(const DS1302&)
 class DS1302
       ^~~~~~
/Users/stevebredschneider/Documents/Arduino/libraries/DS1302/DS1302.h:64:7: note:   candidate expects 1 argument, 3 provided
/Users/stevebredschneider/Documents/Arduino/libraries/DS1302/DS1302.h:64:7: note: candidate: constexpr DS1302::DS1302(DS1302&&)
/Users/stevebredschneider/Documents/Arduino/libraries/DS1302/DS1302.h:64:7: note:   candidate expects 1 argument, 3 provided
/Users/stevebredschneider/Desktop/Arduino/Steve's Project/Time Clock/Clock3/Arduino_7_segment_clock_RTC-master/Clock_7_segment_RTC/clock_final/clock_final.ino: In function 'void setup()':
/Users/stevebredschneider/Desktop/Arduino/Steve's Project/Time Clock/Clock3/Arduino_7_segment_clock_RTC-master/Clock_7_segment_RTC/clock_final/clock_final.ino:51:39: warning: ISO C++ forbids declaration of 'type name' with no type [-fpermissive]
   xTaskCreate(TaskUpdateClock, (const portCHAR *)"UpdateClock", 128, NULL, 2, NULL);
                                       ^~~~~~~~
clock_final:51:33: error: expected primary-expression before 'const'
   xTaskCreate(TaskUpdateClock, (const portCHAR *)"UpdateClock", 128, NULL, 2, NULL);
                                 ^~~~~
clock_final:51:33: error: expected ')' before 'const'
/Users/stevebredschneider/Desktop/Arduino/Steve's Project/Time Clock/Clock3/Arduino_7_segment_clock_RTC-master/Clock_7_segment_RTC/clock_final/clock_final.ino:52:38: warning: ISO C++ forbids declaration of 'type name' with no type [-fpermissive]
   xTaskCreate(TaskReadSerial, (const portCHAR *)"ReadSerial", 128, NULL, 1, NULL);
                                      ^~~~~~~~
clock_final:52:32: error: expected primary-expression before 'const'
   xTaskCreate(TaskReadSerial, (const portCHAR *)"ReadSerial", 128, NULL, 1, NULL);
                                ^~~~~
clock_final:52:32: error: expected ')' before 'const'
/Users/stevebredschneider/Desktop/Arduino/Steve's Project/Time Clock/Clock3/Arduino_7_segment_clock_RTC-master/Clock_7_segment_RTC/clock_final/clock_final.ino: In function 'void TaskUpdateClock(void*)':
clock_final:64:7: error: 'class DS1302' has no member named 'halt'
   rtc.halt(false);
       ^~~~
clock_final:65:7: error: 'class DS1302' has no member named 'writeProtect'
   rtc.writeProtect(false);
       ^~~~~~~~~~~~
clock_final:75:9: error: 'class DS1302' has no member named 'getu8time'
     rtc.getu8time(u8arry);
         ^~~~~~~~~
clock_final:81:23: error: 'portTICK_PERIOD_MS' was not declared in this scope
     vTaskDelay(1000 / portTICK_PERIOD_MS); // wait for one second
                       ^~~~~~~~~~~~~~~~~~
clock_final:81:5: error: 'vTaskDelay' was not declared in this scope
     vTaskDelay(1000 / portTICK_PERIOD_MS); // wait for one second
     ^~~~~~~~~~
/Users/stevebredschneider/Desktop/Arduino/Steve's Project/Time Clock/Clock3/Arduino_7_segment_clock_RTC-master/Clock_7_segment_RTC/clock_final/clock_final.ino: In function 'void TaskReadSerial(void*)':
clock_final:89:3: error: 'mySerial' was not declared in this scope
   mySerial.begin(9600);
   ^~~~~~~~
/Users/stevebredschneider/Desktop/Arduino/Steve's Project/Time Clock/Clock3/Arduino_7_segment_clock_RTC-master/Clock_7_segment_RTC/clock_final/clock_final.ino:89:3: note: suggested alternative: 'Serial'
   mySerial.begin(9600);
   ^~~~~~~~
   Serial
clock_final:96:5: error: 'vTaskDelay' was not declared in this scope
     vTaskDelay(1);
     ^~~~~~~~~~
/Users/stevebredschneider/Desktop/Arduino/Steve's Project/Time Clock/Clock3/Arduino_7_segment_clock_RTC-master/Clock_7_segment_RTC/clock_final/clock_final.ino: In function 'void recvWithStartEndMarkers()':
clock_final:109:10: error: 'mySerial' was not declared in this scope
   while (mySerial.available() > 0 && newData == false)
          ^~~~~~~~
/Users/stevebredschneider/Desktop/Arduino/Steve's Project/Time Clock/Clock3/Arduino_7_segment_clock_RTC-master/Clock_7_segment_RTC/clock_final/clock_final.ino:109:10: note: suggested alternative: 'Serial'
   while (mySerial.available() > 0 && newData == false)
          ^~~~~~~~
          Serial
/Users/stevebredschneider/Desktop/Arduino/Steve's Project/Time Clock/Clock3/Arduino_7_segment_clock_RTC-master/Clock_7_segment_RTC/clock_final/clock_final.ino: In function 'void bluetooth_updatetime(char*)':
clock_final:165:7: error: 'class DS1302' has no member named 'setTime'; did you mean 'dateTime'?
   rtc.setTime(times[0], times[1], 00);
       ^~~~~~~
       dateTime
exit status 1
no matching function for call to 'DS1302::DS1302(int, int, int)'


This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Let me know what you think and thanks so much for your help.

Thank you for properly posting the code and errors.

I think that the code does not match the library. Have you tried any of the examples that come with the DS1302 library that you have installed? Where did you get the library that you have installed? Where did you get the code that you posted?

The data sheet for the DS1302 shows pins for SCLK, IO and CE.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.