Have done some experiments with the code you provide in message #4,
and it actually seem that some of it may work,
even if the code is somewhat light on checking and error handling.
This is with the restriction that all MCC setup and hardware connections are correctly done.
I do not have the same dsPIC33 device you are using.
Have established a MCC configuration and stepped thru some of it in MPLAB simulator. I2C peripheral cannot be simulated.
Have used your main code in a MCC configuration for a different dsPIC33 device,
and run some experiments.
UART communication for results may be used, but correct functioning of asynchronous serial,
depend on MCC setup beeing correctly done with oscillator selection and settings,
and UART baudrate corresponding with the terminal (emulator program) used to display messages.
Note that microcontroller cannot be connected directly to RS-232 port (9 pin) of a computer or laptop,
there is transciever hardware needed.
I2C communication do not depend on any precision timing or particular frequency,
as long as SCL signaling is not much too fast.
Be aware that I2C hardware and MCC driver will check that slave device respond as expected,
so if DS1307 is not correctly connected, I2C1_MasterWrite(...) function will return a error status value into the i2c_status variable. You should check the value in this variable, after the delay have ended,
either in debugger or in the program.
I2C slave address used by the program, seem correct for the DS1307 real time clock
From datasheet for DS1307, it seem to me that when the RTC have been without power,
neither Vbat nor Vcc,
then the clock will not run, until you start it by writing a valid value to the Seconds register,
0x00 should work.
Only reading, without writing a start value, is likely to always return the same value.
When the RTC is eventually running, it will return time values as packed BCD numbers,
(up to) 4 bits for each decimal digit, 2 decimal digits in each 8 bit byte.
BCD values are not directly useable for sprintf(...) formatting or UART printing.
You must separate the 2 digits from each BCD byte, into 2 single digit decimal values,
and insert into separate bytes in a char array, together with a prefix value that make it a valid text digit.
Or combine digits into integer values that may be processed by sprintf(...).
i = 0;
text[i] = ((i2c1_data >> 4) & 0x07) + '0'; /* 10 seconds digit value + character code of '0' symbol. */
i++; /* next character position in text string. */
text[i] = (i2c1_data & 0x0F) + '0'; /* single seconds digit character. */
text[i] = '\r';
text[i] = '\n'
text[i] = 0x00; /* String terminator. */
UART2_WriteBuffer((uint8_t *)text, i);