DS18S20 sensor

General discussion on mikroPascal PRO for AVR.
Post Reply
Author
Message
AlexanderRUS
Posts: 24
Joined: 30 Jul 2013 11:51

DS18S20 sensor

#1 Post by AlexanderRUS » 12 Nov 2013 07:39

All good afternoon! ! ! How to consider serial number and CRC the DS18S20 sensor by means of OneWire library

tpetar
Posts: 593
Joined: 27 Apr 2012 18:44
Location: Pancevo, Serbia

Re: DS18S20 sensor

#2 Post by tpetar » 12 Nov 2013 20:17

AlexanderRUS wrote:All good afternoon! ! ! How to consider serial number and CRC the DS18S20 sensor by means of OneWire library

Its for MikroC Pro for PIC, maybe you will find someting useful:

1-Wire Read Serial Number and Temperature DS18B20 or DS18S20
http://www.libstock.com/projects/view/6 ... or-ds18s20

1-Wire Library for MikroPascal/MikroBasic supports only DS1820 device. In MikroC you can use DS1990, DS2401,.... or other 1-wire devices.



Best regards,
Peter

AlexanderRUS
Posts: 24
Joined: 30 Jul 2013 11:51

Re: DS18S20 sensor

#3 Post by AlexanderRUS » 04 Dec 2013 10:25

tpetar wrote:
AlexanderRUS wrote:All good afternoon! ! ! How to consider serial number and CRC the DS18S20 sensor by means of OneWire library

Its for MikroC Pro for PIC, maybe you will find someting useful:

1-Wire Read Serial Number and Temperature DS18B20 or DS18S20
http://www.libstock.com/projects/view/6 ... or-ds18s20

1-Wire Library for MikroPascal/MikroBasic supports only DS1820 device. In MikroC you can use DS1990, DS2401,.... or other 1-wire devices.



Best regards,
Peter
DS1820 and DS18S20 identical

tpetar
Posts: 593
Joined: 27 Apr 2012 18:44
Location: Pancevo, Serbia

Re: DS18S20 sensor

#4 Post by tpetar » 04 Dec 2013 12:57

AlexanderRUS wrote:DS1820 and DS18S20 identical
Hello,

DS18S20 is marked as DS1820, and today DS1820 is accepted as DS18S20. But old and first serie of this digital sensor (DS1820) have difference. The primary specification difference between the two parts is the temperature conversion time: DS1820 = 500ms (max) and DS18S20 = 750ms (max).


Best regards,
Peter

AlexanderRUS
Posts: 24
Joined: 30 Jul 2013 11:51

Re: DS18S20 sensor

#5 Post by AlexanderRUS » 05 Dec 2013 05:38

tpetar wrote:
AlexanderRUS wrote:DS1820 and DS18S20 identical
Hello,

DS18S20 is marked as DS1820, and today DS1820 is accepted as DS18S20. But old and first serie of this digital sensor (DS1820) have difference. The primary specification difference between the two parts is the temperature conversion time: DS1820 = 500ms (max) and DS18S20 = 750ms (max).


Best regards,
Peter
Hello! ! ! How to read serial number of the DS18S20 sensor

tpetar
Posts: 593
Joined: 27 Apr 2012 18:44
Location: Pancevo, Serbia

Re: DS18S20 sensor

#6 Post by tpetar » 05 Dec 2013 17:40

AlexanderRUS wrote:Hello! ! ! How to read serial number of the DS18S20 sensor

Hello,

Use array of 8 bytes to store serial number. Read serial number store byte by byte in array, convert array byte by byte to hex and print on LCD.

Use ReadROM command 33h:

Code: Select all

     
// Reading Serial Number
     Ow_Reset(PORTE, 2);            // Onewire reset signal
     Ow_Write(PORTE, 2, 0x33);    // Issue command Read_ROM for Serial Number
     Delay_us(120);
Also define correct port and port pin. You can read both DS18B20 and DS18S20.


Best regards,
Peter

AlexanderRUS
Posts: 24
Joined: 30 Jul 2013 11:51

Re: DS18S20 sensor

#7 Post by AlexanderRUS » 06 Dec 2013 05:49

Also define correct port and port pin. You can read both DS18B20 and DS18S20.


Best regards,
Peter[/quote]

Hello,

What to give team I understood. How to read serial number. The Ow_Read team reads on two bytes. I need to read six byte serial number and to write down it in EEPROM

