-7

I am trying to manually set up a RTC clock. When doen automatically, this is the working code:

clock.setDateTime((__DATE__, __TIME__));

But now I want to set it manually and this is what I am trying:

char dateTime[20];
strcat(dateTime, "2017,03,22,16,20,04");
//clock.setDateTime((__DATE__, __TIME__));
clock.setDateTime(dateTime);

I get the following error(at the last line):

error: invalid conversion from 'char*' to 'uint32_t {aka long unsigned int}' [-fpermissive]

How to solve?

EDIT: This is how setDateTime is defined:

void setDateTime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second);
sdd
  • 889
  • 8
  • 29
  • 2
    How is `setDateTime` defined? – NathanOliver Mar 22 '17 at 15:24
  • @NathanOliver See edit – sdd Mar 22 '17 at 15:25
  • 1
    Okay. So you need to split the string into parameters that match how `setDateTime` is defined. – NathanOliver Mar 22 '17 at 15:26
  • 4
    You're feeding a string (`char *`) to a function that expects integer parameters... that's an invalid conversion (as the compiler is telling you). What do you expect? – DevSolar Mar 22 '17 at 15:28
  • 3
    Also, I guess there are multiple declarations for `setDateTime()`, as 1) the one you're showing us shouldn't work with `(__DATE__, __TIME__)` either, and 2) the one you're showing us is not expecting `uint32_t` which is what the compiler complains about. – DevSolar Mar 22 '17 at 15:34
  • 1
    Why screw around with strings if you could just call `clock.setDateTime(2017,3,22,16,20,4)`? – gre_gor Mar 22 '17 at 15:40

2 Answers2

2

setDateTime() takes the date as a succession of integers:

setDateTime(year, month, day, hours, minutes, seconds);

Bonus: according to man strcat:

char *strcat(char *dest, const char *src);

Description

The strcat() function appends the src string to the dest string, ...

Since you use it this way:

char dateTime[20];
strcat(dateTime, "2017,03,22,16,20,04");

you append "2017,03,22,16,20,04" to unitialized memory, which is undefined behaviour.

Community
  • 1
  • 1
YSC
  • 38,212
  • 9
  • 96
  • 149
1

setDateTime() accepts ints as parameters, yet you give it char array.

The call should be:

clock.setDataTime(2017, 3, 22, 16, 20, 4);
zhm
  • 3,513
  • 3
  • 34
  • 55