generated from hulk/gd32e23x_template
	设置喂狗时间为1S,并添加M3指令为复位指令,但是可能无效。修改了数据获取方式,从一直持续获取改为每次申请获取。
This commit is contained in:
		| @@ -28,7 +28,7 @@ | |||||||
|  |  | ||||||
| /******************************************************************************/ | /******************************************************************************/ | ||||||
|  |  | ||||||
| #define I2C_TIME_OUT    (uint16_t)(10000) | #define I2C_TIME_OUT    (uint16_t)(5000) | ||||||
| #define I2C_OK          1 | #define I2C_OK          1 | ||||||
| #define I2C_FAIL        0 | #define I2C_FAIL        0 | ||||||
| #define I2C_END         1 | #define I2C_END         1 | ||||||
|   | |||||||
| @@ -43,12 +43,13 @@ | |||||||
|  |  | ||||||
| /******************************************************************************/ | /******************************************************************************/ | ||||||
|  |  | ||||||
| #define LDC1612_CONVERSION_TIME_CH0        0X0546  //0536 | #define LDC1612_CONVERSION_TIME_CH0        0x0546  //0536 | ||||||
| #define LDC1612_DRIVE_CURRENT              0X9000  //A000 | #define LDC1612_DRIVE_CURRENT              0x9000  //A000 | ||||||
| #define LDC1612_MUX_CONFIG                 0X020C  // no auto scan and filter bandwidth 3.3MHz | #define LDC1612_MUX_CONFIG                 0x020C  // no auto scan and filter bandwidth 3.3MHz | ||||||
| #define LDC1612_SENSOR_CONFIG              0X1601 | #define LDC1612_SENSOR_CONFIG              0x1601 | ||||||
| #define LDC1612_ERROR_CONFIG               0x0000 | #define LDC1612_ERROR_CONFIG               0x0000 | ||||||
| #define LC_STABILIZE_TIME_CH0              0X001E //30 | #define LC_STABILIZE_TIME_CH0              0x001E //30 | ||||||
|  | #define LDC1612_RESET_DEV                  0x8000 //[15:0] 0b1000 0000 0000 0000 | ||||||
|  |  | ||||||
| /******************************************************************************/ | /******************************************************************************/ | ||||||
|  |  | ||||||
|   | |||||||
| @@ -39,4 +39,6 @@ OF SUCH DAMAGE. | |||||||
|  |  | ||||||
| void watchdog_init(void); | void watchdog_init(void); | ||||||
|  |  | ||||||
|  | void reset_mcu(void); | ||||||
|  |  | ||||||
| #endif /* MAIN_H */ | #endif /* MAIN_H */ | ||||||
|   | |||||||
| @@ -13,6 +13,9 @@ | |||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
| #include <sys/types.h> | #include <sys/types.h> | ||||||
|  | #include "i2c.h" | ||||||
|  | #include "ldc1612.h" | ||||||
|  | #include "tmp112.h" | ||||||
|  |  | ||||||
| /******************************************************************************/ | /******************************************************************************/ | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										24
									
								
								src/main.c
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								src/main.c
									
									
									
									
									
								
							| @@ -23,16 +23,24 @@ void watchdog_init(void) { | |||||||
|     rcu_osci_on(RCU_IRC40K); |     rcu_osci_on(RCU_IRC40K); | ||||||
|     rcu_osci_stab_wait(RCU_IRC40K); |     rcu_osci_stab_wait(RCU_IRC40K); | ||||||
|  |  | ||||||
|     /* Enable the FWDGT clock */ |     /* Configure FWDGT counter clock: 40KHz(IRC40K) / 64 = 0.625 KHz */ | ||||||
|     // rcu_periph_clock_enable(RCU_FWDGT); |     fwdgt_config(625, FWDGT_PSC_DIV64); // Set timeout to 1 seconds (625 / 0.625 KHz) | ||||||
|  |  | ||||||
|     /* Configure FWDGT counter clock: 40KHz(IRC40K) / 256 = 0.15625 KHz */ |  | ||||||
|     fwdgt_config(625, FWDGT_PSC_DIV256); // Set timeout to 4 seconds (625 / 0.15625 KHz) |  | ||||||
|  |  | ||||||
|     /* Enable FWDGT */ |     /* Enable FWDGT */ | ||||||
|     fwdgt_enable(); |     fwdgt_enable(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | void reset_mcu(void) { | ||||||
|  |     /* Enable the write access to the FWDGT_CTL register */ | ||||||
|  |     FWDGT_CTL = FWDGT_WRITEACCESS_ENABLE; | ||||||
|  |  | ||||||
|  |     /* Configure FWDGT to trigger a system reset */ | ||||||
|  |     fwdgt_config(5, FWDGT_PSC_DIV4); | ||||||
|  |  | ||||||
|  |     /* Reload the counter to trigger the reset */ | ||||||
|  |     fwdgt_counter_reload(); | ||||||
|  | } | ||||||
|  |  | ||||||
| /*! | /*! | ||||||
|     \brief      main function |     \brief      main function | ||||||
|     \param[in]  none |     \param[in]  none | ||||||
| @@ -57,14 +65,10 @@ int main(void) { | |||||||
|  |  | ||||||
|     /* Initialize watchdog */ |     /* Initialize watchdog */ | ||||||
|     watchdog_init(); |     watchdog_init(); | ||||||
|  |     printf("Hello, world!\n"); | ||||||
|  |  | ||||||
|     while (1) { |     while (1) { | ||||||
|         delay_ms(99); |         delay_ms(99); | ||||||
|         g_eddy_current_value_uint32 = 0; |  | ||||||
|         g_temperature_uint32 = 0; |  | ||||||
|         g_eddy_current_value_uint32 = ldc1612_get_raw_channel_result(CHANNEL_0); |  | ||||||
|         g_temperature_uint32 = tmp112a_get_raw_channel_result(); |  | ||||||
|         // printf("1"); |  | ||||||
|         fwdgt_counter_reload(); |         fwdgt_counter_reload(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										30
									
								
								src/rs485.c
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								src/rs485.c
									
									
									
									
									
								
							| @@ -53,8 +53,12 @@ void process_command(uint8_t *cmd, size_t length) { | |||||||
|             sprintf(combined_str, "%c%c", cmd[3], cmd[4]); |             sprintf(combined_str, "%c%c", cmd[3], cmd[4]); | ||||||
|             if (strcmp(combined_str, "M1") == 0) { |             if (strcmp(combined_str, "M1") == 0) { | ||||||
|                 eddy_current_value_report(); |                 eddy_current_value_report(); | ||||||
|             } else if (strcmp(combined_str, "M2") == 0) { |             } else if (strcmp(combined_str, "M2") == 0) | ||||||
|  |             { | ||||||
|                 tempture_value_report(); |                 tempture_value_report(); | ||||||
|  |             } else if (strcmp(combined_str, "M3") == 0) | ||||||
|  |             { | ||||||
|  |                 reset_mcu(); | ||||||
|             } else { |             } else { | ||||||
|                 printf("%c%c%c%c%c%c%c", 0xB5, 0xF0, 0x03, 0x65, 0x72, 0x72, 0x3C); |                 printf("%c%c%c%c%c%c%c", 0xB5, 0xF0, 0x03, 0x65, 0x72, 0x72, 0x3C); | ||||||
|                 return; |                 return; | ||||||
| @@ -120,10 +124,14 @@ validation_result_t validate_data_length(uint8_t *data) { | |||||||
| } | } | ||||||
|  |  | ||||||
| void eddy_current_value_report(void) { | void eddy_current_value_report(void) { | ||||||
|     package_data[0] = (g_eddy_current_value_uint32 >> 24) & 0xFF; |     static uint32_t eddy_current_value_uint32 = 0; | ||||||
|     package_data[1] = (g_eddy_current_value_uint32 >> 16) & 0xFF; |  | ||||||
|     package_data[2] = (g_eddy_current_value_uint32 >> 8) & 0xFF; |     eddy_current_value_uint32 = ldc1612_get_raw_channel_result(CHANNEL_0); | ||||||
|     package_data[3] = g_eddy_current_value_uint32 & 0xFF; |  | ||||||
|  |     package_data[0] = (eddy_current_value_uint32 >> 24) & 0xFF; | ||||||
|  |     package_data[1] = (eddy_current_value_uint32 >> 16) & 0xFF; | ||||||
|  |     package_data[2] = (eddy_current_value_uint32 >> 8) & 0xFF; | ||||||
|  |     package_data[3] = eddy_current_value_uint32 & 0xFF; | ||||||
|  |  | ||||||
|     uint8_t combined_data[7]; |     uint8_t combined_data[7]; | ||||||
|     memcpy(combined_data, package_header, 3); |     memcpy(combined_data, package_header, 3); | ||||||
| @@ -135,10 +143,14 @@ void eddy_current_value_report(void) { | |||||||
| } | } | ||||||
|  |  | ||||||
| void tempture_value_report(void) { | void tempture_value_report(void) { | ||||||
|     package_data[0] = (g_temperature_uint32 >> 24) & 0xFF; |     static uint32_t temperature_uint32 = 0; | ||||||
|     package_data[1] = (g_temperature_uint32 >> 16) & 0xFF; |  | ||||||
|     package_data[2] = (g_temperature_uint32 >> 8) & 0xFF; |     temperature_uint32 = tmp112a_get_raw_channel_result(); | ||||||
|     package_data[3] = g_temperature_uint32 & 0xFF; |  | ||||||
|  |     package_data[0] = (temperature_uint32 >> 24) & 0xFF; | ||||||
|  |     package_data[1] = (temperature_uint32 >> 16) & 0xFF; | ||||||
|  |     package_data[2] = (temperature_uint32 >> 8) & 0xFF; | ||||||
|  |     package_data[3] = temperature_uint32 & 0xFF; | ||||||
|  |  | ||||||
|     uint8_t combined_data[7]; |     uint8_t combined_data[7]; | ||||||
|     memcpy(combined_data, package_header, 3); |     memcpy(combined_data, package_header, 3); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user