Application notes 68HC11

Endast på Engelska

Interfacing the DS1620 to the Motorola SPI Bus

Dallas Semiconductor makes Thermal Management easy with its line of direct-to-digital temperature sensors. These sensors provide a digital reading of temperature directly, eliminating the need for A/D converters dedicated to temperature to digital conversions. Factory-calibrated to relieve the user of linearity corrections and other compensation, Dallas Semiconductor's sensors provide a range and accuracy unparalleled in the industry.
The DS1620 Digital Thermometer and Thermostat provides 9-bit temperature readings which indicate the temperature of the device. It is available with three thermostatic outputs which change based on where the temperature is in relation to user-programmed trip points. These trip points are stored in onboard EEPROM memory and are nonvolatile.
For multi-point sensing applications, there are temperature sensors, DS1820 series, which can bemultidropped through the Dallas 1-Wire interface.

Block diagram

The DS1620 has a single bi-directional data pin (DQ) which can directly communicate with the SPI interface found on many Motorola microcontrollers.The method to obtain this, is to use the MOSI and MISO of the SPI system wired together and to control the direction of the MOSI from software.In addition, the DS1620 transfers the LSB first, while SPI uses the MSB as the first bit.Using the SPI protocol CPOL,CPHA = 11, there is no contention between MOSI and the DQ output.
This application note describes a straightforward way to connect several DS1620's (and other 3-wire components) to the SPI system.

* Test program for DS1620 ------ 68HC11** DQ -------- MOSI and MISO tied together*       The MOSI can easily be turned off in*       the DDRD register.*       When a read is performed, the DQ*       pin goes to a high impedance state*       while the clock is high *       (CPOL,CPHA=11 is used).* CLK ------- SCK* RST1 ------ PB0      DS1620 #1* RST2 ------ PB1      DS1620 #2   etc.* You can easily connect several DS1620's** The program reads a DS1620 and converts the temperature* to a readable value in reg Y*************** Equates:*-------------IOBASE   equ   $1000PORTB    equ   $1004DDRD     equ   $1009SPCR     equ   $1028SPDR     equ   $102Aportb    equ   $04         offsetsddrd     equ   $09spsr     equ   $29RST1     equ   %00000001RST2     equ   %00000010   etc.MOSI     equ   %00001000SPIF     equ   %10000000St_conv  equ   %01110111   (mirrored)Rd_temp  equ   %01010101   (mirrored)Wr_conf  equ   %00110000   (mirrored)Stack    equ   $00ff*********************** Initializations:*---------------------         org   $f800      RESET    lds   #Stack         jsr   InitSPI         jsr   InitDS************************ Main loop*----------------------Loop     jsr   Read_DS1         jsr   Mirror         jsr   BtoCent         jsr   Read_DS2         jsr   Mirror         jsr   BtoCent         bra   Loop*********************************************** Subroutine Read_DS1* Reads DS1620 #1 and leaves the value* in accB*---------------------------------------------Read_DS1 pshx         ldx   #IOBASE         bset  portb,X,RST1   Select DS1620 #1         bsr   Read_DS        Common routine         bclr  portb,X,RST1   Deselect #1         pulx         rts*********************************************** Subroutine Read_DS2* Reads DS1620 #2 and leaves the value* in accB*---------------------------------------------Read_DS2 pshx         ldx   #IOBASE         bset  portb,X,RST2   Select DS1620 #2         bsr   Read_DS        Common routine         bclr  portb,X,RST2   Deselect #2         pulx         rts*********************************************** Subroutine Read_DS* Reads the DS1620 pointed out by* the RST signal* Leaves the value in accB, sign in accA*---------------------------------------------Read_DS  bset  ddrd,X,MOSI    MOSI on         ldab  #Rd_temp       Read temp command         stab  SPDR         brclr spsr,X,SPIF,*         bclr  ddrd,X,MOSI    MOSI off         stab  SPDR         brclr spsr,X,SPIF,*         ldab  SPDR         stab  SPDR         brclr spsr,X,SPIF,*         ldaa  SPDR         rts*********************************************** Subroutine InitSPI*---------------------------------------------InitSPI  ldaa  #%110000       As default, MOSI is turned off         staa  DDRD         ldaa  #%01011100     CPOL,CPHA = 11         staa  SPCR         rts*********************************************** Subroutine InitDS* Initiates both DS1620's for continous* conversion**********************************************InitDS   ldx   #IOBASE         bset  portb,X,RST1+RST2         bset  ddrd,X,MOSI    MOSI on         ldaa  #Wr_conf       Write config         staa  SPDR         brclr spsr,X,SPIF,*         ldaa  #%01000000     CPU mode, continous conversion         staa  SPDR         brclr spsr,X,SPIF,*         bclr  portb,X,RST1+RST2         bset  portb,X,RST1+RST2         ldaa  #St_conv       Start convert         staa  SPDR         brclr spsr,X,SPIF,*         bclr  ddrd,X,MOSI    MOSI off         bclr  portb,X,RST1+RST2         rts******************************************** Subroutine BtoCent* The value in B is converted to Centigrade* in reg Y.*------------------------------------------BtoCent  psha         pshb         pshx         clra         ldx   #20            Divide with 20         idiv         pshx         pula         pula                 Tenths --> A         lslb         lslb         lslb                 Units --> B_high         bitb  #%00001000     Test B_low for %1000 or %0000         beq   no             if %1000, make it %0101 (5)         subb  #3no       xgdy                 Put A:B into Y         pulx         pulb         pula         rts**************************** Subroutine Mirror* Mirrors the values in B*--------------------------Mirror   psha         rorb         rola         rorb         rola         rorb         rola         rorb         rola         rorb         rola         rorb         rola         rorb         rola         rorb         rola         tab         pula         rts         org   $fffe         fdb   RESET         end

Stefan Nyman © Micronym 1999