generated from hulk/gd32e23x_template
Compare commits
No commits in common. "279c461de5237752e5142467c7c1eec6ace1c9af" and "bfd2296e0550ebe40b7845bb332a95203e2c85af" have entirely different histories.
279c461de5
...
bfd2296e05
@ -60,4 +60,6 @@ void I2C_scan(void);
|
||||
|
||||
int LDC1612_IIC_read_16bits(uint8_t reg, uint16_t *data);
|
||||
|
||||
|
||||
|
||||
#endif //LDC1612_H
|
||||
|
@ -43,5 +43,7 @@ OF SUCH DAMAGE.
|
||||
#define LED_IRQ TIMER16_IRQn
|
||||
|
||||
void led_config(void);
|
||||
void iicSendData(void);
|
||||
void iicReceiveData(void);
|
||||
|
||||
#endif /* MAIN_H */
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#include "LDC1612.h"
|
||||
|
||||
|
||||
|
||||
void I2C_config(void) {
|
||||
rcu_periph_clock_enable(RCU_IR_GPIO);
|
||||
rcu_periph_clock_enable(RCU_I2C);
|
||||
@ -24,6 +26,17 @@ void I2C_config(void) {
|
||||
i2c_ack_config(I2C0, I2C_ACK_ENABLE);
|
||||
}
|
||||
|
||||
// void LDC1612_Init(void) {
|
||||
// uint8_t RCOUNT0_ALL[3]={SET_CONVERSION_TIME_REG_START,0x05,0x36};//csdn
|
||||
// uint8_t SETTLECOUNT0_ALL[3]={SET_LC_STABILIZE_REG_START,0x00,0x0a};
|
||||
// uint8_t CLOCK_DIVIDERS0_ALL[3]={SET_FREQ_REG_START,0x10,0x02};
|
||||
// uint8_t ERROR_CONFIG_ALL[3]={ERROR_CONFIG_REG,0x00,0x00};
|
||||
// uint8_t MUX_CONFIG_ALL[3]={MUL_CONFIG_REG,0x82,0x0c};
|
||||
// uint8_t DRIVE_CURRENT0_ALL[3]={SET_DRIVER_CURRENT_REG,0x90,0x00};
|
||||
// uint8_t CONFIG_ALL[3]={SENSOR_CONFIG_REG,0x14,0x01};//csdn
|
||||
//
|
||||
// }
|
||||
|
||||
/**
|
||||
* @brief 扫描I2C总线,查找连接的设备
|
||||
*
|
||||
|
44
src/main.c
44
src/main.c
@ -39,6 +39,49 @@ void led_config(void) {
|
||||
nvic_irq_enable(LED_IRQ, 2);
|
||||
}
|
||||
|
||||
void iicSendData(void) {
|
||||
while (i2c_flag_get(I2C0, I2C_FLAG_I2CBSY));
|
||||
i2c_start_on_bus(I2C0);
|
||||
printf("1\r\n");
|
||||
while (!i2c_flag_get(I2C0, I2C_FLAG_SBSEND));
|
||||
i2c_master_addressing(I2C0, LDC1612_ADDR, I2C_TRANSMITTER);
|
||||
printf("2\r\n");
|
||||
while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND));
|
||||
i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND);
|
||||
printf("3\r\n");
|
||||
while (!i2c_flag_get(I2C0, I2C_FLAG_TBE));
|
||||
i2c_data_transmit(I2C0, 0x7E);
|
||||
printf("4\r\n");
|
||||
i2c_start_on_bus(I2C0);
|
||||
}
|
||||
|
||||
void iicReceiveData(void) {
|
||||
uint16_t data[3] = {0};
|
||||
i2c_start_on_bus(I2C0);
|
||||
// i2c_stop_on_bus(I2C0);
|
||||
printf("5\r\n");
|
||||
while (!i2c_flag_get(I2C0, I2C_FLAG_SBSEND));
|
||||
i2c_master_addressing(I2C0, LDC1612_ADDR, I2C_RECEIVER);
|
||||
printf("6\r\n");
|
||||
while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND));
|
||||
i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND);
|
||||
printf("7\r\n");
|
||||
i2c_ack_config(I2C0, I2C_ACK_DISABLE);
|
||||
while (!i2c_flag_get(I2C0, I2C_FLAG_RBNE));
|
||||
data[0] = i2c_data_receive(I2C0);
|
||||
while (!i2c_flag_get(I2C0, I2C_FLAG_RBNE));
|
||||
data[1] = i2c_data_receive(I2C0);
|
||||
while (!i2c_flag_get(I2C0, I2C_FLAG_RBNE));
|
||||
data[2] = i2c_data_receive(I2C0);
|
||||
|
||||
i2c_stop_on_bus(I2C0);
|
||||
i2c_ack_config(I2C0, I2C_ACK_ENABLE);
|
||||
|
||||
printf("data[0] = %x\r\n", data[0]);
|
||||
printf("data[1] = %x\r\n", data[1]);
|
||||
printf("data[2] = %x\r\n", data[2]);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief main function
|
||||
\param[in] none
|
||||
@ -52,6 +95,7 @@ int main(void) {
|
||||
led_config();
|
||||
I2C_config();
|
||||
|
||||
// delay_ms(5000);
|
||||
printf("\r\n");
|
||||
printf("XLSW-3DP-LDC1612! V0.0.1\r\n");
|
||||
printf("\r\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user