【正文】
MA define sEE_I2C_DMA_TX_IRQn DMA1_Channel6_IRQndefine sEE_I2C_DMA_RX_IRQn DMA1_Channel7_IRQndefine sEE_I2C_DMA_TX_IRQHandler DMA1_Channel6_IRQHandlerdefine sEE_I2C_DMA_RX_IRQHandler DMA1_Channel7_IRQHandler define sEE_I2C_DMA_PREPRIO 0define sEE_I2C_DMA_SUBPRIO 0 define sEE_DIRECTION_TX 0define 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)。/* Start and End of critical section: these callbacks should be typically used to disable interrupts when entering a critical section of I2C munication You may use default callbacks provided into this driver by unmenting the define USE_DEFAULT_CRITICAL_CALLBACK in file.. Or you can ment that line and implement these callbacks into your application */void sEE_EnterCriticalSection_UserCallback(void)。void sEE_LowLevel_DeInit(void){ GPIO_InitTypeDef GPIO_InitStructure。GPIO_InitStructure)。 NVIC_Init(amp。 DMA_Cmd(sEE_I2C_DMA_CHANNEL_RX, DISABLE)。 = GPIO_Speed_50MHz。 = sEE_I2C_DMA_PREPRIO。 NVIC_Init(amp。 /* This parameter will be configured durig munication */ = DMA_PeripheralInc_Disable。sEEDMA_InitStructure)。 = (uint32_t)BufferSize。 }}void sEE_DeInit(void){ sEE_LowLevel_DeInit()。 = I2C_SPEED。 while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_BUSY)) { if((sEETimeout) == 0) return sEE_TIMEOUT_UserCallback()。s internal address to read from: Only one byte address */ I2C_SendData(sEE_I2C, ReadAddr)。 0x00FF))。t be used */ /* One Byte Master Reception procedure (POLLING) */ if ((uint16_t)(*NumByteToRead) 2) { /* Wait on ADDR flag to be set (ADDR is still not cleared at this level */ sEETimeout = sEE_FLAG_TIMEOUT。 while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_RXNE) == RESET) { if((sEETimeout) == 0) return sEE_TIMEOUT_UserCallback()。 while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)) { if((sEETimeout) == 0) return sEE_TIMEOUT_UserCallback()。 /*! While the bus is busy */ sEETimeout = sEE_LONG_TIMEOUT。 while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) { if((sEETimeout) == 0) return sEE_TIMEOUT_UserCallback()。 } /*! Send the EEPROM39。}/** * brief Writes buffer of data to the I2C EEPROM. * param pBuffer : pointer to the buffer containing the data to be written * to the EEPROM. * param WriteAddr : EEPROM39。 /* Start writing data */ sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(amp。 sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(amp。 pBuffer += sEE_PAGESIZE。 } sEE_WaitEepromStandbyState()。 } sEE_WaitEepromStandbyState()。 } sEE_WaitEepromStandbyState()。 } sEE_WaitEepromStandbyState()。 while (sEEDataNum 0) { if((sEETimeout) == 0) {sEE_TIMEOUT_UserCallback()。sEEDataNum))。 } if(NumOfSingle != 0) { /* Store the number of data to be written */ sEEDataNum = NumOfSingle。 } } } }/** * brief Wait for EEPROM Standby state. * * note This function allows to wait and check that EEPROM has finished the * last Write operation. It is mostly used after Write operation: after * receiving the buffer to be written, the EEPROM may need additional * time to actually perform the write operation. During this time, it * doesn39。 } /*! Send EEPROM address for write */ I2C_Send7bitAddress(sEE_I2C, sEEAddress, I2C_Direction_Transmitter)。 /*! STOP condition */ I2C_GenerateSTOP(sEE_I2C, ENABLE)。 } /*! Send STOP condition */ I2C_GenerateSTOP(sEE_I2C, ENABLE)。 /*! Wait till all data have been physically transferred on the bus */ sEETimeout = sEE_LONG_TIMEOUT。 /* Check if the ADDR flag has been set */ if (tmpSR1 amp。 /*! Test on EV5 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT。}。 WriteAddr += sEE_PAGESIZE。 } while(NumOfPage) { /* Store the number of data to be written */ sEEDataNum = sEE_PAGESIZE。sEEDataNum))。 return。 return。 return。 return。 } sEE_WaitEepromStandbyState()。 } sEE_WaitEepromStandbyState()。 NumOfSingle = NumByteToWrite % sEE_PAGESIZE。 /* Enable the DMA Tx Channel */ DMA_Cmd(sEE_I2C_DMA_CHANNEL_TX, ENABLE)。 /*! Test on EV8 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT。 //寫器件地址最后一位由方向控制 I2C_Send7bitAddress(sEE_I2C, sEEAddress, I2C_Direction_Transmitter)。t check on boundaries condition (in this driver * the function sEE_WriteBuffer() which calls sEE_WritePage() is * responsible of checking on Page boundaries). * * param pBuffer : pointer to the buffer containing the data to be written to * the EEPROM. * param WriteAddr : EEPROM39。 } /*! ReEnable Acknowledgement to be ready for another reception */ I2C_AcknowledgeConfig(sEE_I2C, ENABLE)。 /* Call User callback for critical section end (should typically reenable interrupts) */ sEE_ExitCriticalSection_UserCallback()。 } /*! Send EEPROM address for read */ I2C_Send7bitAddress(sEE_I2C, sEEAddress, I2C_Direction_Receiver)。 } /*! Send the EEPROM39。 while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) {