generated from hulk/gd32e23x_template
	recevice function
This commit is contained in:
		| @@ -94,9 +94,12 @@ set(TARGET_CFLAGS_HARDWARE "-mcpu=cortex-m23 -mfloat-abi=soft -mthumb -mthumb-in | ||||
| #set(CMAKE_C_FLAGS_DEBUG     "-DDEBUG=0 -O0 -g") | ||||
| #set(CMAKE_CXX_FLAGS_DEBUG   "-DDEBUG=0 -O0 -g") | ||||
| #set(CMAKE_ASM_FLAGS_DEBUG   "-DDEBUG=0 -O0 -g") | ||||
| set(CMAKE_C_FLAGS_DEBUG     "-DDEBUG=0 -Os -g") | ||||
| set(CMAKE_CXX_FLAGS_DEBUG   "-DDEBUG=0 -Os -g") | ||||
| set(CMAKE_ASM_FLAGS_DEBUG   "-DDEBUG=0 -Os -g") | ||||
| set(CMAKE_C_FLAGS_DEBUG     "-DDEBUG=0 -O2 -g") | ||||
| set(CMAKE_CXX_FLAGS_DEBUG   "-DDEBUG=0 -O2 -g") | ||||
| set(CMAKE_ASM_FLAGS_DEBUG   "-DDEBUG=0 -O2 -g") | ||||
| #set(CMAKE_C_FLAGS_DEBUG     "-DDEBUG=0 -Os -g") | ||||
| #set(CMAKE_CXX_FLAGS_DEBUG   "-DDEBUG=0 -Os -g") | ||||
| #set(CMAKE_ASM_FLAGS_DEBUG   "-DDEBUG=0 -Os -g") | ||||
|  | ||||
| # RELEASE | ||||
| set(CMAKE_C_FLAGS_RELEASE        "-DNDEBUG -O3") #  -flto | ||||
|   | ||||
| @@ -43,5 +43,6 @@ OF SUCH DAMAGE. | ||||
| #define LED_IRQ             TIMER16_IRQn | ||||
|  | ||||
| void led_config(void); | ||||
| void iicReceiveData(void); | ||||
|  | ||||
| #endif /* MAIN_H */ | ||||
|   | ||||
							
								
								
									
										87
									
								
								src/main.c
									
									
									
									
									
								
							
							
						
						
									
										87
									
								
								src/main.c
									
									
									
									
									
								
							| @@ -40,6 +40,34 @@ void led_config(void) | ||||
|     nvic_irq_enable(LED_IRQ, 2); | ||||
| } | ||||
|  | ||||
| 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 | ||||
| @@ -59,14 +87,69 @@ int main(void) | ||||
|     printf("XLSW-3DP-LDC1612! V0.0.1\r\n"); | ||||
|     printf("\r\n"); | ||||
|  | ||||
|     I2C_scan(); | ||||
|     LDC1612_read_sensor_infomation(); | ||||
|     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"); | ||||
|     // | ||||
|     // // delay_us(2); | ||||
|     // while (!i2c_flag_get(I2C0, I2C_FLAG_TBE)); | ||||
|     // | ||||
|     // // 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]); | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|     iicReceiveData(); | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|     while(1){ | ||||
|         printf("OK!!!\r\n"); | ||||
|  | ||||
|         delay_ms(1000); | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user