How to initialize and read DS1621? Solved

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all! 

I have a project in which the DS1621 is connected via the i2c bus.

Device emulated in Proteus. In the i2c debugger, I see that the temperature value is not correctly transmitted in response to the request.

My DS1621 initialization and reading code looks like this:

// Адрес устройства

#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)
{
	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();
}

uint8_t getTemperatura(void)
{
  i2c_start();
  i2c_send_byte(DS1621_ADR_W);
  i2c_send_byte(DS1621_READ_TEMPR);
  i2c_send_byte(DS1621_ADR_R);
  actualtemperatura = i2c_read_byte(ACK);
  temperatura = i2c_read_byte(NACK);
  i2c_restart();
  i2c_send_byte(DS1621_ADR_W);
  i2c_send_byte(DS1621_START_CONVERT);
  i2c_stop();
  _delay_ms(750);
}

I get this response:

Help me crying

This topic has a solution.

BORN IN BELARUS

Last Edited: Tue. Sep 20, 2022 - 01:02 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try adding the i2c_restart(); line in red.

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);
  actualtemperatura = i2c_read_byte(ACK);
  temperatura = i2c_read_byte(NACK);
  i2c_restart();
  i2c_send_byte(DS1621_ADR_W);
  i2c_send_byte(DS1621_START_CONVERT);
  i2c_stop();
  _delay_ms(750);
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

N.Winterbottom wrote:

Try adding the i2c_restart(); line in red.

i2c_restart();

thank you so much!

Solved!

 

BORN IN BELARUS

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

del

BORN IN BELARUS

Last Edited: Tue. Sep 20, 2022 - 01:03 PM