DS1307 adrress register help !

I´m trying to do a watering controller, I wanna set time/date via switch and that shows the info in a LCD, I read that the square wave output drain the battery faster, what do if I don´t defined it in the code?
Is it possible to use a specific time to activate and deactivate a relay like a time alarm using I2C?

Write 0 to the Square waver register, that will turn it off.
On the other hand, the RTV only draws 1.5mA.
You can use the 1/Sec pulse to wake up the uc once a second to check the time, if not the time you want, go back into power down sleep mode until the next 2nd. Keep going until you reach the turn on/turn off time.

This is what it shows the serial monitor, is it right? I´m sending data in hex but nothing changes !

Post the code you are running, lets see if we can get some other software help here.
I only ever wrote the one sketch, was my first code ever for getting data back over I2C also.

It´s the same code that you gave me, I wanna see what it does to put in order my ideas

halejandro,
Do you have 10K pullup resistors on the SCL/SDA lines? And they are connected to the SCL/SDA lines on the microprocessor?
It should be connected like this (but without C12, that was for experimenting)

Yes sir, it's connected like that, Arduino pin 4, 5 !

Pullup resisters too? They are needed.

Yes 10K pullup resistors !

// Only to request data
#include <Wire.h>

byte sec_address = 0x00;
byte seconds;
byte min_address = 0x01;
byte minutes;
byte hrs_address = 0x02;
byte hours;
byte day_address = 0x03;
byte day_week;
byte date_address = 0x04;
byte date;
byte mon_address = 0x05;
byte months;
byte yrs_address = 0x06;
byte years;
byte square_address = 0x07;


int  register_address = 0x68;

void setup(){
  Wire.begin();
  Serial.begin(9600);
}

void loop(){
  Wire.beginTransmission(register_address);
  Wire.send(0);
  Wire.endTransmission();

  Wire.requestFrom(register_address, 7);
  seconds = Wire.receive();
  minutes = Wire.receive();
  hours = Wire.receive();
  day_week = Wire.receive();
  date = Wire.receive();
  months = Wire.receive();
  years = Wire.receive();
  
  //TIME
  
  if ((hrs_address & 0x0F) < 10) Serial.print("0"); // Bitwise 0x02 & 0x0F resulting the bit that controls the units 
  if (hrs_address < 0x23) hours = 0;
  Serial.print(hours,HEX);    
  Serial.print(":");
  if ((min_address & 0x0F) < 10) Serial.print("0");
  if (min_address < 0x59) minutes = 0;
  Serial.print(minutes, HEX);
  Serial.print(":");
  if ((sec_address & 0x0F) < 10) Serial.print("0");
  if (sec_address < 0x59) seconds = 0;
  Serial.print(seconds, HEX);
  Serial.print(" - ");
  
  //DATE
  
  if ((date_address & 0x0F) < 10) Serial.print("0");
  if (date_address < 0x31) date = 0;
  Serial.print(date,HEX);    
  Serial.print("/");
  if ((mon_address & 0x0F) < 10) Serial.print("0");
  if (mon_address < 0x12) months = 0;
  Serial.print(months, HEX);
  Serial.print("/");
  Serial.print("20");
  if ((yrs_address & 0x0F) < 10) Serial.print("0");
  if (yrs_address < 0x99) years = 0;
  Serial.println(years, HEX);
  
  delay(1000);
  
}

Finally I could show the format that I want to ! but this just request data from DS1307 !

Okay, what might be happening is that the recieved data is coming in as characters, so if you sent F049,
it would show up as
'F', '0', '4', '9'.
So you can test for 'F' no problem,
you can do the switch:case using '0', '1', '2', no problem.
The '2' and '7' you need to put back into 0x27 to send to the DS1307.
If you look here

You can see 0-9 in the Chr column, correspond to Hex 30-39.
So you should be able to take the 3rd & 4th characters, subtract 30, and have the real value needed.

3rdchar = 3drchar-0x30; // or -48
4thchar - 4thchar-0x30; // or -49

then
databyte_to_write = (3rdchar<<4 + 4thchar); // should result in 0x27

3rdchar gets shifted left 4 bits, so 0x02 becomes 0x20, and then add 7.

Let me know if that works out. Try adding serialprint(incomingByte, HEX); and see if what you send in from the IDE monitor agrees with the table.

Sorry, but what are the 3rd & 4th characters? should I change something in the sketch?

