【正文】
} /* 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()。 /*! While the bus is busy */ sEETimeout = sEE_LONG_TIMEOUT。 return。 NumOfSingle = NumByteToWrite % sEE_PAGESIZE。sEEDataNum))。sEEDataNum))。 while (sEEDataNum 0) { if((sEETimeout) == 0) {sEE_TIMEOUT_UserCallback()。 endif /*! sEE_M24C08 */ /*! Test on EV8 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT。//開(kāi)始符號(hào) /*! Test on EV5 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT。 /* Wait to make sure that STOP control bit has been cleared */ sEETimeout = sEE_FLAG_TIMEOUT。 } /*! Send STRAT condition a second time */ I2C_GenerateSTART(sEE_I2C, ENABLE)。 while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_MODE_SELECT)) { if((sEETimeout) == 0) return sEE_TIMEOUT_UserCallback()。 /*! I2C configuration */ /* sEE_I2C configuration */ = I2C_Mode_I2C。sEEDMA_InitStructure)。 /* I2C TX DMA Channel configuration */ DMA_DeInit(sEE_I2C_DMA_CHANNEL_TX)。GPIO_InitStructure)。 = sEE_I2C_DMA_PREPRIO。 /* sEE_I2C DeInit */ I2C_DeInit(sEE_I2C)。uint32_t sEE_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t* NumByteToWrite)。 __IO uint16_t* sEEDataReadPointer。 /* Configure and enable I2C DMA TX Channel interrupt */ = sEE_I2C_DMA_TX_IRQn。 NVIC_InitTypeDef NVIC_InitStructure。NVIC_InitStructure)。 = DMA_Mode_Normal。 = DMA_DIR_PeripheralSRC。 /* Enable the sEE_I2C peripheral DMA requests */ I2C_DMACmd(sEE_I2C, ENABLE)。 //發(fā)送高位地址 /*! Test on EV8 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT。 /* Clear ADDR register by reading SR1 then SR2 register (SR1 has already been read) */ (void)sEE_I2CSR2。 } /* If all operations OK, return sEE_OK (0) */ return sEE_OK。s internal address to write to : MSB of the address first */ I2C_SendData(sEE_I2C, (uint8_t)((WriteAddr amp。 count = sEE_PAGESIZE Addr。 return。 /* Wait transfer through DMA to be plete */ sEETimeout = sEE_LONG_TIMEOUT。 /* Wait transfer through DMA to be plete */ sEETimeout = sEE_LONG_TIMEOUT。 WriteAddr += count。 while (sEEDataNum 0) { if((sEETimeout) == 0) {sEE_TIMEOUT_UserCallback()。 } /* Keep looping till the Address is acknowledged or the AF flag is set (address not acknowledged at time) */ while((tmpSR1 amp。 (void)sEE_I2CSR2。 do { /* Get the current value of the SR1 register */ tmpSR1 = sEE_I2CSR1。sEEDataNum))。}。 sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(amp。 /*! Write the data conained in same page */ sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(amp。 /* Wait transfer through DMA to be plete */ sEETimeout = sEE_LONG_TIMEOUT。 uint16_t Addr = 0。s internal address to write to : only one byte Address */ I2C_SendData(sEE_I2C, WriteAddr)。 /* Inform the DMA that the next End Of Transfer Signal will be the last one */ I2C_DMALastTransferCmd(sEE_I2C, ENABLE)。 } /*! Disable Acknowledgement */ I2C_AcknowledgeConfig(sEE_I2C, DISABLE)。s internal address to read from: MSB of the address first */ I2C_SendData(sEE_I2C, (uint8_t)((ReadAddr amp。 /* Apply sEE_I2C configuration after enabling it */ I2C_Init(sEE_I2C, amp。sEEDMA_InitStructure)。 = DMA_MemoryDataSize_Byte。 = ENABLE。 DMA_DeInit(sEE_I2C_DMA_CHANNEL_RX)。 GPIO_Init(sEE_I2C_SDA_GPIO_PORT, amp。ifdef __cplusplus}endifendif 以下是C文件include __IO uint16_t sEEAddress = 0xa0。uint32_t sEE_WaitEepromStandbyState(void)。 /*! GPIO configuration */ /*! Configure sEE_I2C pins: SCL */ = sEE_I2C_SCL_PIN。 NVIC_Init(amp。 GPIO_Init(sEE_I2C_SDA_GPIO_PORT, amp。 = (uint32_t)0。 DMA_ITConfig(sEE_I2C_DMA_CHANNEL_RX, DMA_IT_TC, ENABLE)。 = I2C_SLAVE_ADDRESS7。 /*! Test on EV6 and clear it */ sEETimeout = sEE_FLAG_TIMEOUT。 while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_MODE_SELECT)) { if((sEETimeout) == 0) return sEE_TIMEOUT_UserCallback()。 I2C_CR1_STOP) { if((sEETimeout) == 0) return sEE_TIMEOUT_UserCallback()。 } /*! Send EEPROM address for write */ sEETimeout = sEE_FLAG_TIMEOUT。 } /* Configure the DMA Tx Channel with the buffer address and the buffer size */ sEE_LowLevel_DMAConfig((uint32_t)pBuffer, (uint8_t)(*NumByteToWrite), sEE_DIRECTION_TX)。}。 while (sEEDataNum 0) { if((sEETimeout) == 0) {sEE_TIMEOUT_UserCallback()。 while (sEEDataNum 0) { if((sEETimeout) == 0) {sEE_TIMEOUT_UserCallback()。 sEE_WritePage(pBuffer, WriteAddr, (uint8_t*)(amp。 } sEE_WaitEepromStandbyState()。 } /* Keep looping till the slave acknowledge his address or maximum number of trials is reached (this number is defined by sEE_MAX_TRIALS_NUMBER define in file) */ while (1) { /*! Send START condition */ I2C_GenerateSTART(sEE_I2C, ENABLE)。 DMA_ClearFlag(sEE_I2C_DMA_FLAG_TX_GL)。 /* Exit the function */ return sEE_OK。t answer to I2C packets addressed to it. Once the write operation * is plete the EEPROM responds to its address. * * note It is not necessary to call this function after sEE_WriteBuffer() * function (sEE_WriteBuffer() already calls this function after each * write page operation). * * param None * retval sEE_OK (0) if operation is correctly performed, else return value * different from sEE_OK (0) or the timeout user callba