generated from hulk/gd32e23x_template
在board_config.h文件中添加#define SOFTWARE_IIC选项用以选择使用软件IIC还是硬件IIC,如果注释掉该行则为硬件IIC方式。并完整实现软件IIC功能。
This commit is contained in:
73
src/main.c
73
src/main.c
@@ -12,12 +12,14 @@
|
||||
#include "rs485.h"
|
||||
#include "led.h"
|
||||
#include "i2c.h"
|
||||
#include "soft_i2c.h"
|
||||
#include "ldc1612.h"
|
||||
#include "tmp112.h"
|
||||
#include "board_config.h"
|
||||
|
||||
uint32_t g_temperature_uint32;
|
||||
uint32_t g_eddy_current_value_uint32;
|
||||
#ifdef SOFTWARE_IIC
|
||||
#include "soft_i2c.h"
|
||||
#else
|
||||
#include "i2c.h"
|
||||
#endif
|
||||
|
||||
void watchdog_init(void) {
|
||||
/* Enable the LSI clock */
|
||||
@@ -59,73 +61,16 @@ int main(void) {
|
||||
|
||||
// watchdog_init();
|
||||
/* configure I2C */
|
||||
// i2c_gpio_config();
|
||||
// i2c_config();
|
||||
soft_i2c_config();
|
||||
|
||||
// ldc1612_iic_get_sensor_infomation();
|
||||
ldc1612_iic_get_sensor_infomation();
|
||||
/* configure LDC1612 */
|
||||
// ldc1612_single_ch0_config();
|
||||
|
||||
uint8_t data[2] = {0};
|
||||
|
||||
printf("Start\n");
|
||||
|
||||
|
||||
ldc1612_single_ch0_config();
|
||||
|
||||
/* Initialize watchdog */
|
||||
watchdog_init();
|
||||
|
||||
while (1) {
|
||||
soft_i2c_config();
|
||||
printf("111\n");
|
||||
|
||||
soft_i2c_start();
|
||||
soft_i2c_send_byte((0x2B << 1));
|
||||
if (!soft_i2c_wait_ack())
|
||||
{
|
||||
printf("NACK\n");
|
||||
}
|
||||
|
||||
|
||||
soft_i2c_send_byte(0x7E);
|
||||
if (!soft_i2c_wait_ack())
|
||||
{
|
||||
printf("NACK\n");
|
||||
}
|
||||
|
||||
soft_i2c_delay();
|
||||
soft_i2c_start();
|
||||
|
||||
soft_i2c_send_byte((0x2B << 1) + 1);
|
||||
if (!soft_i2c_wait_ack())
|
||||
{
|
||||
printf("NACK\n");
|
||||
}
|
||||
|
||||
soft_i2c_delay();
|
||||
|
||||
data[0] = soft_i2c_receive_byte(1);
|
||||
data[1] = soft_i2c_receive_byte(0);
|
||||
|
||||
delay_us(5);
|
||||
soft_i2c_stop();
|
||||
|
||||
printf("0x%x 0x%x\n", data[0], data[1]);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// i2c_start();
|
||||
// delay_ms(1);
|
||||
// i2c_stop();
|
||||
// delay_ms(1);
|
||||
delay_ms(1000);
|
||||
// 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\n");
|
||||
delay_ms(99);
|
||||
fwdgt_counter_reload();
|
||||
}
|
||||
|
Reference in New Issue
Block a user