LibDriver MAX31855
Loading...
Searching...
No Matches
driver_max31855_read_test.c
Go to the documentation of this file.
1
36
38
39static max31855_handle_t gs_handle;
40
49uint8_t max31855_read_test(uint32_t times)
50{
51 uint8_t res;
52 uint32_t i;
53 max31855_info_t info;
54
55 /* link functions */
62
63 /* max31855 info */
64 res = max31855_info(&info);
65 if (res != 0)
66 {
67 max31855_interface_debug_print("max31855: get info failed.\n");
68
69 return 1;
70 }
71 else
72 {
73 /* print chip information */
74 max31855_interface_debug_print("max31855: chip is %s.\n", info.chip_name);
75 max31855_interface_debug_print("max31855: manufacturer is %s.\n", info.manufacturer_name);
76 max31855_interface_debug_print("max31855: interface is %s.\n", info.interface);
77 max31855_interface_debug_print("max31855: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
78 max31855_interface_debug_print("max31855: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
79 max31855_interface_debug_print("max31855: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
80 max31855_interface_debug_print("max31855: max current is %0.2fmA.\n", info.max_current_ma);
81 max31855_interface_debug_print("max31855: max temperature is %0.1fC.\n", info.temperature_max);
82 max31855_interface_debug_print("max31855: min temperature is %0.1fC.\n", info.temperature_min);
83 }
84
85 /* max31855 init */
86 res = max31855_init(&gs_handle);
87 if (res != 0)
88 {
89 max31855_interface_debug_print("max31855: init failed.\n");
90
91 return 1;
92 }
93
94 /* start read test */
95 max31855_interface_debug_print("max31855: start read test.\n");
96
97 for (i = 0; i < times; i++)
98 {
99 int16_t thermocouple_raw;
100 float thermocouple_temp;
101 int16_t reference_junction_raw;
102 float reference_junction_temp;
103
104 /* read data */
105 res = max31855_read(&gs_handle, &thermocouple_raw, &thermocouple_temp,
106 &reference_junction_raw, &reference_junction_temp);
107 if (res != 0)
108 {
109 max31855_interface_debug_print("max31855: read failed.\n");
110 (void)max31855_deinit(&gs_handle);
111
112 return 1;
113 }
114
115 /* output */
116 max31855_interface_debug_print("max31855: thermocouple raw is %d.\n", thermocouple_raw);
117 max31855_interface_debug_print("max31855: thermocouple is %0.2fC.\n", thermocouple_temp);
118 max31855_interface_debug_print("max31855: reference junction raw is %d.\n", reference_junction_raw);
119 max31855_interface_debug_print("max31855: reference junction is %0.2fC.\n", reference_junction_temp);
120
121 /* delay 1000ms */
123 }
124
125 /* finish read test */
126 max31855_interface_debug_print("max31855: finish read test.\n");
127 (void)max31855_deinit(&gs_handle);
128
129 return 0;
130}
driver max31855 read test header file
uint8_t max31855_deinit(max31855_handle_t *handle)
close the chip
uint8_t max31855_info(max31855_info_t *info)
get chip's information
uint8_t max31855_read(max31855_handle_t *handle, int16_t *thermocouple_raw, float *thermocouple_temp, int16_t *reference_junction_raw, float *reference_junction_temp)
read the temperature
struct max31855_info_s max31855_info_t
max31855 information structure definition
struct max31855_handle_s max31855_handle_t
max31855 handle structure definition
uint8_t max31855_init(max31855_handle_t *handle)
initialize the chip
uint8_t max31855_interface_spi_read_cmd(uint8_t *buf, uint16_t len)
interface spi bus read command
uint8_t max31855_interface_spi_deinit(void)
interface spi bus deinit
void max31855_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t max31855_interface_spi_init(void)
interface spi bus init
void max31855_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t max31855_read_test(uint32_t times)
read test
uint32_t driver_version
char manufacturer_name[32]