AN #142 - Using MAX1668 with BASCOM-AVR |
|
Connecting the MAX1668 to the AT90S2313 by Roland van Leusden
The MAX1668 is a precise multichannel digital
thermometer that report the temperature of 4 remote sensors and it's
own package. The remote sensors are diode-connected
transistors—typically low-cost, easily mounted 2N3904 NPN types—that
replace conventional thermistors or thermocouples. The remote channels
can also measure the die temperature of other ICs, such as
microprocessors, that contain an on-chip, diode-connected transistor. |
The 2-wire serial interface accepts standard system
management bus (SMBus™) write byte, read byte, send byte, and receive
byte commands to program the alarm thresholds and to read temperature
data. The data format is 7 bits plus sign, in two's-complement format.
|
|
|
Is to connect the small QSOP package MAX1668
comes in. Each pin is 0.25mm wide, and there is one pin each 0.6 mm.
That is : "on less than 5mm there is 8 pins to solder". The easy way is
to buy SMT adapterboards, http://smt-adapter.com/
|
|
This is the Bascom code example I used. The code uses 74% of the available 2Kb of the AT90S2313. A demo version (4Kb limit) of Bascom can be downloaded here |
The code does the following:
Read Manufacture ID
Read Device ID
Read Status byte 1
Read Status byte 2
Read MAX1668 Local Temperature
Set remote DX1 Thigh limit
Set remote DX1 Tlow limit
Read Remote DX1 Thigh limit
Read Remote DX1 Tlow limit
Read Remote DX1 temperature 10 times with a 1sec. intervalThere is much more possible with the MAX1668, the MAX1668 can generate
an interrupt if a temperature is outside Thigh or Tlow limits for
example. Consult the datasheet for an overview of all available
commands. Bascom example program :
'**********************************************************************
' Application Note: Using the MAX1668
'-----------------------------------------------------
'
' Program-ID.: MAX1668.bas.
' Date...... : 22 /
05 / 2005
' Description: Example program for MAX1668 Multichannel Remote/Local
' Temperature Sensors
' write and read routines.
'
' Author : Roland
van leusden (sayang@zonnet.nl).
'
' Setup for the AT90S2313 using portd.6 for SDA and
Portd.5 for SCL.
' (Futurlec ET-JRAVR board)
' See page 1 from MAX1668 datasheet for shematic.
(www.maxim-ic.com)
'
' This program provides an example for writing to and
reading from
' a MAX1668 device wired with AO,A1 open.
'
'
'**********************************************************************
$regfile = "2313def.dat" ' Change for your AVR.
$crystal = 4000000 ' 4 MHz Crystal.
$baud = 19200 ' Output at 19200 baud.
'**********************************************************************
'** Set up Data Direction Registers and ports - Do this
before defining I2C pins!
'**********************************************************************
' Port B
Portb = &B0000_0000 ' Set All Port Pins Low
Ddrb = &B1111_1111 ' Set Unused Pins As Outputs.
' Port D
Portd = &B0000_0000 ' All low - with push-pull output
Ddrd = &B1111_1111 ' with internal pullups.
'**********************************************************************
'** Define and initialize I2C pins **
'**********************************************************************
Config Sda = Portd.6 ' I2C Data.
Config Scl = Portd.5 ' I2C Clock.
'**********************************************************************
'**********************************************************************
'
'** Declare subroutines **
'**********************************************************************
'
' This subroutine writes data to the I2C MAX1668.
'
Declare Sub I2c_max1668_write(byval Cmd As Byte , Byval Msb As Byte)
'
' This subroutine reads data from the I2C MAX1668.
'
Declare Sub I2c_max1668_read(byval Cmd As Byte , Msb As Byte)
'**********************************************************************
'** Define working variables and constants **
'**********************************************************************
Dim Max1668_adress_w As Byte
Max1668_adress_w = &H54 'A1 & A0 open, see datasheet
Dim Max1668_adress_r As Byte
Max1668_adress_r = &H55 'A1 & A0 open, see datasheet
Dim Counter_1 As Byte
Dim Cmd As Byte
Dim Msb As Byte
'**********************************************************************
'** Actual work starts here. **
'**********************************************************************
Main:
Msb = &H00
Call I2c_max1668_read(&Hfe , Msb) ' Read MSB
Print "Manufacture ID :
" ; Hex(msb) ' MSB to serial port
Msb = &H00
Call I2c_max1668_read(&Hff , Msb) ' Read MSB
Print "Device ID :
" ; Hex(msb) ' MSB to serial port
Msb = &H00
Call I2c_max1668_read(&H05 , Msb) ' Read MSB
Print "Status byte 1 :
" ; Bin(msb) ' MSB to serial port
Msb = &H00
Call I2c_max1668_read(&H06 , Msb) ' Read MSB
Print "Status byte 2 :
" ; Bin(msb) ' MSB to serial port
Msb = &H00
Call I2c_max1668_read(&H00 , Msb) ' Read MSB
Print "MAX1668 Local Temperature: " ; Msb ' MSB to serial port
Msb = &H09
Call I2c_max1668_write(&H15 , Msb) ' Write remote DX1 THIGH limit
Msb = &H00
Call I2c_max1668_write(&H16 , Msb) ' Write remote DX1 Tlow limit
Msb = &H00
Call I2c_max1668_read(&H0a , Msb) ' Read MSB
Print "Remote DX1 Thigh limit: " ; Msb ' MSB to serial port
Msb = &H00
Call I2c_max1668_read(&H0b , Msb) ' Read MSB
Print "Remote DX1 Tlow limit: " ; Msb ' MSB to serial port
Counter_1 = 0
Do
Msb = &H00
Call I2c_max1668_read(&H01 , Msb) ' Read MSB
Print "Remote DX1 temperature: " ; Msb ' MSB to serial port
Wait 1
Counter_1 = Counter_1 + 1
Loop Until Counter_1 = 10
End 'end program
'**********************************************************************
'** Define Subroutines **
'**********************************************************************
Sub I2c_max1668_write(byval Cmd As Byte , Msb As Byte)
' Writes data to the I2C MAX1668.
I2cstart 'Generate A Start Condition
I2cwbyte Max1668_adress_w 'Transmit The "ADDRESS and WRITE" Byte
I2cwbyte Cmd 'Transmit The Command Byte
I2cwbyte Msb 'Transmit Data Byte
I2cstop 'Generate a STOP condition
'Waitus 50 'Some delay may be
necessary for back to back transmitions
End Sub
Sub I2c_max1668_read(byval Cmd As Byte , Msb As Byte)
' Read data from the I2C MAX1668
I2cstart 'Generate START condition
I2cwbyte Max1668_adress_w 'Transmit The "ADDRESS and WRITE" Byte
I2cwbyte Cmd 'Transmit The Command Byte
I2cstart 'Generate a
REPEATED-START condition
I2cwbyte Max1668_adress_r 'Transmit ADDRESS with READ command
I2crbyte Msb , Nack 'Receive DATA byte (MSB) and don't acknowledge
I2cstop 'Generate a STOP condition
End Sub
Original pages are here
|