【正文】
__IO uint32_t sEETrials = 0。 do { /* Get the current value of the SR1 register */ tmpSR1 = sEE_I2CSR1。 } else { /*! Clear AF flag */ I2C_ClearFlag(sEE_I2C, I2C_FLAG_AF)。 (void)sEE_I2CSR2。 } }}/** * brief This function handles the DMA Tx Channel interrupt Handler. * param None * retval None */void sEE_I2C_DMA_TX_IRQHandler(void){ /* Check if the DMA transfer is plete */ if(DMA_GetFlagStatus(sEE_I2C_DMA_FLAG_TX_TC) != RESET) { /* Disable the DMA Tx Channel and Clear all its Flags */ DMA_Cmd(sEE_I2C_DMA_CHANNEL_TX, DISABLE)。 } /* Keep looping till the Address is acknowledged or the AF flag is set (address not acknowledged at time) */ while((tmpSR1 amp。 while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_BUSY)) { if((sEETimeout) == 0) return sEE_TIMEOUT_UserCallback()。 while (sEEDataNum 0) { if((sEETimeout) == 0) {sEE_TIMEOUT_UserCallback()。}。 WriteAddr += count。 if(count != 0) { /* Store the number of data to be written */ sEEDataNum = count。 /* Wait transfer through DMA to be plete */ sEETimeout = sEE_LONG_TIMEOUT。 /* Wait transfer through DMA to be plete */ sEETimeout = sEE_LONG_TIMEOUT。 /* Wait transfer through DMA to be plete */ sEETimeout = sEE_LONG_TIMEOUT。 /* Wait transfer through DMA to be plete */ sEETimeout = sEE_LONG_TIMEOUT。 return。 return。 count = sEE_PAGESIZE Addr。 while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) { if((sEETimeout) == 0) return sEE_TIMEOUT_UserCallback()。s internal address to write to : MSB of the address first */ I2C_SendData(sEE_I2C, (uint8_t)((WriteAddr amp。 while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_MODE_SELECT)) { if((sEETimeout) == 0) return sEE_TIMEOUT_UserCallback()。 } /* If all operations OK, return sEE_OK (0) */ return sEE_OK。 while(sEE_I2CCR1 amp。 /* Clear ADDR register by reading SR1 then SR2 register (SR1 has already been read) */ (void)sEE_I2CSR2。 /*! Test on EV5 and clear it (cleared by reading SR1 then writing to DR) */ sEETimeout = sEE_FLAG_TIMEOUT。 //發(fā)送高位地址 /*! Test on EV8 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT。 } /*! Send EEPROM address for write */ I2C_Send7bitAddress(sEE_I2C, sEEAddress, I2C_Direction_Transmitter)。 /* Enable the sEE_I2C peripheral DMA requests */ I2C_DMACmd(sEE_I2C, ENABLE)。 = I2C_DutyCycle_2。 = DMA_DIR_PeripheralSRC。 /* Enable the DMA Channels Interrupts */ DMA_ITConfig(sEE_I2C_DMA_CHANNEL_TX, DMA_IT_TC, ENABLE)。 = DMA_Mode_Normal。 = (uint32_t)sEE_I2C_DR_Address。NVIC_InitStructure)。 /*! Configure sEE_I2C pins: SDA */ = sEE_I2C_SDA_PIN。 NVIC_InitTypeDef NVIC_InitStructure。 = sEE_I2C_DMA_SUBPRIO。 /* Configure and enable I2C DMA TX Channel interrupt */ = sEE_I2C_DMA_TX_IRQn。 /*! sEE_I2C Periph clock disable */ RCC_APB1PeriphClockCmd(sEE_I2C_CLK, DISABLE)。 __IO uint16_t* sEEDataReadPointer。void sEE_WriteBuffer(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite)。uint32_t sEE_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t* NumByteToWrite)。 __IO uint32_t sEETimeout = sEE_LONG_TIMEOUT。 /* sEE_I2C DeInit */ I2C_DeInit(sEE_I2C)。GPIO_InitStructure)。 = sEE_I2C_DMA_PREPRIO。}/** * brief Initializes peripherals used by the I2C EEPROM driver. * param None * retval None */void sEE_LowLevel_Init(void){ GPIO_InitTypeDef GPIO_InitStructure。GPIO_InitStructure)。 NVIC_Init(amp。 /* I2C TX DMA Channel configuration */ DMA_DeInit(sEE_I2C_DMA_CHANNEL_TX)。 = DMA_MemoryDataSize_Byte。sEEDMA_InitStructure)。 } else { /* Configure the DMA Rx Channel with the buffer address and the buffer size */ = (uint32_t)pBuffer。 /*! I2C configuration */ /* sEE_I2C configuration */ = I2C_Mode_I2C。I2C_InitStructure)。 while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_MODE_SELECT)) { if((sEETimeout) == 0) return sEE_TIMEOUT_UserCallback()。 0xFF00) 8))。 } /*! Send STRAT condition a second time */ I2C_GenerateSTART(sEE_I2C, ENABLE)。 /* Call User callback for critical section start (should typically disable interrupts) */ sEE_EnterCriticalSection_UserCallback()。 /* Wait to make sure that STOP control bit has been cleared */ sEETimeout = sEE_FLAG_TIMEOUT。 /* Enable the DMA Rx Channel */ DMA_Cmd(sEE_I2C_DMA_CHANNEL_RX, ENABLE)。//開(kāi)始符號(hào) /*! Test on EV5 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT。 elif defined(sEE_M24C64_32) /*! Send the EEPROM39。 endif /*! sEE_M24C08 */ /*! Test on EV8 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT。 Addr = WriteAddr % sEE_PAGESIZE。 while (sEEDataNum 0) { if((sEETimeout) == 0) {sEE_TIMEOUT_UserCallback()。 while (sEEDataNum 0) { if((sEETimeout) == 0) {sEE_TIMEOUT_UserCallback()。sEEDataNum))。sEEDataNum))。sEEDataNum))。sEEDataNum))。 NumOfSingle = NumByteToWrite % sEE_PAGESIZE。 } sEE_WaitEepromStandbyState()。 return。 /* Wait transfer through DMA to be plete */ sEETimeout = sEE_LONG_TIMEOUT。 /*! While the bus is busy */ sEETimeout = sEE_LONG_TIMEOUT。 /* Update the timeout value and exit if it reach 0 */ if((sEETimeout) == 0) return sEE_TIMEOUT_UserCallback()。 } /* Check if the maximum allowed numbe of trials has bee reached */ if (sEETrials++ == sEE_MAX_TRIALS_NUMBER) { /* If the maximum number of trials has been reached, exit the function */ return sEE_TIMEOUT_UserCallback()。