voilier-team-1/implementation/rtc.c

37 lines
977 B
C

#include "rtc.h"
void plantage_i2C(void) {
while(1);
}
void (*IT_I2C_Err) (void) = plantage_i2C;
void MyRTC_Init(void)
{
MyI2C_Init(I2C2, 15, IT_I2C_Err);
}
void MyRTC_GetTime(MyRTC_Struct_TypeDef * rtc)
{
MyI2C_RecSendData_Typedef data;
char regCopy = 0;
data.SlaveAdress7bits = 0x68;
data.Ptr_Data = &regCopy;
data.Nb_Data = 1;
MyI2C_GetString(I2C2, 0x00, &data);
rtc->seconds = ((regCopy >> 4) & 0x07) * 10 + (regCopy & 0x0F);
MyI2C_GetString(I2C2, 0x01, &data);
rtc->minutes = ((regCopy >> 4) & 0x07) * 10 + (regCopy & 0x0F);
MyI2C_GetString(I2C2, 0x02, &data);
rtc->hours = 0;
MyI2C_GetString(I2C2, 0x03, &data);
rtc->day = (regCopy & 0x07);
MyI2C_GetString(I2C2, 0x04, &data);
rtc->date = ((regCopy >> 4) & 0x03) * 10 + (regCopy & 0x0F);
MyI2C_GetString(I2C2, 0x05, &data);
rtc->month = ((regCopy >> 4) & 0x01) * 10 + (regCopy & 0x0F);
MyI2C_GetString(I2C2, 0x06, &data);
rtc->year = ((regCopy >> 4) & 0xF0) * 10 + (regCopy & 0x0F) + 2000;
}