generated from hulk/gd32e23x_template
主函数中重复执行,500ms间隔获取温度数据
This commit is contained in:
parent
e86f8b0dd3
commit
c12273fd46
@ -48,4 +48,6 @@ validation_result_t validate_package_type(uint8_t* data);
|
|||||||
|
|
||||||
validation_result_t validate_data_length(uint8_t* data);
|
validation_result_t validate_data_length(uint8_t* data);
|
||||||
|
|
||||||
|
void gd60914_tempture(void);
|
||||||
|
|
||||||
#endif //RS485_PROTOCOL_H
|
#endif //RS485_PROTOCOL_H
|
||||||
|
@ -15,7 +15,7 @@ void watchdog_init(void) {
|
|||||||
rcu_osci_stab_wait(RCU_IRC40K);
|
rcu_osci_stab_wait(RCU_IRC40K);
|
||||||
|
|
||||||
/* Configure FWDGT counter clock: 40KHz(IRC40K) / 64 = 0.625 KHz */
|
/* Configure FWDGT counter clock: 40KHz(IRC40K) / 64 = 0.625 KHz */
|
||||||
fwdgt_config(625, FWDGT_PSC_DIV256); // Set timeout to 1 seconds (625 / 0.625 KHz)
|
fwdgt_config(625, FWDGT_PSC_DIV64); // Set timeout to 1 seconds (625 / 0.625 KHz)
|
||||||
|
|
||||||
/* Enable FWDGT */
|
/* Enable FWDGT */
|
||||||
fwdgt_enable();
|
fwdgt_enable();
|
||||||
|
@ -11,23 +11,31 @@ void gd60914_get_object_tempture(void) {
|
|||||||
i2c_config();
|
i2c_config();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t data[2] = {0};
|
static uint8_t sensor_validation_data[2];
|
||||||
|
extern uint8_t g_temperature_uint8[2];
|
||||||
|
|
||||||
#ifdef SOFTWARE_IIC
|
#ifdef SOFTWARE_IIC
|
||||||
soft_i2c_read_16bits(GD60914_ADDR, GD60914_OBJ_TEMP, data);
|
soft_i2c_read_16bits(GD60914_ADDR, GD60914_OBJ_TEMP, data);
|
||||||
#else
|
#else
|
||||||
i2c_read_16bits(GD60914_ADDR, GD60914_OBJ_TEMP, data);
|
i2c_read_16bits(GD60914_ADDR, GD60914_OBJ_TEMP, sensor_validation_data);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
delay_ms(300);
|
if (sensor_validation_data[0] != 0xAA || sensor_validation_data[1] != 0x55) {
|
||||||
|
#ifdef DEBUG_VERBOES
|
||||||
|
printf("sensor error\r\n");
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
delay_ms(350);
|
||||||
|
|
||||||
#ifdef SOFTWARE_IIC
|
#ifdef SOFTWARE_IIC
|
||||||
soft_i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, data);
|
soft_i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, g_temperature_uint8);
|
||||||
#else
|
#else
|
||||||
i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, data);
|
i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, g_temperature_uint8);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
printf("%d\r\n", data[1] << 8 | data[0]);
|
// printf("%d\r\n", g_temperature_uint8[1] << 8 | g_temperature_uint8[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gd60914_read_temp(void) {
|
void gd60914_read_temp(void) {
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
*/
|
*/
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
volatile uint8_t g_temperature_uint8[2] = {0};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief main function
|
\brief main function
|
||||||
\param[in] none
|
\param[in] none
|
||||||
@ -34,8 +36,10 @@ int main(void)
|
|||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
// printf("hello world!\r\n");
|
// printf("hello world!\r\n");
|
||||||
delay_ms(500);
|
// delay_ms(500);
|
||||||
gd60914_get_object_tempture();
|
gd60914_get_object_tempture();
|
||||||
|
// delay_ms(100);
|
||||||
|
// printf("%d\r\n", g_temperature_uint8[1] << 8 | g_temperature_uint8[0]);
|
||||||
|
|
||||||
watchdog_reload();
|
watchdog_reload();
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include "rs485_protocol.h"
|
#include "rs485_protocol.h"
|
||||||
|
|
||||||
|
extern uint8_t g_temperature_uint8[2];
|
||||||
|
|
||||||
void process_command(uint8_t *cmd, size_t length) {
|
void process_command(uint8_t *cmd, size_t length) {
|
||||||
char combined_str[3];
|
char combined_str[3];
|
||||||
validation_result_t validate = VALIDATION_SUCCESS;
|
validation_result_t validate = VALIDATION_SUCCESS;
|
||||||
@ -20,9 +22,11 @@ void process_command(uint8_t *cmd, size_t length) {
|
|||||||
if (strcmp(combined_str, "M1") == 0) {
|
if (strcmp(combined_str, "M1") == 0) {
|
||||||
printf("%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0xCC);
|
printf("%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0xCC);
|
||||||
// eddy_current_value_report();
|
// eddy_current_value_report();
|
||||||
} else if (strcmp(combined_str, "M2") == 0) {
|
} else if (strcmp(combined_str, "M2") == 0)
|
||||||
printf("%c%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0x6B, 0xCC);
|
{
|
||||||
|
// printf("%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, g_temperature_uint8[1], g_temperature_uint8[0], 0xCC);
|
||||||
// tempture_value_report();
|
// tempture_value_report();
|
||||||
|
gd60914_tempture();
|
||||||
} else if (strcmp(combined_str, "M3") == 0)
|
} else if (strcmp(combined_str, "M3") == 0)
|
||||||
{
|
{
|
||||||
printf("%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0xCC);
|
printf("%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0xCC);
|
||||||
@ -90,3 +94,15 @@ validation_result_t validate_data_length(uint8_t *data) {
|
|||||||
return VALIDATION_LENGTH_ERROR;
|
return VALIDATION_LENGTH_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gd60914_tempture(void) {
|
||||||
|
static uint8_t package_header[3] = {0xB5, 0xF0, 0x02};
|
||||||
|
|
||||||
|
uint8_t combined_data[5];
|
||||||
|
memcpy(combined_data, package_header, 3);
|
||||||
|
memcpy(combined_data + 3, g_temperature_uint8, 2);
|
||||||
|
|
||||||
|
printf("%c%c%c", package_header[0], package_header[1], package_header[2]);
|
||||||
|
printf("%c%c", g_temperature_uint8[1], g_temperature_uint8[0]);
|
||||||
|
printf("%c", calculate_crc(combined_data, 6));
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user