unsigned char initRTCmodule(unsigned char devADDR){ unsigned char btemp; Nop(); Nop(); // I2C_Close(); I2C_Init(39); // I2C 100 KHZ, 16 MHZ OSC (see note in "myI2C.c") Nop(); Nop(); // I2C_Start(); I2C_Idle(); btemp = I2C_WriteByte(devADDR); Nop(); Nop(); Nop(); if (btemp != 0){ Nop(); Nop(); I2C_Stop(); I2C_Close(); return 0xFF; } else { btemp = DS3231_GetInfo(0x0F); Nop(); Nop(); return btemp; }; }
void read_RTC_I2c(unsigned char pos_memoria) { I2C_Idle(); I2C_Start(); I2C_Idle(); I2C_Write_Byte(0xD0); //address of DS1307. I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível. I2C_Write_Byte(pos_memoria); // Position the address pointer to 0. I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível. I2C_ReStart(); I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível. I2C_Write_Byte(0xD1); // Direction bit set to read. I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível. leitura = I2C_Read_Byte(); I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível. I2C_Send_NACK(); I2C_Stop(); }
void write_RTC_I2c() { I2C_Idle(); I2C_Start(); // Inicializa a comunicação I2c I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível. I2C_Write_Byte(0xD0); // End. fixo para DS1307: 1101000X, onde x = 0 é para gravação. I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível. I2C_Write_Byte(0x00); // End. onde começa a programação do relógio, end. dos segundos. I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível. //I2C_Write_Byte(0x00); // Inicializa com 00 segundos. I2C_Write_Byte(0x00); I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível. //I2C_Write_Byte(0x08); // Inicializa com 8 minutos. I2C_Write_Byte(0x30); I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível. //I2C_Write_Byte(0x08); // Inicializa com 08:00hs (formato 24 horas). I2C_Write_Byte(0x14); //19 horas I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível. //I2C_Write_Byte(0x04); // Inicializa com terça I2C_Write_Byte(0x04); I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível. //I2C_Write_Byte(0x17); // Inicializa com dia 17 I2C_Write_Byte(0x22);// dia 20 do mês I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível. //I2C_Write_Byte(0x04); // Inicializa com mês 04 I2C_Write_Byte(0x01); //mês 1, janeiro I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível. //I2C_Write_Byte(0x13); // Inicializa com ano 13 I2C_Write_Byte(0x16); //ano 16 I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível. I2C_Stop(); // Finaliza a comunicação I2c }