Exemple #1
0
void
i2c_at24mac_read(char *buf, uint8_t eui64)
{
  if(eui64) {
    i2c_read_mem(I2C_AT24MAC_ADDR, 0x98, (uint8_t *)buf, 8);
  }
  /* 128bit unique serial number */
  else {
    i2c_read_mem(I2C_AT24MAC_ADDR, 0x80, (uint8_t *)buf, 16);
  }
}
Exemple #2
0
uint8_t ds1338_get_date_time(struct date_time * date_time)
{
	/* Receive all registers from ds1338 except format register */
	uint8_t ret = i2c_read_mem(DS1338_I2C_ADDR,0,(uint8_t*)date_time,sizeof(*date_time)-1);
	if(ret)
	{
		return ret;
	}
	/* convert ds1338 time format to RTC time format */
	if(date_time->hours&&(1<<DS1338_TIME_FORMAT))
	{
		/* 12h time format */
		/* clear 12/24h bit in hours byte */
		date_time->hours &= ~(1<<DS1338_TIME_FORMAT);
		/* set proper bit in format byte */
		date_time->format |= (1<<RTC_FORMAT_12_24);
		/* check AM/PM */
		if(date_time->hours&&(1<<DS1338_TIME_PM_AM))
		{
			/* if PM clear proper bit in rtc format byte */
			date_time->format &= ~(1<<RTC_FORMAT_AM_PM);
		}
		else
		{
			/* if AM set proper bit in rtc format byte */
			date_time->format |= (1<<RTC_FORMAT_AM_PM);
		}
		/* clear AM/PM bit in hours byte */
		date_time->hours &= ~(1<<DS1338_TIME_PM_AM);
	}
	
	return 0;
}
Exemple #3
0
uint8_t ds1338_start_stop(uint8_t start)
{
	uint8_t sec;
	uint8_t ret;
	/* read CH's register */
	ret = i2c_read_mem(DS1338_I2C_ADDR,DS1338_REG_CLOCK_HALT,&sec,1);
	if(ret) return ret;
	/* set or clear CH bit*/
	if(start)
	{
		sec &= ~(1<<DS1338_CLOCK_HALT);
	}
	else
	{
		sec |= (1<<DS1338_CLOCK_HALT);
	}
	/* write CH's register */
	return i2c_write_mem(DS1338_I2C_ADDR,DS1338_REG_CLOCK_HALT,&sec,1); 
}
Exemple #4
0
uint8_t ds1338_set_format(uint8_t format)
{
	uint8_t sec;
	uint8_t ret;
	/* read time format register */
	ret = i2c_read_mem(DS1338_I2C_ADDR,DS1338_REG_TIME_FORMAT,&sec,1);
	if(ret) 
	{
		return ret;
	}
	/* set time format register */
	if(format&(1<<RTC_FORMAT_12_24))
	{
		sec |= (1<<DS1338_TIME_FORMAT);
	}
	else
	{
		sec &= ~(1<<DS1338_TIME_FORMAT);
	}
	/* write time format register */
	return i2c_write_mem(DS1338_I2C_ADDR,DS1338_REG_TIME_FORMAT,&sec,1); 
}