generated from hulk/gd32e23x_template
clean dev branch
This commit is contained in:
87
src/main.c
87
src/main.c
@@ -40,51 +40,6 @@ 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
|
||||
@@ -99,58 +54,16 @@ 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");
|
||||
|
||||
// uint16_t data[3] = {0};
|
||||
|
||||
// I2C_scan();
|
||||
|
||||
delay_ms(1000);
|
||||
|
||||
// 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);
|
||||
// // i2c_stop_on_bus(I2C0);
|
||||
|
||||
|
||||
// delay_ms(100);
|
||||
// i2c_start_on_bus(I2C0);
|
||||
// delay_ms(100);
|
||||
// i2c_stop_on_bus(I2C0);
|
||||
|
||||
|
||||
// i2c_stop_on_bus(I2C0);
|
||||
// i2c_ack_config(I2C0, I2C_ACK_ENABLE);
|
||||
|
||||
// iicSendData();
|
||||
// iicReceiveData();
|
||||
|
||||
int result = 0;
|
||||
result = LDC1612_IIC_read_16bits();
|
||||
printf("result = %d\r\n", result);
|
||||
|
||||
while(1){
|
||||
|
||||
|
||||
delay_ms(1000);
|
||||
printf("OK!!!\r\n");
|
||||
// iicSendData();
|
||||
|
||||
// i2c_flag_clear(I2C0, I2C_FLAG_I2CBSY);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user