Вс сен 18, 2022 10:42:14
// Адрес устройства
#define DS1621_ADR 0x48
// Адреса регистров
#define DS1621_READ_TEMPR 0xAA // Адрес регистра чтения температуры
#define DS1621_READ_COUNTER 0xA8 // Адрес регистра reads the value Count_Remain
#define DS1621_RAED_SLOPE 0xA9 // Адрес регистра reads the value Count_Per_C
#define DS1621_START_CONVERT 0xEE // Адрес регистра begins a temperature conversion
#define DS1621_STOP_CONVERT 0x22 // Адрес регистра stops temperature conversion
#define DS1621_ACCES_TH 0xA1 // Адрес регистра high temperature limit value into TH register
#define DS1621_ACCES_TL 0xA2 // Адрес регистра low temperature limit value into TH register
#define DS1621_ACCES_CONFIG 0xAC // Адрес регистра configuration data to configuration register
// Funcion to init DS1621
//******************************************************************
void ds1621_init(void)
{
//BYTE temp = 0;
i2c_init();
i2c_start();
i2c_send_byte(DS1621_ADR);
i2c_send_byte(DS1621_ACCES_CONFIG);
i2c_send_byte(0x01); //в LSB конфигурационного байта пишем 1 — преобр. по запросу.
i2c_restart();
i2c_send_byte(DS1621_ADR);
i2c_send_byte(DS1621_START_CONVERT);
i2c_stop();
}
// get temperature ----------
char getTemperatura(void)
{
//uint8_t actualtemperatura;
i2c_start();
i2c_send_byte(DS1621_ADR);
i2c_send_byte(DS1621_READ_TEMPR);
temperatura = i2c_read_byte(NACK);
i2c_restart();
i2c_send_byte(DS1621_ADR);
i2c_send_byte(DS1621_START_CONVERT);
i2c_stop();
}
Вс сен 18, 2022 11:59:22
Вс сен 18, 2022 12:31:53
void i2c_restart(void)
{
ONE_SDA();
I2C_DELAY();
ONE_SCL();
I2C_DELAY();
NULL_SDA();
I2C_DELAY();
NULL_SCL();
I2C_DELAY();
}
A control byte is the first byte received following the START condition from the master device. The
control byte consists of a 4-bit control code; for the DS1621, this is set as 1001 binary for read and write
operations. The next 3 bits of the control byte are the device select bits (A2, A1, A0).
Вс сен 18, 2022 12:39:43
ADDR_I2C = 0b1001[A2][A1][A0][R/W]
write:
i2c_write(i2c_addr << 1);
read:
i2c_write(i2c_addr << 1 | 0x01);
Вс сен 18, 2022 13:13:02
// Адрес устройства
#define DS1621_ADR_R 0x91
#define DS1621_ADR_W 0x90
// Адреса регистров
#define DS1621_READ_TEMPR 0xAA // Адрес регистра reads temperature
#define DS1621_READ_COUNTER 0xA8 // Адрес регистра reads the value Count_Remain
#define DS1621_RAED_SLOPE 0xA9 // Адрес регистра reads the value Count_Per_C
#define DS1621_START_CONVERT 0xEE // Адрес регистра begins a temperature conversion
#define DS1621_STOP_CONVERT 0x22 // Адрес регистра stops temperature conversion
#define DS1621_ACCES_TH 0xA1 // Адрес регистра high temperature limit value into TH register
#define DS1621_ACCES_TL 0xA2 // Адрес регистра low temperature limit value into TH register
#define DS1621_ACCES_CONFIG 0xAC // Адрес регистра configuration data to configuration register
// Funcion to init DS1621
//******************************************************************
void ds1621_init(void)
{
//BYTE temp = 0;
i2c_init();
i2c_start();
i2c_send_byte(DS1621_ADR_W);
i2c_send_byte(DS1621_ACCES_CONFIG);
i2c_send_byte(0x01); //in LSB One Shot Mode.
i2c_restart();
i2c_send_byte(DS1621_ADR_W);
i2c_send_byte(DS1621_START_CONVERT);
i2c_stop();
}
// get temperature ----------
uint8_t getTemperatura(void)
{
i2c_start();
i2c_send_byte(DS1621_ADR_W);
i2c_send_byte(DS1621_READ_TEMPR);
i2c_restart();
i2c_send_byte(DS1621_ADR_R);
temperatura = i2c_read_byte(NACK);
i2c_restart();
i2c_send_byte(DS1621_ADR_W);
i2c_send_byte(DS1621_START_CONVERT);
i2c_stop();