Private Function temperature(address As Integer) As Double
Dim temperature_int As Long
Dim temperature_frac As Long
address = address * 2
On Error GoTo errors
open_iic_bus MSComm1.object
'/*resettiamo bene il chip*/
IIC_stop
'/**/
IIC_start
IIC_tx_byte &H90 + address
IIC_tx_byte &HAC
IIC_tx_byte &H2
IIC_start
IIC_tx_byte &H90 + address
IIC_tx_byte &HEE
IIC_stop
IIC_start
IIC_tx_byte &H90 + address
IIC_tx_byte &HAA
IIC_start
IIC_tx_byte &H91 + address
temperature_int = IIC_rx_byte(1)
temperature_frac = IIC_rx_byte(0)
temperature = (temperature_int * 256 + temperature_frac) / 128 * 5 / 10
If temperature_int >= 128 Then
temperature = temperature - 256
End If
IIC_stop
Exit Function
errors:
temperature = ERROR_TEMPERATURE_NOT_READ
End Function