《stm32 i2c dma》由会员分享,可在线阅读,更多相关《stm32 i2c dma(21页珍藏版)》请在金锄头文库上搜索。
1、真诚为您提供优质参考资料,若有不当之处,请指正。#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_TRI
2、ALS_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#def
3、ine 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#def
4、ine 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_DM
5、A_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
6、 #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_T
7、IME_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* pBuf
8、fer, 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 wheneve
9、r a timeout condition occure during communication (waiting on an event that doesnt 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 thi
10、s 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 co
11、mmunication 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_ExitC
12、riticalSection_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 sE
13、E_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_InitStruct