資源簡介
目前網上能找到的最完美的STM32讀寫EEPROM驅動,硬件I2C中斷加DMA方式!用24C16測試通過!

代碼片段和文件信息
/**************************************************************************
*?i2c_ee_dma.c?
*?2010-12-01?lj2505
***************************************************************************/
#include?“i2c_ee_dma.h“
#include?“stm32f10x_rcc.h“
#include?“stm32f10x_i2c.h“
/*?specified?by?user??----------------------------------------------------*/
#define?I2C_REMAP
//#define?SLAVE_10BIT_ADDRESS
/*?Private?define?--------------------------------------------------------*/
#define?ADDRESS_MAX?(1024*AT24Cxx/8)
#if?(AT24Cxx<4) //AT24C02
? #define?I2C_PageSize??????8
#elif??(AT24Cxx<=16)//AT24C04?AT24C08?AT24C16
#define?I2C_PageSize??????16
#elif??(AT24Cxx<=512)?//AT24C32?AT24C64?AT24C512
#define?I2C_PageSize??????32
#define?EE_ADDRESS_NUM ??2
#else
#error?“unsupport?eeprom“
#endif
??
#define?I2C1_DR_Address????????0x40005410
#define?I2C2_DR_Address????????0x40005810
#define?Transmitter?????????????0x00
#define?Receiver????????????????0x01
/*?Local?variables?-------------------------------------------------------*/
static?vu8?MasterDirection?=?Transmitter;
static?u16?SlaveADDR;
static?u16?DeviceOffset=0x0;
static?bool?check_begin?=?FALSE;
static?bool?OffsetDone?=?FALSE;
vu8?MasterReceptionComplete?=?0;
vu8?MasterTransitionComplete?=?0;?//?to?indicat?master‘s?send?process
vu8?WriteComplete?=?0;?//?to?indicat?target‘s?internal?write?process
int?I2C_NumByteToWrite?=?0;
u8?I2C_NumByteWritingNow?=?0;
u8*?I2C_pBuffer?=?0;?
u16?I2C_WriteAddr?=?0;
u8?EE_Addr_Count?=?0;//地址字節數
/*P-V?operation?on?I2C1?*/
static?vu8?PV_flag_1;
volatile?I2C_STATE?i2c_comm_state;
/*******************************************************************************
*?Function?Name??:?I2C_EE_Init
*?Description????:?Initializes?peripherals?used?by?the?I2C?EEPROM?driver.
*?Input??????????:?None
*?Output?????????:?None
*?Return?????????:?None
*******************************************************************************/
void??I2C_EE_Init(void)
{
/*******?GPIO?configuration?and?clock?enable?*********/
GPIO_InitTypeDef??GPIO_InitStructure;?
I2C_InitTypeDef??I2C_InitStructure;
NVIC_InitTypeDef?NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB?ENABLE);
????
#ifdef?I2C_REMAP
GPIO_PinRemapConfig(GPIO_Remap_I2C1?ENABLE);?
????GPIO_InitStructure.GPIO_Pin?=??GPIO_Pin_8?|?GPIO_Pin_9;
#else
????GPIO_InitStructure.GPIO_Pin?=??GPIO_Pin_6?|?GPIO_Pin_7;
#endif
????RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1?ENABLE);
????I2C_DeInit(I2C1);
?
GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_AF_OD;
GPIO_Init(GPIOB?&GPIO_InitStructure);
??
??
/***********?I2C?periphral?configuration?**********/
I2C_DeInit(I2C1);
I2C_InitStructure.I2C_Mode?=?I2C_Mode_I2C;?//?fixed
I2C_InitStructure.I2C_DutyCycle?=?I2C_DutyCycle_2;??//?fixed
I2C_InitStructure.I2C_OwnAddress1?=?I2C1_ADDRESS7;??//?user?parameter
I2C_InitStructure.I2C_Ack?=?I2C_Ack_Enable;?//?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????20928??2011-01-21?11:05??最完美的STM32讀寫EEPROM驅動,硬件I2C中斷加DMA方式\i2c_ee_dma.c
?????文件???????1208??2010-12-05?10:56??最完美的STM32讀寫EEPROM驅動,硬件I2C中斷加DMA方式\i2c_ee_dma.h
?????目錄??????????0??2011-08-13?15:28??最完美的STM32讀寫EEPROM驅動,硬件I2C中斷加DMA方式
-----------?---------??----------?-----??----
????????????????22136????????????????????3
評論
共有 條評論