-
Notifications
You must be signed in to change notification settings - Fork 0
/
MHZ19_sensor.c
54 lines (52 loc) · 1.03 KB
/
MHZ19_sensor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "STM32_USART.h"
#include "MHZ19_sensor.h"
ErrorStatus Z19MeasureCO2(USART_TypeDef * USARTx, int* value)
{
int i = 0;
char data[9];
//Send command
UsartPutC(USARTx,0xFF);
UsartPutC(USARTx,0x01);
UsartPutC(USARTx,0x86);
for (i = 0; i < 5; i++)
{
if (UsartPutC(USARTx,0x00) == ERROR)
return ERROR;
}
if (UsartPutC(USARTx,0x79) == ERROR)
return ERROR;
//Get answer
for (i = 0; i < 9; i++)
{
if(UsartGetC(USARTx,&data[i]) == ERROR)
return ERROR;
}
*value = (data[2]*256+data[3]);
return SUCCESS;
}
void Z19CalibrateZero(USART_TypeDef * USARTx)
{
int i = 0;
UsartPutC(USARTx,0xFF);
UsartPutC(USARTx,0x01);
UsartPutC(USARTx,0x87);
for (i=0;i<5;i++)
{
UsartPutC(USARTx,0x00);
}
UsartPutC(USARTx,0x78);
}
void Z19CalibrateSpan(USART_TypeDef * USARTx)
{
int i = 0;
UsartPutC(USARTx,0xFF);
UsartPutC(USARTx,0x01);
UsartPutC(USARTx,0x88);
UsartPutC(USARTx,0x07);
UsartPutC(USARTx,0xD0);
for (i=0;i<3;i++)
{
UsartPutC(USARTx,0x00);
}
UsartPutC(USARTx,0xA0);
}