diff --git a/inc/rs485_protocol.h b/inc/rs485_protocol.h index b358deb..6b8ed06 100644 --- a/inc/rs485_protocol.h +++ b/inc/rs485_protocol.h @@ -48,4 +48,6 @@ validation_result_t validate_package_type(uint8_t* data); validation_result_t validate_data_length(uint8_t* data); +void gd60914_tempture(void); + #endif //RS485_PROTOCOL_H diff --git a/src/fwdgt.c b/src/fwdgt.c index 688572f..4beebce 100644 --- a/src/fwdgt.c +++ b/src/fwdgt.c @@ -15,7 +15,7 @@ void watchdog_init(void) { rcu_osci_stab_wait(RCU_IRC40K); /* 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 */ fwdgt_enable(); diff --git a/src/gd60914.c b/src/gd60914.c index ccdeb21..b9662dc 100644 --- a/src/gd60914.c +++ b/src/gd60914.c @@ -11,23 +11,31 @@ void gd60914_get_object_tempture(void) { i2c_config(); #endif - uint8_t data[2] = {0}; + static uint8_t sensor_validation_data[2]; + extern uint8_t g_temperature_uint8[2]; #ifdef SOFTWARE_IIC soft_i2c_read_16bits(GD60914_ADDR, GD60914_OBJ_TEMP, data); #else - i2c_read_16bits(GD60914_ADDR, GD60914_OBJ_TEMP, data); + i2c_read_16bits(GD60914_ADDR, GD60914_OBJ_TEMP, sensor_validation_data); #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 - soft_i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, data); + soft_i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, g_temperature_uint8); #else - i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, data); + i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, g_temperature_uint8); #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) { diff --git a/src/main.c b/src/main.c index 96ffd8b..547d512 100644 --- a/src/main.c +++ b/src/main.c @@ -6,6 +6,8 @@ */ #include "main.h" +volatile uint8_t g_temperature_uint8[2] = {0}; + /*! \brief main function \param[in] none @@ -34,8 +36,10 @@ int main(void) while(1){ // printf("hello world!\r\n"); - delay_ms(500); + // delay_ms(500); gd60914_get_object_tempture(); + // delay_ms(100); + // printf("%d\r\n", g_temperature_uint8[1] << 8 | g_temperature_uint8[0]); watchdog_reload(); } diff --git a/src/rs485_protocol.c b/src/rs485_protocol.c index ea8ce98..dd21581 100644 --- a/src/rs485_protocol.c +++ b/src/rs485_protocol.c @@ -4,6 +4,8 @@ #include "rs485_protocol.h" +extern uint8_t g_temperature_uint8[2]; + void process_command(uint8_t *cmd, size_t length) { char combined_str[3]; 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) { printf("%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0xCC); // eddy_current_value_report(); - } else if (strcmp(combined_str, "M2") == 0) { - printf("%c%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0x6B, 0xCC); + } else if (strcmp(combined_str, "M2") == 0) + { + // printf("%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, g_temperature_uint8[1], g_temperature_uint8[0], 0xCC); // tempture_value_report(); + gd60914_tempture(); } else if (strcmp(combined_str, "M3") == 0) { 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; } } + +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)); +} \ No newline at end of file