第一版代码,为了在EEPROM保存参数的时候走STM32的CRC,让Codex修改了一下,现在的效果是无法存储,codex表示原因是CRC方法不同,修改到一半今天的额度使用完了,有待后续解决CRC的bug

This commit is contained in:
2026-02-28 17:36:05 +08:00
commit b2fedd58b2
212 changed files with 208290 additions and 0 deletions

43
MyDriver/SoftI2C.h Normal file
View File

@@ -0,0 +1,43 @@
#ifndef __DRIVER_I2C_H__
#define __DRIVER_I2C_H__
#include <stdint.h>
#include "stm32f407xx.h"
#include "stm32f4xx.h"
#include "main.h"
#include "Com_debug.h"
#include "DWT.h"
// PA8是SDAPA9是SCL
// 板子改进意见PE9和PE11用作定时器1的CH1和CH2然后PA8和PA9留出来用作I2C的通信引脚
#define I2C_SCL_PIN GPIO_PIN_9
#define I2C_SDA_PIN GPIO_PIN_8
#define I2C_GPIO_PORT GPIOA
// 宏定义 SDA拉高或拉低
#define SDA_HIGH I2C_GPIO_PORT->BSRR = I2C_SDA_PIN
#define SDA_LOW I2C_GPIO_PORT->BSRR = (uint32_t)I2C_SDA_PIN << 16U
// 宏定义 SCL拉高或拉低
#define SCL_HIGH I2C_GPIO_PORT->BSRR = I2C_SCL_PIN
#define SCL_LOW I2C_GPIO_PORT->BSRR = (uint32_t)I2C_SCL_PIN << 16U
// 宏定义 读SDA
#define SDA_READ (I2C_GPIO_PORT->IDR & I2C_SDA_PIN)
// 宏定义 延时5us
#define SCL_DELAY DWT_delay_us(5)
void Dri_I2C_Init(void); // 初始化函数
void Dri_I2C_Start(void); // 发送起始信号
void Dri_I2C_Stop(void); // 发送停止信号
void Dri_I2C_TransmitByte(uint8_t byte); // 发送一个字节的数据
uint8_t Dri_I2C_ReceiveByte(void); // 接收一个字节的数据
void Dri_I2C_TransmitACK(uint8_t ack); // 发送一个ACK信号, 参数是0(ACK)或1(NACK)
uint8_t Dri_I2C_ReceiveACK(void); // 接收一个ACK信号并返回
void Dri_I2C_WriteAddr(uint8_t slave_addr); // 写从机地址
void Dri_I2C_WriteReg(uint8_t reg, uint8_t data); // 写一个寄存器
uint8_t Dri_I2C_ReadReg(uint8_t slave_addr_read, uint8_t reg); // 读一个寄存器
#endif /* __DRIVER_I2C_H__ */