
stm32 i2c dma.doc
55页ifndef __AT24C256_H#define __AT24C256_H/* Includes ------------------------------------------------------------------*/#include "stm32f10x.h"#ifdef __cplusplus extern "C" {#endif#define I2C_SPEED 300000#define I2C_SLAVE_ADDRESS7 0xA0 #define sEE_PAGESIZE 32/* Maximum number of trials for sEE_WaitEepromStandbyState() function */#define sEE_MAX_TRIALS_NUMBER 150 /* Defintions for the state of the DMA transfer */ #define sEE_STATE_READY 0#define sEE_STATE_BUSY 1#define sEE_STATE_ERROR 2 #define sEE_OK 0#define sEE_FAIL 1 #define sEE_FLAG_TIMEOUT ((uint32_t)0x1000)#define sEE_LONG_TIMEOUT ((uint32_t)(10 * sEE_FLAG_TIMEOUT))#define sEE_I2C I2C1#define sEE_I2C_CLK RCC_APB1Periph_I2C1#define sEE_I2C_SCL_PIN GPIO_Pin_6 #define sEE_I2C_SCL_GPIO_PORT GPIOB #define sEE_I2C_SCL_GPIO_CLK RCC_APB2Periph_GPIOB#define sEE_I2C_SDA_PIN GPIO_Pin_7 #define sEE_I2C_SDA_GPIO_PORT GPIOB #define sEE_I2C_SDA_GPIO_CLK RCC_APB2Periph_GPIOB#define sEE_M24C64_32#define sEE_I2C_DMA DMA1 #define sEE_I2C_DMA_CHANNEL_TX DMA1_Channel6#define sEE_I2C_DMA_CHANNEL_RX DMA1_Channel7 #define sEE_I2C_DMA_FLAG_TX_TC DMA1_IT_TC6 #define sEE_I2C_DMA_FLAG_TX_GL DMA1_IT_GL6 #define sEE_I2C_DMA_FLAG_RX_TC DMA1_IT_TC7 #define sEE_I2C_DMA_FLAG_RX_GL DMA1_IT_GL7 #define sEE_I2C_DMA_CLK RCC_AHBPeriph_DMA1#define sEE_I2C_DR_Address ((uint32_t)0x40005410)#define sEE_USE_DMA #define sEE_I2C_DMA_TX_IRQn DMA1_Channel6_IRQn#define sEE_I2C_DMA_RX_IRQn DMA1_Channel7_IRQn#define sEE_I2C_DMA_TX_IRQHandler DMA1_Channel6_IRQHandler#define sEE_I2C_DMA_RX_IRQHandler DMA1_Channel7_IRQHandler #define sEE_I2C_DMA_PREPRIO 0#define sEE_I2C_DMA_SUBPRIO 0 #define sEE_DIRECTION_TX 0#define sEE_DIRECTION_RX 1 /* Time constant for the delay caclulation allowing to have a millisecond incrementing counter. This value should be equal to (System Clock / 1000). ie. if system clock = 24MHz then sEE_TIME_CONST should be 24. */#define sEE_TIME_CONST 48 void sEE_DeInit(void);void sEE_Init(void);uint32_t sEE_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t* NumByteToRead);uint32_t sEE_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t* NumByteToWrite);void sEE_WriteBuffer(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite);uint32_t sEE_WaitEepromStandbyState(void);/* USER Callbacks: These are functions for which prototypes only are declared in EEPROM driver and that should be implemented into user applicaiton. */ /* sEE_TIMEOUT_UserCallback() function is called whenever a timeout condition occure during communication (waiting on an event that doesn't occur, bus errors, busy devices ...). You can use the default timeout callback implementation by uncommenting the define USE_DEFAULT_TIMEOUT_CALLBACK in stm32_evel_i2c_ee.h file. Typically the user implementation of this callback should reset I2C peripheral and re-initialize communication or in worst case reset all the application. */uint32_t sEE_TIMEOUT_UserCallback(void);/* Start and End of critical section: these callbacks should be typically used to disable interrupts when entering a critical section of I2C communication You may use default callbacks provided into this driver by uncommenting the define USE_DEFAULT_CRITICAL_CALLBACK in stm32_evel_i2c_ee.h file.. Or you can comment that line and implement these callbacks into your application */void sEE_EnterCriticalSection_UserCallback(void);void sEE_ExitCriticalSection_UserCallback(void);#ifdef __cplusplus}#endif#endif 如下是C文献#include "at24c256.h"__IO uint16_t sEEAddress = 0xa0; __IO uint32_t sEETimeout = sEE_LONG_TIMEOUT; __IO uint16_t* sEEDataReadPointer; __IO uint8_t* sEEDataWritePointer; __IO uint8_t sEEDataNum;DMA_InitTypeDef sEEDMA_InitStructure;void sEE_LowLevel_DeInit(void){ GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* sEE_I2C Peripheral Disable */ I2C_Cmd(sEE_I2C, DISABLE); /* sEE_I2C DeInit */ I2C_DeInit(sEE_I2C); /*!< sEE_I2C Periph clock disable */ RCC_APB1PeriphClockCmd(sEE_I2C_CLK, DISABLE); /*!< GPIO configuration */ /*!< Configure sEE_I2C pins: SCL */ GPIO_InitStructure.GPIO_Pin = sEE_I2C_SCL_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_。
