IIC发送和接收函数的printf函数改为条件编译,条件在main.h

This commit is contained in:
yelvlab 2024-12-24 11:17:25 +08:00
parent 05fb90c727
commit 8fa7ed32d8
3 changed files with 37 additions and 0 deletions

View File

@ -8,6 +8,7 @@
#include "gd32e23x_it.h"
#include "gd32e23x.h"
#include "systick.h"
#include "main.h"
#include <stdbool.h>
#include <string.h>
#include <stdio.h>

View File

@ -35,4 +35,6 @@ OF SUCH DAMAGE.
#ifndef MAIN_H
#define MAIN_H
#define DEBUG_VERBOES
#endif /* MAIN_H */

View File

@ -158,7 +158,9 @@ uint8_t i2c_write_16bits(uint8_t slave_addr, uint8_t reg_addr, uint8_t data[2])
} else {
timeout = 0;
state = I2C_START;
#ifdef DEBUG_VERBOES:
printf("i2c bus is busy in WRITE BYTE!\n");
#endif
}
break;
case I2C_SEND_ADDRESS:
@ -173,7 +175,9 @@ uint8_t i2c_write_16bits(uint8_t slave_addr, uint8_t reg_addr, uint8_t data[2])
} else {
timeout = 0;
state = I2C_START;
#ifdef DEBUG_VERBOES:
printf("i2c master sends start signal timeout in WRITE BYTE!\n");
#endif
}
break;
case I2C_CLEAR_ADDRESS_FLAG:
@ -188,7 +192,9 @@ uint8_t i2c_write_16bits(uint8_t slave_addr, uint8_t reg_addr, uint8_t data[2])
} else {
timeout = 0;
state = I2C_START;
#ifdef DEBUG_VERBOES:
printf("i2c master clears address flag timeout in WRITE BYTE!\n");
#endif
}
break;
case I2C_TRANSMIT_DATA:
@ -203,7 +209,9 @@ uint8_t i2c_write_16bits(uint8_t slave_addr, uint8_t reg_addr, uint8_t data[2])
} else {
timeout = 0;
state = I2C_START;
#ifdef DEBUG_VERBOES:
printf("i2c master sends data timeout in WRITE BYTE!\n");
#endif
}
/* wait until BTC bit is set */
@ -217,7 +225,9 @@ uint8_t i2c_write_16bits(uint8_t slave_addr, uint8_t reg_addr, uint8_t data[2])
} else {
timeout = 0;
state = I2C_START;
#ifdef DEBUG_VERBOES:
printf("i2c master sends MSB data timeout in WRITE BYTE!\n");
#endif
}
/* wait until BTC bit is set */
@ -232,7 +242,9 @@ uint8_t i2c_write_16bits(uint8_t slave_addr, uint8_t reg_addr, uint8_t data[2])
} else {
timeout = 0;
state = I2C_START;
#ifdef DEBUG_VERBOES:
printf("i2c master sends LSB data timeout in WRITE BYTE!\n");
#endif
}
/* wait until BTC bit is set */
@ -245,7 +257,9 @@ uint8_t i2c_write_16bits(uint8_t slave_addr, uint8_t reg_addr, uint8_t data[2])
} else {
timeout = 0;
state = I2C_START;
#ifdef DEBUG_VERBOES:
printf("i2c master sends data timeout in WRITE BYTE!\n");
#endif
}
break;
case I2C_STOP:
@ -262,14 +276,18 @@ uint8_t i2c_write_16bits(uint8_t slave_addr, uint8_t reg_addr, uint8_t data[2])
} else {
timeout = 0;
state = I2C_START;
#ifdef DEBUG_VERBOES:
printf("i2c master sends stop signal timeout in WRITE BYTE!\n");
#endif
}
break;
default:
state = I2C_START;
i2c_timeout_flag = I2C_OK;
timeout = 0;
#ifdef DEBUG_VERBOES:
printf("i2c master sends start signal in WRITE BYTE.\n");
#endif
break;
}
}
@ -301,7 +319,9 @@ uint8_t i2c_read_16bits(uint8_t slave_addr, uint8_t reg_addr, uint8_t *data) {
// i2c_bus_reset();
timeout = 0;
state = I2C_START;
#ifdef DEBUG_VERBOES:
printf("i2c bus is busy in READ!\n");
#endif
}
}
/* send the start signal */
@ -328,7 +348,9 @@ uint8_t i2c_read_16bits(uint8_t slave_addr, uint8_t reg_addr, uint8_t *data) {
timeout = 0;
state = I2C_START;
read_cycle = RESET;
#ifdef DEBUG_VERBOES:
printf("i2c master sends start signal timeout in READ!\n");
#endif
}
break;
case I2C_CLEAR_ADDRESS_FLAG:
@ -348,7 +370,9 @@ uint8_t i2c_read_16bits(uint8_t slave_addr, uint8_t reg_addr, uint8_t *data) {
timeout = 0;
state = I2C_START;
read_cycle = RESET;
#ifdef DEBUG_VERBOES:
printf("i2c master clears address flag timeout in READ!\n");
#endif
}
break;
case I2C_TRANSMIT_DATA:
@ -365,7 +389,9 @@ uint8_t i2c_read_16bits(uint8_t slave_addr, uint8_t reg_addr, uint8_t *data) {
timeout = 0;
state = I2C_START;
read_cycle = RESET;
#ifdef DEBUG_VERBOES:
printf("i2c master wait data buffer is empty timeout in READ!\n");
#endif
}
/* wait until BTC bit is set */
while ((!i2c_flag_get(I2C0, I2C_FLAG_BTC)) && (timeout < I2C_TIME_OUT)) {
@ -379,7 +405,9 @@ uint8_t i2c_read_16bits(uint8_t slave_addr, uint8_t reg_addr, uint8_t *data) {
timeout = 0;
state = I2C_START;
read_cycle = RESET;
#ifdef DEBUG_VERBOES:
printf("i2c master sends register address timeout in READ!\n");
#endif
}
} else {
while (number_of_byte) {
@ -404,7 +432,9 @@ uint8_t i2c_read_16bits(uint8_t slave_addr, uint8_t reg_addr, uint8_t *data) {
timeout = 0;
state = I2C_START;
read_cycle = 0;
#ifdef DEBUG_VERBOES:
printf("i2c master sends data timeout in READ!\n");
#endif
}
}
timeout = 0;
@ -424,7 +454,9 @@ uint8_t i2c_read_16bits(uint8_t slave_addr, uint8_t reg_addr, uint8_t *data) {
timeout = 0;
state = I2C_START;
read_cycle = 0;
#ifdef DEBUG_VERBOES:
printf("i2c master sends stop signal timeout in READ!\n");
#endif
}
break;
default:
@ -432,7 +464,9 @@ uint8_t i2c_read_16bits(uint8_t slave_addr, uint8_t reg_addr, uint8_t *data) {
read_cycle = 0;
i2c_timeout_flag = I2C_OK;
timeout = 0;
#ifdef DEBUG_VERBOES:
printf("i2c master sends start signal in READ.\n");
#endif
break;
}
}