voilier-team-1/implementation/rtc.c

38 lines
987 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);
}
2023-04-05 08:25:25 +02:00
void MyRTC_GetTime(int* sec, int* min, int* hour, int* day, int* date, int* month, int* year)
{
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);
2023-04-05 08:25:25 +02:00
*sec = ((regCopy >> 4) & 0x07) * 10 + (regCopy & 0x0F);
2023-04-07 14:34:13 +02:00
MyI2C_GetString(I2C2, 0x01, &data);
2023-04-05 08:25:25 +02:00
*min = ((regCopy >> 4) & 0x07) * 10 + (regCopy & 0x0F);
2023-04-07 14:34:13 +02:00
MyI2C_GetString(I2C2, 0x02, &data);
2023-04-05 08:25:25 +02:00
*hour = 0;
2023-04-07 14:34:13 +02:00
MyI2C_GetString(I2C2, 0x03, &data);
2023-04-05 08:25:25 +02:00
*day = (regCopy & 0x07);
2023-04-07 14:34:13 +02:00
MyI2C_GetString(I2C2, 0x04, &data);
2023-04-05 08:25:25 +02:00
*date = ((regCopy >> 4) & 0x03) * 10 + (regCopy & 0x0F);
2023-04-07 14:34:13 +02:00
MyI2C_GetString(I2C2, 0x05, &data);
2023-04-05 08:25:25 +02:00
*month = ((regCopy >> 4) & 0x01) * 10 + (regCopy & 0x0F);
2023-04-07 14:34:13 +02:00
MyI2C_GetString(I2C2, 0x06, &data);
2023-04-05 08:25:25 +02:00
*year = ((regCopy >> 4) & 0xF0) * 10 + (regCopy & 0x0F) + 2000;
2023-04-07 13:53:08 +02:00
}