I understood

Ow_Reset(PORTB, 0);
Ow_Write(PORTB, 0, 0x33);
Delay_us(120);
for i:= 0 to 4 do
begin
btemp := Ow_Read(PORTB, 0);
ByteToHex(btemp, output);
if i > 0 then sTemp:= output + sTemp;
Delay_us(120);
end;
Lcd_Out(1, 1, sTemp);
Last edited by AlexanderRUS on 06 Dec 2013 06:37, edited 1 time in total.

tpetar
Posts: 593
Joined: 27 Apr 2012 18:44
Location: Pancevo, Serbia

Re: DS18S20 sensor

#8 Post by tpetar » 06 Dec 2013 06:00

AlexanderRUS wrote:What to give team I understood. How to read serial number. The Ow_Read team reads on two bytes. I need to read six byte serial number and to write down it in EEPROM
Hi Alexander,

Yes, but you can use loop and earlier mentioned array.

Try something like this. I cant test MikroPascal Pro code with AVR right now.

Code: Select all

     
program serialnumber;

// LCD module connections
var LCD_RS : sbit  at PORTB4_bit;
var LCD_EN : sbit  at PORTB6_bit;
var LCD_D4 : sbit  at PORTB0_bit;
var LCD_D5 : sbit  at PORTB1_bit;
var LCD_D6 : sbit  at PORTB2_bit;
var LCD_D7 : sbit  at PORTB3_bit;

var LCD_RS_Direction : sbit at DDB4_bit;
var LCD_EN_Direction : sbit at DDB6_bit;
var LCD_D4_Direction : sbit at DDB0_bit;
var LCD_D5_Direction : sbit at DDB1_bit;
var LCD_D6_Direction : sbit at DDB2_bit;
var LCD_D7_Direction : sbit at DDB3_bit;
// End LCD module connections

var serialnumber : array[8] of char;
     serialnumber_hex : array[2] of char;
     i : integer;
     col : integer;

.
.
.

// Display Serial Number
procedure Display_SerialNumber();
  begin
       col := 17;
       i := 0;
            for i := 0 to 7 do
                   begin
                      col := col - 2;
                      ByteToHex(serialnumber[i], serialnumber_hex);
                      Lcd_Out(1, col, serialnumber_hex);
                   end;
  end;

.
.
.

begin
    Lcd_Init();                // Initialize LCD
    Lcd_Cmd(_LCD_CLEAR);       // Clear display
    Lcd_Cmd(_LCD_CURSOR_OFF);  // Cursor off

// Reading Serial Number
     Ow_Reset(PORTD, 6);             // Onewire reset signal
     Ow_Write(PORTD, 6, 0x33);    // Issue command Read_ROM for Serial Number
     Delay_us(120);

     i := 0;
     for i := 0 to 7 do
            begin
               serialnumber[i] := Ow_Read(PORTD, 6);
            end;

Display_SerialNumber();

end.

Best regards,
Peter

tpetar
Posts: 593
Joined: 27 Apr 2012 18:44
Location: Pancevo, Serbia

Re: DS18S20 sensor

#9 Post by tpetar » 06 Dec 2013 11:17

Hi,

For writing to uC internal EEPROM you can use EEPROM library, but first check uC datasheet to see what is EEPROM size:

EEPROM Library
http://www.mikroe.com/download/eng/docu ... &width=970

Principe for EEPROM writing is similar as for showing on LCD, use array.

Also you can use external EEPROMs over I2C and SPI (I2C and SPI software librarires).


Best regards,
Peter

AlexanderRUS
Posts: 24
Joined: 30 Jul 2013 11:51

Re: DS18S20 sensor

#10 Post by AlexanderRUS » 18 Dec 2013 10:05

At me everything turned out. Snachalo considered 64 bit code, then:

Ow_Reset(PORTB, 0);
Ow_Write(PORTB, 0, 0xCC);
Ow_Write(PORTB, 0, 0x44);
Delay_ms(1000);

Ow_Reset(PORTB, 0);
Ow_Write(PORTB, 0, 0x55);

for i:= 0 to 7 do Ow_Write(PORTB, 0, serialnumber); // We work with the concrete sensor

Ow_Write(PORTB, 0, 0xBE);
Delay_ms(400);

Thank you very much

Post Reply

Return to “mikroPascal PRO for AVR General”