Multiple One Wire Devices

General discussion on mikroBasic.
Post Reply
Author
Message
felix
Posts: 37
Joined: 12 Oct 2005 22:03

Multiple One Wire Devices

#1 Post by felix » 13 Nov 2005 17:11

I am trying to get two one wire temperate sensors working but I can not seem to address them individually does anyone have a sample code??

Thanks Felix.

I am using a PIC18F452 and two DS1820 sensors

Early Bird
Posts: 178
Joined: 09 Jul 2005 10:00
Location: Scunthorpe UK

#2 Post by Early Bird » 13 Nov 2005 18:37

How far have you got?

Post your code and we can help.

The one wire example assumes a single DS1820 and therefore skips the complicated routine for searching the bus for what is present.

Have you read the data sheet for the DS1820?

Steve

guyfoc
Posts: 297
Joined: 09 Sep 2005 11:34
Location: belgium

#3 Post by guyfoc » 14 Nov 2005 07:51

here an ex with an old version of micro basic
1st you must know the 64bits serial of your device
there was ex to do that
and put your serial and adap the prog to your version of mb

Code: Select all

program four_ds1820_v2

'depart et modif de :program four_ds1820_v1
'16f628a 4mhz config word= 3f21 and lcd 2lines x24 col
' you must first read the 8 bytes serial of the ds1820 (see others exemples) to put them here
' 16 is the dev type ...rest= serial and crc ..see data sheet at maxim...
' if a ds1820 is not connected lcd gives -127,5 as temp because tie up on the pin  and return $ffff..
const serial_1         as byte[8]= (16,139,130,172,0,8,0,108) 'ds1820 n1 serial
const serial_2         as byte[8]= (16,65,248,158,0,8,0,163)  'ds1820 n2 serial
const serial_3         as byte[8]= ($10,$bc,$e4,$c4,$00,$08,$00,$05)  'ds1820 n3 serial
const serial_4         as byte[8]= ($10,$77,$7d,$c4,$00,$08,$00,$26)  'ds1820 n4 serial



dim    j as byte
dim    scratch as byte[9]
dim    text  as char[7]
dim    a,b,i,x,r as byte
dim    deci     as char

Sub procedure get_temp (dim lig,col as byte)

   Ow_Write(portA, 3, $BE)        'read scratchpad cmd
       for i=0 to 8
           x = ow_read(PORTA, 3)
            scratch[i] = x       ' get result  9 bytes in array
       next i
       a= scratch[1]                   ' signe temp
       if a=0 then
                  lcd_chr(lig,col,"+")
              else
                  lcd_chr(lig,col,"-")
       end if

       a=scratch[0]
       if a.0 = 0  then               'a.0 is 0.5c value
                       deci = "0"
                  else
                       deci = "5"
       end if
       a = scratch[0]  >>1            ' temp en degre
       ByteToStr(a,text)
       lcd_out_cp( text)
       Lcd_Chr_CP(",")
       Lcd_Chr_CP(deci)
       'lcd_chr_CP(223)
       'Lcd_Chr_CP("c")
end sub

main:

   CMCON = 7
   porta  = 255                     ' initialize porte to 255
   PORTB  =   0                     ' initialize portb to 0
   trisa  = 255                     ' designate porte as input
   trisb  =   0                     ' designate portb as output
   Lcd_Init(PORTB)
   lcd_cmd( LCD_CURSOR_OFF)
   Lcd_Cmd(LCD_CLEAR)
   while true
       'Lcd_Cmd(LCD_CLEAR)
       Ow_Reset(PORTA, 3)
       Ow_Write(portA, 3, $CC)       ' skip rom cmd   send cmd to all devices
       Ow_Write(portA, 3, $44)       'convert temp cmd  for the 2 ds1820 s
       Delay_ms(1000)                ' conversion delay fonction of  precision

       Ow_Reset(PORTA, 3)
       Ow_Write(portA, 3, $55)       ' match rom cmd selection  ds1820 n1
       for i=0 to 7
            b = serial_1[i]
            Ow_Write(portA, 3, b)     'serial of ds1820 n1
            delay_ms(10)
       next i
    get_temp(1,1)

       Ow_Reset(PORTA, 3)
       Ow_Write(portA, 3, $55)       ' match rom cmd selection  ds1820 n2
       for i=0 to 7
            b = serial_2[i]
            Ow_Write(portA, 3, b)     'serial of ds1820 n2
            delay_ms(10)
       next i
    get_temp(1,7)

       Ow_Reset(PORTA, 3)
       Ow_Write(portA, 3, $55)       ' match rom cmd selection  ds1820 n3
       for i=0 to 7
            b = serial_3[i]
            Ow_Write(portA, 3, b)     'serial of ds1820 n3
            delay_ms(10)
       next i
    get_temp(1,13)

       Ow_Reset(PORTA, 3)
       Ow_Write(portA, 3, $55)       ' match rom cmd selection  ds1820 n4
       for i=0 to 7
            b = serial_4[i]
            Ow_Write(portA, 3, b)     'serial of ds1820 n4
            delay_ms(10)
       next i
    get_temp(1,19)

      Lcd_Cmd(LCD_SECOND_ROW)  ' if only 4 ds1820 and sec line for label
      text= " gar"
      Lcd_out_CP(text)
      text= "   liv"
      Lcd_out_CP(text)
      text= "   ext"
      Lcd_out_CP(text)
      text= "   ch1"
      Lcd_out_CP(text)
      delay_ms(1000)
   wend                 ' endless loop
end.
things we are knowing are always easy

felix
Posts: 37
Joined: 12 Oct 2005 22:03

#4 Post by felix » 14 Nov 2005 20:47

Thanks guyfoc do you have the other example? The one that reads the ID of the device.

Thanks

Felix

guyfoc
Posts: 297
Joined: 09 Sep 2005 11:34
Location: belgium

#5 Post by guyfoc » 15 Nov 2005 10:22

there is an ex of reading the serial of an IButton ds1990 in the mb ex dallas ibutton
its is the same for a ds1820
there must have only one device connected at a time
1st cmd is a ow_reset
2nd a ow_write with a cmd of" read rom" = $33
3rd a ow_read of the data 8 bytes serial of the device
and you display it in hex or dec on the lcd
i donot remember if you receive the byte family code "$10" for a ds1820 first or last during the reading ...
look also the data sheet of the ds1820
later when you want to addr that specific dev you send always reset first then a match rom cmd $55 followed by its 8 bytes serial
things we are knowing are always easy

guyfoc
Posts: 297
Joined: 09 Sep 2005 11:34
Location: belgium

#6 Post by guyfoc » 19 Nov 2005 11:19

do you need more help or is it ok?
things we are knowing are always easy

Post Reply

Return to “mikroBasic General”