فهرست منبع

change i2c clk to 100K(MUST set the APB1 clk to div4:21M)

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 5 سال پیش
والد
کامیت
478275a033
5فایلهای تغییر یافته به همراه16 افزوده شده و 8 حذف شده
  1. 6 1
      Application/bsp/AT24CXX.c
  2. 1 0
      Application/bsp/AT24CXX.h
  3. 1 1
      Application/bsp/bsp.c
  4. 4 2
      Application/bsp/i2c.c
  5. 4 4
      Application/bsp/mcu_power_sleep.c

+ 6 - 1
Application/bsp/AT24CXX.c

@@ -3,7 +3,12 @@
 
 void AT24CXX_Init(void)
 {
-	gd32_i2c_init(0, 120*1000);//here, need 120K min speed, may be the GD lib is something wrong!!!!
+	gd32_i2c_init(0, 100*1000);//here, need 120K min speed, may be the GD lib is something wrong!!!!
+}
+
+
+void AT24CXX_DeInit(void){
+	gd32_i2c_deinit(0);
 }
 
 uint8_t AT24CXX_ReadOneByte(uint16_t ReadAddr)

+ 1 - 0
Application/bsp/AT24CXX.h

@@ -21,6 +21,7 @@ void AT24CXX_Write(uint16_t WriteAddr,uint8_t *pBuffer,uint16_t NumToWrite);	//
 void AT24CXX_Read(uint16_t ReadAddr,uint8_t *pBuffer,uint16_t NumToRead);   	//从指定地址开始读出指定长度的数据
 uint8_t AT24CXX_Check(void);  //检查器件
 void AT24CXX_Init(void); //初始化IIC
+void AT24CXX_DeInit(void);
 #endif
 
 

+ 1 - 1
Application/bsp/bsp.c

@@ -12,7 +12,7 @@ const char iap_board_name[] __attribute__((at(0x08002800))) = "SP600";
 const char iap_fw_version[] __attribute__((at(0x08002A00))) = "1.0";
 const char iap_fw_name[] __attribute__((at(0x08002C00))) = "App";
 
-#define CONFIG_DEBUG 0
+#define CONFIG_DEBUG 1
 
 extern void system_clock_config(void);
 extern void SystemCoreClockUpdate(void);

+ 4 - 2
Application/bsp/i2c.c

@@ -69,13 +69,15 @@ void gd32_i2c_init(uint32_t i2c_device, uint32_t rate){
 		gd32_i2c_busy_recovery(I2C0);
 		_i2c_deinit(I2C0);
 		gpio_af_set(GPIOB, GPIO_AF_1, GPIO_PIN_8|GPIO_PIN_9);
-		gpio_mode_af(GPIOB ,GPIO_PUPD_NONE, GPIO_PIN_8|GPIO_PIN_9);
+		gpio_mode_af(GPIOB ,GPIO_PUPD_PULLUP, GPIO_PIN_8|GPIO_PIN_9);
+		//gpio_output_options_set(GPIOB, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ,GPIO_PIN_8|GPIO_PIN_9);
 	} else {	
 		rcu_periph_clock_enable(RCU_I2C1);
 		gd32_i2c_busy_recovery(I2C1);
 		_i2c_deinit(I2C1);
 		gpio_af_set(GPIOB, GPIO_AF_1, GPIO_PIN_10|GPIO_PIN_11);
-		gpio_mode_af(GPIOB ,GPIO_PUPD_NONE, GPIO_PIN_10|GPIO_PIN_11);		
+		gpio_mode_af(GPIOB ,GPIO_PUPD_PULLUP, GPIO_PIN_10|GPIO_PIN_11);
+		//gpio_output_options_set(GPIOB, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ,GPIO_PIN_10|GPIO_PIN_11);
 	}
 	i2c_clock_config(device, rate, I2C_DTCY_2);
 	i2c_enable(device);

+ 4 - 4
Application/bsp/mcu_power_sleep.c

@@ -6,6 +6,7 @@
 #include "bsp/uart.h"
 #include "bsp/i2c.h"
 #include "bsp/shark_rtc.h"
+#include "bsp/AT24CXX.h"
 #include "app/sox/iostate.h"
 
 extern void system_clock_24m_irc8m(void);
@@ -47,7 +48,7 @@ static void pre_deepsleep(void){
 	ml5238_power_save(1); //call, before spi0_deinit
 	spi0_deinit();
 	spi1_deinit();
-	gd32_i2c_deinit(0);
+	AT24CXX_DeInit();
 	adc_deinit();
 	if (AUX_VOL_IS_OPEN()) {
 		AUX_VOL_OPEN(0);//we should close small power, before dcdc close
@@ -74,13 +75,12 @@ static void post_deepsleep(void){
 	SystemCoreClockUpdate();
 	spi0_init();
 	ml5238_power_save(0);
+	adc_init();
 	CS1180_PWR_ENABLE(1);
 	cs1180_adc_init();
 	shark_uart_init(SHARK_UART0);
 	shark_uart_init(SHARK_UART1);
-
-	gd32_i2c_init(0, 120* 1000);
-	adc_init();
+	AT24CXX_Init();
 	wdog_set_timeout(4);
 	current_calibrate();
 	wdog_reload();