DS1621 Complete Conversion - how?

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

Hi, All!

DC 1621 works. Warming up. Lying.

I want to run it 1 time per minute.

After starting the conversion, it is necessary to determine the Сonversion complete. I'm trying the status of the MCB bit in the Operation and Control register (ACh). Does not work:

#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
#define DONE                    0x80    //Conversion Done bit. “1” = Conversion complete

uint8_t getTemperatura(void)
{
	uint8_t temp = 0;
	i2c_start();
	i2c_send_byte(DS1621_ADR_W);
	i2c_send_byte(DS1621_START_CONVERT);
	i2c_restart();
	i2c_send_byte(DS1621_ADR_W);
	i2c_send_byte(DS1621_ACCES_CONFIG);
	i2c_restart();
	i2c_send_byte(DS1621_ADR_R);
	temp = i2c_read_byte(ACK);
		if(!(temp & (1 << DONE))){i2c_restart(); i2c_send_byte(DS1621_ADR_R); temp = i2c_read_byte(NACK);}
			else i2c_restart();
	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_STOP_CONVERT);
	i2c_stop();

I want to wait for 1 in MSB status register bit. Then read the temperature value. I am getting the wrong value. Please help me )

This topic has a solution.

BORN IN BELARUS

Last Edited: Wed. Sep 21, 2022 - 11:10 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My Mistake ( you should use while, not if

uint8_t getTemperatura(void)
{
   i2c_start();
   i2c_send_byte(DS1621_ADR_W);
   i2c_send_byte(DS1621_START_CONVERT); 
      while(!(temp & 0x80)) 
	  {
		  ds1621_get_status(); 
	  }
          temp = 0x00;
   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_STOP_CONVERT);
   i2c_stop();
   	return temperatura;
}

 

BORN IN BELARUS

Last Edited: Wed. Sep 21, 2022 - 11:18 AM