"should I change something in the sketch? "

That's what I am suggesting.
Treat the data coming from the serial monitor as ASCII characters, so instead of hex bytes coming over, such as
F0 00 04
instead you may be getting
'F' (or 0x whatever F is in the ASCII table)
'0' (or 0x30)
'0'
'0'
'0'
'4' (or 0x34)
which you can use as is for some things, but you need to convert to hex for others

But like I said, add a line to repeat the characters back
Serial.print(receivedByte, HEX);
and confirm that.

Okay, Yesterday I didn't see the screen shot, my moderator settings are fixed now.

That looks like the right kind of output when the device powers up.
You can change the Screen Settings so the text displayed wider & easier to see.

These is how I setup & run the test with RS232 Monitor

Settings for RTC_I2C_test:
a. Setup Serial1 : RS232MON @ 57600, COM8, connected to DB9, R232 to USB adapter.
Format: 2 bytes, HEX.

b. Clock not set, time not running. Updates every 5 seconds:
Hr 0 Mins 0 Secs 80 Day 1 Date 1 Month 1 Year 200 Square Wave 3

c. Set Secs: enter F0 33 (high nibble 0-5 and nibble 0-9). High nibble bit 3 (indicates time stopped, hence 80 after initial power)

[You should see the time, date, etc change after every command.]

d. Set Mins: F1 25 (high nibble 0-5 and low nibble 0-9)

e. Set Hrs: F2 11 (high nibble 0-1 and low nibble 0-9)

f. Set Day (of week): F3 05 (high nibble 0, low nibble 1-7)

g. Set Date (of month): F4 09 (high nibble 0-3, low nibble 0-9)

h. Set Month: F5 08 (high nibble 0-1, low nibble 0-9)

i. Set Year: F6 11 (high nibble 09, low nibble 0-9)

j. Set Square Wave: F7 10, test with LED. (high nibble 1 = square wave on, low nibble = 0 for 1 Hz)

k. Set RAM: F8 (08-3F) (00-FF) (no code written for read back yet)

I´m introducing the commands but nothing change, SORRY but why does it have to set the RAM?

Ok, I tried duplicating the test, see what was going on.
I think I only told you 1/2 the settings.
See the Left side - Screen Settings seem to work at 1 or 2 bytes, needs to be text mode.

On the Send side, I've been using 2 byte and entering commands as shown - in this, a fresh power up, no battery back up, command used was F004 - sets the seconds to 4, and sets bit 7 to 0 so timekeeping is enabled.
Looks I could use a linefeed in there where too.

I remembered why I used Serial1 - my UBS port shows up as COM13, so I was using that for uploading sketches, and using Serial1 to see test results.

Yeah, your code it`s so cool :D! now I can see the time and date !!!! Let me see if I understood the last explanation that you gave me, I have to try to do something similar but, with the exeption that I should use the serial monitor from Arduino IDE, inserting ASCII characters and take it to HEX!

Yes, let me know how it goes. The idea behind it is straightforward.

CrossRoads:
Okay, what might be happening is that the recieved data is coming in as characters, so if you sent F049,
it would show up as
'F', '0', '4', '9'.
So you can test for 'F' no problem,
you can do the switch:case using '0', '1', '2', no problem.
The '2' and '7' you need to put back into 0x27 to send to the DS1307.

3rdchar = 3drchar-0x30; // or -48
4thchar - 4thchar-0x30; // or -49

then
databyte_to_write = (3rdchar<<4 + 4thchar); // should result in 0x27

3rdchar gets shifted left 4 bits, so 0x02 becomes 0x20, and then add 7.

Hello, Okay I´m testing this part but only works with numebers 0-9, and when I send 'F' shows 16, acording to the table 'F' is 46! In the last part why do I have to add 7?

'F' was for the case where you had ascii characters coming in instead of HEX bytes.
If you are gettting 0x0F, that is decimal 16. No further processing needed.
if (commandByte == 0x0F) will work the same as
if (commandByte == 16)

0x27 was just an example to show how to put two nibbles together to make up a byte.
So if you had '2' and '7' come in, you would do the math on them to get
0x02
0x07
so shift 2 left 4 bits:
highnibble = 0x02<<4; // hows its 0x20
add the low nibble 0x07, and you have 0x27, which will make the DS1307 happy when you send a seconds or minutes command.

But if you have HEX data coming in, like F027, then you can just pass along the 0x27 as data.