stm32 i2c dma

上传人:tang****xu1 文档编号:132726177 上传时间:2020-05-19 格式:DOC 页数:18 大小:97KB
返回 下载 相关 举报
stm32 i2c dma_第1页
第1页 / 共18页
stm32 i2c dma_第2页
第2页 / 共18页
stm32 i2c dma_第3页
第3页 / 共18页
stm32 i2c dma_第4页
第4页 / 共18页
stm32 i2c dma_第5页
第5页 / 共18页
点击查看更多>>
资源描述

《stm32 i2c dma》由会员分享,可在线阅读,更多相关《stm32 i2c dma(18页珍藏版)》请在金锄头文库上搜索。

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_TRIALS_NUMBER 150/* Definti

2、ons 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_APB1Pe

3、riph_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 #defi

4、ne 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#d

5、efine 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_PREPRI

6、O 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. */#d

7、efine 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, uin

8、t16_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

9、 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 this callback should reset I2C

10、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 defa

11、ult 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(

12、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

13、_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_IN_FLOATING; GPIO_Init(sEE_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 商业计划书

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号