Пример #1
0
bool DS1307Write(uint8_t address,uint8_t data)
{
	uint8_t res;	//result

	//Start
	SoftI2CStart();

	//SLA+W
	res=SoftI2CWriteByte(DS1307_SLA_W);	//DS1307 address + W

	//Error
	if(!res)	return false;

	//Now send the address of required register
	res=SoftI2CWriteByte(address);

	//Error
	if(!res)	return false;

	//Now write the value
	res=SoftI2CWriteByte(data);

	//Error
	if(!res)	return false;

	//STOP
	SoftI2CStop();

	return true;
}
Пример #2
0
void LM75_set_conf(uint8_t addr, uint8_t data) {
  SoftI2CStart();
  while(1) {
    if(!SoftI2CWriteByte(LM75_I2C_ADDR_MASK(addr))) break; //break if LM75 not ACK
    SoftI2CWriteByte(LM75_CONF_MASK(data));
  }
  SoftI2CStop();
}
Пример #3
0
void LM75_set_pointer(uint8_t addr, uint8_t ptr) {
  SoftI2CStart();
  while(1) {
    if(!SoftI2CWriteByte(LM75_I2C_ADDR_MASK(addr))) break; //break if LM75 not ACK
    SoftI2CWriteByte(LM75_POINTER_MASK(ptr)); //set pointer
    break;
  }
  SoftI2CStop();
}
Пример #4
0
int16_t LM75_TempRead(uint8_t addr) {
  int16_t temp=0;

  SoftI2CStart();
  while(1) {
    if(!SoftI2CWriteByte(LM75_I2C_ADDR_MASK(addr) | LM75_I2C_READ)) break; //break if LM75 not ACK
    temp = (SoftI2CReadByte(1)<<8); //Read high byte
    temp |= (SoftI2CReadByte(0) & 0xE0); // Read low byte. Mask? maybe 0x80
    break;
  }
  SoftI2CStop();
  return temp;
}
Пример #5
0
bool DS1307Read(uint8_t address,uint8_t *data)
{
	uint8_t res;	//result

	//Start
	SoftI2CStart();

	//SLA+W (for dummy write to set register pointer)
	res=SoftI2CWriteByte(0xD0);	//DS1307 address + W

	//Error
	if(!res)	return false;

	//Now send the address of required register
	res=SoftI2CWriteByte(address);

	//Error
	if(!res)	return false;

	//Repeat Start
	SoftI2CStart();

	//SLA + R
	res=SoftI2CWriteByte(DS1307_SLA_R);	//DS1307 Address + R

	//Error
	if(!res)	return false;

	//Now read the value with NACK
	*data=SoftI2CReadByte(0);

	//Error
	if(!res)	return false;

	//STOP
	SoftI2CStop();

	return true;
}