Exemple #1
0
int main(void) {
	uint8_t data[] = {0, 1, 2};
	
	/* Initialize system */
	SystemInit();

	/* Initialize I2C, custom pinout with 100kHt serial clock */
	TM_I2C_Init(I2C1, TM_I2C_PinsPack_Custom, 100000);

	/* Write "5" at location 0x00 to slave with address ADDRESS */
	TM_I2C_Write(I2C1, ADDRESS, 0x00, 5);
	
	/**
	 * Write multi bytes to slave with address ADDRESS
	 * Write to registers starting from 0x00, get data in variable "data" and write 3 bytes
	 */
	TM_I2C_WriteMulti(I2C1, ADDRESS, 0x00, data, 3);
	
	/* Read single byte from slave with 0xD0 (1101 000 0) address and register location 0x00 */
	data[0] = TM_I2C_Read(I2C1, ADDRESS, 0x00);
	
	/**
	 * Read 3 bytes of data from slave with 0xD0 address
	 * First register to read from is at 0x00 location 
	 * Store received data to "data" variable
	 */
	TM_I2C_ReadMulti(I2C1, 0xD0, 0x00, data, 3);
	
	while (1) {

	}
}
void TM_DS1307_SetDateTime(TM_DS1307_Time_t* time) {
	uint8_t data[7];
	
	data[TM_DS1307_SECONDS] = TM_DS1307_Bin2Bcd(TM_DS1307_CheckMinMax(time->seconds, 0, 59));
	data[TM_DS1307_MINUTES] = TM_DS1307_Bin2Bcd(TM_DS1307_CheckMinMax(time->minutes, 0, 59));
	data[TM_DS1307_HOURS] = TM_DS1307_Bin2Bcd(TM_DS1307_CheckMinMax(time->hours, 0, 23));
	data[TM_DS1307_DAY] = TM_DS1307_Bin2Bcd(TM_DS1307_CheckMinMax(time->day, 1, 7));
	data[TM_DS1307_DATE] = TM_DS1307_Bin2Bcd(TM_DS1307_CheckMinMax(time->date, 1, 31));
	data[TM_DS1307_MONTH] = TM_DS1307_Bin2Bcd(TM_DS1307_CheckMinMax(time->month, 1, 12));
	data[TM_DS1307_YEAR] = TM_DS1307_Bin2Bcd(TM_DS1307_CheckMinMax(time->year, 0, 99));
	
	TM_I2C_WriteMulti(TM_DS1307_I2C, TM_DS1307_I2C_ADDR, TM_DS1307_SECONDS, data, 7);
}