Hi just to the point, these is my code
#include <Arduino.h>
int RTCrstPin = 2;int RTCclkPin = 4;int RTCdatPin = 3;
void RTCwrite(byte address, byte data) {
address |= 0x01;
pinMode(RTCdatPin, OUTPUT);
digitalWrite(RTCrstPin, HIGH);
for (int i = 0; i < 8; i++) {
digitalWrite(RTCdatPin, address & 0x01);
digitalWrite(RTCclkPin, HIGH);
digitalWrite(RTCclkPin, LOW);
address >>= 1;
}
for (int i = 0; i < 8; i++) {
digitalWrite(RTCdatPin, data & 0x01);
digitalWrite(RTCclkPin, HIGH);
digitalWrite(RTCclkPin, LOW);
data >>= 1;
}
digitalWrite(RTCrstPin, LOW);
}
void RTCread(byte address) {
address |= 0x81;
pinMode(RTCdatPin, OUTPUT);
digitalWrite(RTCrstPin, HIGH);
for (int i = 0; i < 8; i++) {
digitalWrite(RTCdatPin, address & 0x01);
digitalWrite(RTCclkPin, HIGH);
delayMicroseconds(5);
digitalWrite(RTCclkPin, LOW);
delayMicroseconds(5);
address >>= 1;
}
pinMode(RTCdatPin, INPUT);
for (int i = 0; i < 8; i++) {
digitalWrite(RTCclkPin, LOW);
delayMicroseconds(5);
Serial.print(digitalRead(RTCdatPin));
digitalWrite(RTCclkPin, HIGH);
delayMicroseconds(5);
}
Serial.println();
}
void setup() {
pinMode(RTCrstPin, OUTPUT);pinMode(RTCclkPin, OUTPUT);pinMode(RTCdatPin, OUTPUT);
Serial.begin(250000);
RTCwrite(0x8E, 0x00);
RTCwrite(0x80, 0x30);
delay(100);
RTCread(0x81);
}
void loop() {
RTCread(0x81);
delay(1000);
}
the output
* Executing task in folder DS1302 Test: C:\Users\DayatKun0\.platformio\penv\Scripts\platformio.exe device monitor
--- Terminal on COM4 | 250000 8-N-1
--- Available filters and text transformations: colorize, debug, default, direct, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at https://bit.ly/pio-monitor-filters
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
10101000
00000000
00000000
00000000
...
My problem is the first result that i called from setup is giving result (10101000) but the seccond and other result giving 00000000 so im thinking if the first read is work, seccond and other not, can someone help me ?? plss i coded this for 3 hour and learning this 1 week (lazy time included) and its still not workkk im trying hard for this thing, sorry im noob at coding lol, im just learning, and FYI, why did i not using library? because i wanna learning it more deeper. but as i know i followed the datasheet corectly (with some chatgpt helping).
