From de21450df64589725f7e85b94a06772f203538fa Mon Sep 17 00:00:00 2001 From: wu58430 Date: Fri, 5 Jan 2024 18:46:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=8F=E5=B0=91eeprom=E5=BB=B6=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/workspace.xml | 1083 +------------------------------------------ driver/eeprom.c | 2 +- driver/i2c.c | 50 +- 3 files changed, 30 insertions(+), 1105 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index e8398f5..aee7b59 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -21,1082 +21,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + @@ -1263,10 +188,10 @@ + - @@ -1335,7 +260,7 @@ - + 1701738485690 diff --git a/driver/eeprom.c b/driver/eeprom.c index 2239fc8..89f881c 100644 --- a/driver/eeprom.c +++ b/driver/eeprom.c @@ -58,7 +58,7 @@ void EEPROM_WriteBuffer(uint32_t Address, const void *pBuffer,uint8_t WRITE_SIZE I2C_WriteBuffer(pBuffer, WRITE_SIZE); I2C_Stop(); } - SYSTEM_DelayMs(8); + SYSTEM_DelayMs(6); } diff --git a/driver/i2c.c b/driver/i2c.c index 17e19f8..03ebd93 100644 --- a/driver/i2c.c +++ b/driver/i2c.c @@ -23,25 +23,25 @@ void I2C_Start(void) { GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA); - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL); - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA); - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL); - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); } void I2C_Stop(void) { GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA); - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL); - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL); - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA); - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); } uint8_t I2C_Read(bool bFinal) @@ -55,33 +55,33 @@ uint8_t I2C_Read(bool bFinal) Data = 0; for (i = 0; i < 8; i++) { GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL); - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL); - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); Data <<= 1; - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); if (GPIO_CheckBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA)) { Data |= 1U; } GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL); - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); } PORTCON_PORTA_IE &= ~PORTCON_PORTA_IE_A11_MASK; PORTCON_PORTA_OD |= PORTCON_PORTA_OD_A11_BITS_ENABLE; GPIOA->DIR |= GPIO_DIR_11_BITS_OUTPUT; GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL); - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); if (bFinal) { GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA); } else { GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA); } - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL); - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL); - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); return Data; } @@ -92,7 +92,7 @@ int I2C_Write(uint8_t Data) int ret = -1; GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL); - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); for (i = 0; i < 8; i++) { if ((Data & 0x80) == 0) { GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA); @@ -100,20 +100,20 @@ int I2C_Write(uint8_t Data) GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA); } Data <<= 1; - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL); - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL); - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); } PORTCON_PORTA_IE |= PORTCON_PORTA_IE_A11_BITS_ENABLE; PORTCON_PORTA_OD &= ~PORTCON_PORTA_OD_A11_MASK; GPIOA->DIR &= ~GPIO_DIR_11_MASK; GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA); - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL); - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); for (i = 0; i < 255; i++) { if (GPIO_CheckBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA) == 0) { @@ -123,7 +123,7 @@ int I2C_Write(uint8_t Data) } GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL); - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); PORTCON_PORTA_IE &= ~PORTCON_PORTA_IE_A11_MASK; PORTCON_PORTA_OD |= PORTCON_PORTA_OD_A11_BITS_ENABLE; GPIOA->DIR |= GPIO_DIR_11_BITS_OUTPUT; @@ -143,11 +143,11 @@ int I2C_ReadBuffer(void *pBuffer, uint8_t Size) } for (i = 0; i < Size - 1; i++) { - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); pData[i] = I2C_Read(false); } - SYSTICK_DelayUs(3); + SYSTICK_DelayUs(1); pData[i++] = I2C_Read(true); return Size;