change iic speed to 20K

This commit is contained in:
yelvlab 2024-12-19 20:12:28 +08:00
parent fd06d54fdc
commit e2c2e81247
3 changed files with 67 additions and 16 deletions

View File

@ -30,11 +30,27 @@
#define SENSOR_RESET_REG 0X1C
#define SET_DRIVER_CURRENT_REG 0X1E
#define RCOUNT_CH0_REG 0x08
#define SETTLECOUNT_CH0_REG 0x10
#define CLOCK_DIVIDERS_CH0_REG 0x14
#define ERROR_CONFIG_REG 0X19
#define MUX_CONFIG_REG 0x1B
#define DRIVE_CURRENT_CH0_REG 0x1E
#define SENSOR_CONFIG_REG 0X1A
#define READ_MANUFACTURER_ID 0X7E
#define READ_DEVICE_ID 0X7F
/******************************************************************************/
#define CHANNEL_0 0
#define CHANNEL_1 1
/******************************************************************************/
#define CONVERSION_TIME_CH0 0X0546 //0536
#define CONVERSION_OFFSET_CH0 0X0000
#define LC_STABILIZE_TIME_CH0 0X001E //30
typedef enum {
I2C_START = 0,
@ -49,7 +65,7 @@ typedef enum {
#define I2C_FAIL 0
#define I2C_END 1
#define I2C_SPEED 100000
#define I2C_SPEED 20000
#define RCU_GPIO_I2C RCU_GPIOF
#define RCU_I2C RCU_I2C0
#define I2C_SCL_PORT GPIOF

View File

@ -157,6 +157,39 @@ void I2C_scan(void) {
}
}
/** @brief set conversion interval time.
@param channel LDC1612 has total two channels.
@param result The value to be set.
* */
void ldc1612_set_conversion_time(uint8_t channel, uint16_t result) {
uint8_t data[2] = {0};
data[0] = (result >> 8) & 0xFF;
data[1] = result & 0xFF;
ldc1612_iic_write_16bits(SET_CONVERSION_TIME_REG_START + channel, data);
}
/** @brief set conversion offset.
@param channel LDC1612 has total two channels.
@param result The value to be set.
* */
void ldc1612_set_conversion_offset(uint8_t channel, uint16_t result) {
uint8_t data[2] = {0};
data[0] = (result >> 8) & 0xFF;
data[1] = result & 0xFF;
ldc1612_iic_write_16bits(SET_CONVERSION_OFFSET_REG_START + channel, data);
}
/** @brief Before conversion,wait LC sensor stabilize for a short time.
@param channel LDC1612 has total two channels.
@param result The value to be set.
* */
void ldc1612_set_LC_stabilize_time(uint8_t channel, uint16_t result) {
uint8_t data[2] = {0};
data[0] = (result >> 8) & 0xFF;
data[1] = result & 0xFF;
ldc1612_iic_write_16bits(SET_LC_STABILIZE_REG_START + channel, data);
}
int LDC1612_IIC_read_16bits(uint8_t reg, uint16_t *data) {
uint16_t timeout = 0;
@ -262,9 +295,8 @@ int LDC1612_IIC_read_16bits(uint8_t reg, uint16_t *data) {
void ldc1612_iic_get_sensor_infomation(void) {
uint16_t data = 0;
LDC1612_IIC_read_16bits(READ_DEVICE_ID, &data);
LDC1612_IIC_read_16bits(READ_MANUFACTURER_ID, &data);
printf("\tManufacturer: 0x%x\r\n", data);
// delay_ms(5000);
LDC1612_IIC_read_16bits(READ_DEVICE_ID, &data);
printf("\tDevice: 0x%x\r\n", data);
}
@ -306,7 +338,7 @@ uint8_t ldc1612_iic_read_16bits(uint8_t reg_addr, uint8_t *data) {
/* whether to send ACK or not for the next byte */
i2c_ackpos_config(I2C0, I2C_ACKPOS_NEXT);
} else {
i2c_bus_reset();
// i2c_bus_reset();
timeout = 0;
state = I2C_START;
printf("i2c bus is busy in READ!\n");

View File

@ -60,20 +60,23 @@ int main(void) {
printf("\r\n");
delay_ms(500);
ldc1612_iic_get_sensor_infomation();
uint16_t device_id = 0;
device_id = ldc1612_get_deveice_id();
printf("device id = 0x%x\r\n", device_id);
delay_ms(100);
device_id = 0;
device_id = ldc1612_get_manufacturer_id();
printf("device id = 0x%x\r\n", device_id);
uint8_t data[2] = {0x05, 0x36};
ldc1612_iic_write_16bits(SET_CONVERSION_TIME_REG_START, data);
// uint16_t device_id = 0;
// device_id = ldc1612_get_deveice_id();
// printf("device id = 0x%x\r\n", device_id);
//
// delay_ms(100);
//
// device_id = 0;
// device_id = ldc1612_get_manufacturer_id();
// printf("device id = 0x%x\r\n", device_id);
uint16_t result = {0x0546};
uint8_t data[2] = {0};
data[0] = (result >> 8) & 0xFF;
data[1] = result & 0xFF;
printf("data[0] = 0x%x, data[1] = 0x%x\r\n", data[0], data[1]);
while (1) {
// delay_ms(1000);