使用硬件IIC实现回去数据,并且,间隔缩小到300ms

This commit is contained in:
2025-01-07 15:42:56 +08:00
parent 997637efcf
commit aee082068e
8 changed files with 91 additions and 7 deletions

View File

@@ -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_DIV64); // Set timeout to 1 seconds (625 / 0.625 KHz)
fwdgt_config(625, FWDGT_PSC_DIV256); // Set timeout to 1 seconds (625 / 0.625 KHz)
/* Enable FWDGT */
fwdgt_enable();

43
src/gd60914.c Normal file
View File

@@ -0,0 +1,43 @@
//
// Created by dell on 25-1-7.
//
#include "gd60914.h"
void gd60914_get_object_tempture(void) {
#ifdef SOFTWARE_IIC
soft_i2c_config();
#else
i2c_config();
#endif
uint8_t data[2] = {0};
#ifdef SOFTWARE_IIC
soft_i2c_read_16bits(GD60914_ADDR, GD60914_OBJ_TEMP, data);
#else
i2c_read_16bits(GD60914_ADDR, GD60914_OBJ_TEMP, data);
#endif
delay_ms(300);
#ifdef SOFTWARE_IIC
soft_i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, data);
#else
i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, data);
#endif
printf("%d\r\n", data[1] << 8 | data[0]);
}
void gd60914_read_temp(void) {
uint8_t value[2] = {0};
#ifdef SOFTWARE_IIC
soft_i2c_read_16bits(GD60914_ADDR, GD60914_OBJ_TEMP, value);
#else
i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, value);
#endif
printf("%x %x\r\n", value[1], value[0]);
}

View File

@@ -27,6 +27,12 @@ int main(void)
/* configure FWDGT */
watchdog_init();
#ifdef SOFTWARE_IIC
soft_i2c_config();
#else
i2c_config();
#endif
printf("system start!\r\n");
ultrasonic_config();
@@ -34,14 +40,13 @@ int main(void)
// gpio_bit_write(RS485_EN_PORT, RS485_EN_PIN, RESET);
while(1){
// printf("hello world!\r\n");
delay_ms(500);
gd60914_get_object_tempture();
delay_ms(50);
ultrasonic_pwm_out_cycles(ULTRASONIC_TX_CYCLES);
// delay_ms(2);
// g_distance_uint16 = ultrasonic_calc_distance();
// printf("Distance: %d cm\r\n", g_distance_uint16);
watchdog_reload();
}
}

View File

@@ -11,7 +11,7 @@
\retval none
*/
void soft_i2c_delay(void) {
delay_us(20); // Adjust delay as needed
delay_us(1); // Adjust delay as needed
/* delay to freq
* 15KHz: delay_us(20);
* 65KHz: delay_us(1);