zhaijunyuan
5 years ago
13 changed files with 269 additions and 21 deletions
@ -0,0 +1,67 @@ |
|||
#include <stdio.h> |
|||
#include "_i2c.h" |
|||
#include "dwt.h" |
|||
|
|||
|
|||
void max31730_init(uint8_t addr) |
|||
{ |
|||
i2c730_write(addr, 0x13, 0x52, 1); |
|||
dwt_wait_ms(50); |
|||
i2c730_write(addr, 0x12, 0x00, 1); |
|||
i2c730_write(addr, 0x13, 0x12, 1); |
|||
i2c730_write(addr, 0x15, 0x00, 1); |
|||
i2c730_write(addr, 0x17, 0x00, 1); |
|||
i2c730_write(addr, 0x18, 0x00, 1); |
|||
i2c730_write(addr, 0x19, 0x00, 1); |
|||
i2c730_write(addr, 0x35, 0x0F, 1); |
|||
} |
|||
|
|||
float max31730_read_temperature(uint8_t addr, int device_num) |
|||
{ |
|||
uint8_t T_MSB = 0x00, T_LSB = 0x00; |
|||
signed char data_M, data_L; |
|||
float temp,data_F; |
|||
|
|||
switch(device_num) |
|||
{ |
|||
case 1: |
|||
T_MSB = 0x02; |
|||
T_LSB = 0x03; |
|||
break; |
|||
case 2: |
|||
T_MSB = 0x04; |
|||
T_LSB = 0x05; |
|||
break; |
|||
case 3: |
|||
T_MSB = 0x06; |
|||
T_LSB = 0x07; |
|||
break; |
|||
default: |
|||
break; |
|||
} |
|||
|
|||
i2c730_read(addr, T_MSB, &data_M, 1); |
|||
i2c730_read(addr, T_LSB, &data_L, 1); |
|||
|
|||
data_F = ((data_L >> 4) & 0x01) * 0.0625 + ((data_L >> 5) & 0x01) * 0.125 + ((data_L >> 6) & 0x01) * 0.25 + ((data_L >> 7) & 0x01) * 0.5; |
|||
temp = data_M + data_F + 64; |
|||
|
|||
return temp; |
|||
} |
|||
|
|||
float max31730_read_local(uint8_t addr) |
|||
{ |
|||
uint8_t T_MSB = 0x00, T_LSB = 0x01; |
|||
signed char data_M, data_L; |
|||
float temp,data_F; |
|||
|
|||
|
|||
i2c730_read(addr, T_MSB, &data_M, 1); |
|||
i2c730_read(addr, T_LSB, &data_L, 1); |
|||
printf("data_M = %d, data_L = %d\r\n",data_M, data_L); |
|||
|
|||
data_F = ((data_L >> 4) & 0x01) * 0.0625 + ((data_L >> 5) & 0x01) * 0.125 + ((data_L >> 6) & 0x01) * 0.25 + ((data_L >> 7) & 0x01) * 0.5; |
|||
temp = data_M + data_F + 64; |
|||
|
|||
return temp; |
|||
} |
@ -0,0 +1,10 @@ |
|||
#ifndef MAX31730_H |
|||
#define MAX31730_H |
|||
|
|||
|
|||
int max31730_read(uint8_t addr, uint8_t reg, uint8_t *buf, int count); |
|||
void max31730_init(uint8_t addr); |
|||
float max31730_read_temperature(uint8_t addr, int device_num); |
|||
float max31730_read_local(uint8_t addr); |
|||
|
|||
#endif |
@ -0,0 +1,22 @@ |
|||
#include <stdio.h> |
|||
#include "_i2c.h" |
|||
#include "max6884.h" |
|||
|
|||
#define ADDR 0x52 |
|||
|
|||
void max6884_init() |
|||
{ |
|||
i2c6884_write(ADDR,0x16,0x20, 1); |
|||
i2c6884_write(ADDR,0x11,0x00, 1); |
|||
i2c6884_write(ADDR,0x12,0x00, 1); |
|||
i2c6884_write(ADDR,0x13,0x00, 1); |
|||
i2c6884_write(ADDR,0x14,0x00, 1); |
|||
i2c6884_write(ADDR,0x15,0x00, 1); |
|||
} |
|||
|
|||
signed char max6884_read(uint8_t reg) |
|||
{ |
|||
signed char buf; |
|||
i2c6884_read(ADDR, reg, &buf, 1); |
|||
return buf; |
|||
} |
@ -0,0 +1,8 @@ |
|||
#ifndef MAX6884_H |
|||
#define MAX6884_H |
|||
|
|||
void max6884_init(); |
|||
signed char max6884_read(uint8_t reg); |
|||
|
|||
#endif |
|||
|
Loading…
Reference in new issue