generated from hulk/gd32e23x_template
添加board_config.h作为全部板上IO的宏定义位置,独立soft_i2c为单独文件
This commit is contained in:
38
src/main.c
38
src/main.c
@@ -12,6 +12,7 @@
|
||||
#include "rs485.h"
|
||||
#include "led.h"
|
||||
#include "i2c.h"
|
||||
#include "soft_i2c.h"
|
||||
#include "ldc1612.h"
|
||||
#include "tmp112.h"
|
||||
|
||||
@@ -75,10 +76,26 @@ int main(void) {
|
||||
watchdog_init();
|
||||
|
||||
while (1) {
|
||||
si2c_config();
|
||||
soft_i2c_config();
|
||||
printf("111\n");
|
||||
|
||||
i2c_start();
|
||||
i2c_send_byte((0x2B << 1));
|
||||
if (!i2c_wait_ack())
|
||||
{
|
||||
printf("NACK\n");
|
||||
}
|
||||
|
||||
|
||||
i2c_send_byte(0x7E);
|
||||
if (!i2c_wait_ack())
|
||||
{
|
||||
printf("NACK\n");
|
||||
}
|
||||
|
||||
i2c_delay();
|
||||
i2c_start();
|
||||
|
||||
i2c_send_byte((0x2B << 1) + 1);
|
||||
if (!i2c_wait_ack())
|
||||
{
|
||||
@@ -87,30 +104,11 @@ int main(void) {
|
||||
|
||||
i2c_delay();
|
||||
|
||||
i2c_send_byte(0x7E);
|
||||
// if (!i2c_wait_ack())
|
||||
// {
|
||||
// printf("NACK\n");
|
||||
// }
|
||||
|
||||
i2c_delay();
|
||||
i2c_start();
|
||||
|
||||
i2c_send_byte((0x2B << 1));
|
||||
if (!i2c_wait_ack())
|
||||
{
|
||||
printf("NACK\n");
|
||||
}
|
||||
|
||||
i2c_delay();
|
||||
|
||||
data[0] = i2c_receive_byte(1);
|
||||
i2c_delay();
|
||||
data[1] = i2c_receive_byte(0);
|
||||
|
||||
delay_us(5);
|
||||
i2c_stop();
|
||||
// printf("OK\n");
|
||||
|
||||
printf("0x%x 0x%x\n", data[0], data[1]);
|
||||
|
||||
|
Reference in New Issue
Block a user