2023-04-04 14:36:29 +02:00
|
|
|
#include "rtc.h"
|
|
|
|
|
|
|
|
void plantage_i2C(void) {
|
|
|
|
while(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void (*IT_I2C_Err) (void) = plantage_i2C;
|
|
|
|
|
2023-04-07 13:53:08 +02:00
|
|
|
void MyRTC_Init(void)
|
2023-04-04 14:36:29 +02:00
|
|
|
{
|
2023-04-07 14:34:13 +02:00
|
|
|
MyI2C_Init(I2C2, 15, IT_I2C_Err);
|
2023-04-04 14:36:29 +02:00
|
|
|
}
|
|
|
|
|
2023-04-11 11:28:42 +02:00
|
|
|
void MyRTC_GetTime(MyRTC_Struct_TypeDef * rtc)
|
2023-04-04 14:36:29 +02:00
|
|
|
{
|
|
|
|
MyI2C_RecSendData_Typedef data;
|
|
|
|
char regCopy = 0;
|
|
|
|
|
2023-04-05 08:25:25 +02:00
|
|
|
data.SlaveAdress7bits = 0x68;
|
2023-04-04 14:36:29 +02:00
|
|
|
data.Ptr_Data = ®Copy;
|
|
|
|
data.Nb_Data = 1;
|
|
|
|
|
2023-04-07 14:34:13 +02:00
|
|
|
MyI2C_GetString(I2C2, 0x00, &data);
|
2023-04-11 11:28:42 +02:00
|
|
|
rtc->seconds = ((regCopy >> 4) & 0x07) * 10 + (regCopy & 0x0F);
|
2023-04-07 14:34:13 +02:00
|
|
|
MyI2C_GetString(I2C2, 0x01, &data);
|
2023-04-11 11:28:42 +02:00
|
|
|
rtc->minutes = ((regCopy >> 4) & 0x07) * 10 + (regCopy & 0x0F);
|
2023-04-07 14:34:13 +02:00
|
|
|
MyI2C_GetString(I2C2, 0x02, &data);
|
2023-04-11 11:28:42 +02:00
|
|
|
rtc->hours = 0;
|
2023-04-07 14:34:13 +02:00
|
|
|
MyI2C_GetString(I2C2, 0x03, &data);
|
2023-04-11 11:28:42 +02:00
|
|
|
rtc->day = (regCopy & 0x07);
|
2023-04-07 14:34:13 +02:00
|
|
|
MyI2C_GetString(I2C2, 0x04, &data);
|
2023-04-11 11:28:42 +02:00
|
|
|
rtc->date = ((regCopy >> 4) & 0x03) * 10 + (regCopy & 0x0F);
|
2023-04-07 14:34:13 +02:00
|
|
|
MyI2C_GetString(I2C2, 0x05, &data);
|
2023-04-11 11:28:42 +02:00
|
|
|
rtc->month = ((regCopy >> 4) & 0x01) * 10 + (regCopy & 0x0F);
|
2023-04-07 14:34:13 +02:00
|
|
|
MyI2C_GetString(I2C2, 0x06, &data);
|
2023-04-11 11:28:42 +02:00
|
|
|
rtc->year = ((regCopy >> 4) & 0xF0) * 10 + (regCopy & 0x0F) + 2000;
|
2023-04-07 13:53:08 +02:00
|
|
|
}
|