voilier-team-1/implementation/rtc.c

38 lines
977 B
C
Raw Normal View History

#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-07 14:34:13 +02:00
MyI2C_Init(I2C2, 15, IT_I2C_Err);
}
void MyRTC_GetTime(MyRTC_Struct_TypeDef * rtc)
{
MyI2C_RecSendData_Typedef data;
char regCopy = 0;
2023-04-05 08:25:25 +02:00
data.SlaveAdress7bits = 0x68;
data.Ptr_Data = &regCopy;
data.Nb_Data = 1;
2023-04-07 14:34:13 +02:00
MyI2C_GetString(I2C2, 0x00, &data);
rtc->seconds = ((regCopy >> 4) & 0x07) * 10 + (regCopy & 0x0F);
2023-04-07 14:34:13 +02:00
MyI2C_GetString(I2C2, 0x01, &data);
rtc->minutes = ((regCopy >> 4) & 0x07) * 10 + (regCopy & 0x0F);
2023-04-07 14:34:13 +02:00
MyI2C_GetString(I2C2, 0x02, &data);
rtc->hours = 0;
2023-04-07 14:34:13 +02:00
MyI2C_GetString(I2C2, 0x03, &data);
rtc->day = (regCopy & 0x07);
2023-04-07 14:34:13 +02:00
MyI2C_GetString(I2C2, 0x04, &data);
rtc->date = ((regCopy >> 4) & 0x03) * 10 + (regCopy & 0x0F);
2023-04-07 14:34:13 +02:00
MyI2C_GetString(I2C2, 0x05, &data);
rtc->month = ((regCopy >> 4) & 0x01) * 10 + (regCopy & 0x0F);
2023-04-07 14:34:13 +02:00
MyI2C_GetString(I2C2, 0x06, &data);
rtc->year = ((regCopy >> 4) & 0xF0) * 10 + (regCopy & 0x0F) + 2000;
2023-04-07 13:53:08 +02:00
}