lse 有的 波形正常。后来改为这个有好了, while( (CLK->ECKCR) & (uint8_t)(1<<3) == (uint8_t)RESET);
这个不知道怎么会影响i2c read
- void sEE_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t* NumByteToRead)
- {
- //__IO uint32_t timeout = 0xFFFF;
- __IO uint32_t timeout = 0xf00;
- /*!< Wait the end of last communication */
- for (;timeout > 0; timeout--);
- /* Set the pointer to the Number of data to be read. This pointer will be used
- by the DMA Transfer Complete interrupt Handler in order to reset the
- variable to 0. User should check on this variable in order to know if the
- DMA transfer has been completed or not. */
- sEEDataReadPointer = NumByteToRead;
- /*!< While the bus is busy */
- while (I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_BUSY))
- {}
- /*!< Send START condition */
- I2C_GenerateSTART(sEE_I2C, ENABLE);
- /*!< Test on EV5 and clear it */
- while (!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_MODE_SELECT))
- {}
- /*!< Send EEPROM address for write */
- I2C_Send7bitAddress(sEE_I2C, (uint8_t)sEEAddress, I2C_Direction_Transmitter);
- /*!< Test on EV6 and clear it */
- while (!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
- {}
- #ifdef sEE_M24C64_32
- /*!< Send the EEPROM's internal address to read from: MSB of the address first */
- I2C_SendData(sEE_I2C, (uint8_t)((ReadAddr & 0xFF00) >> 8));
- /*!< Test on EV8 and clear it */
- while (!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTED))
- {}
- /*!< Send the EEPROM's internal address to read from: LSB of the address */
- I2C_SendData(sEE_I2C, (uint8_t)(ReadAddr & 0x00FF));
- #endif /*!< sEE_M24C64_32 */
- /*!< Test on EV8 and clear it */
- while (!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTED))
- {}
- /*!< Send STRAT condition a second time */
- I2C_GenerateSTART(sEE_I2C, ENABLE);
- /*!< Test on EV5 and clear it */
- while (!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_MODE_SELECT))
- {}
- /*!< Send EEPROM address for read */
- I2C_Send7bitAddress(sEE_I2C, (uint8_t)sEEAddress|0x01, I2C_Direction_Receiver);
- /*!< Test on EV6 and clear it */
- while (!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
- {}
- // cheng
- I2C_AcknowledgeConfig(sEE_I2C, ENABLE);
- while((uint16_t)(*NumByteToRead))
- {
- if((uint16_t)(*NumByteToRead) == 1)
- {
- /* Disable Acknowledgement */
- //I2C_AcknowledgeConfig(I2C_ACK_NONE);
- I2C_AcknowledgeConfig(sEE_I2C, DISABLE);
- /*!< Send STOP Condition */
- I2C_GenerateSTOP(sEE_I2C, ENABLE);
- /* Send STOP Condition */
- //I2C_GenerateSTOP(ENABLE);
- }
- /* Test on EV7 and clear it */
- while (!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_BYTE_RECEIVED))
- {}
- /*!< Read a byte from the EEPROM */
- *pBuffer = I2C_ReceiveData(sEE_I2C);
- /* Point to the next location where the byte read will be saved */
- pBuffer++;
-
- /* Decrement the read bytes counter */
- (uint16_t)(*NumByteToRead)--;
-
- }
- /* Enable Acknowledgement to be ready for another reception */
- I2C_AcknowledgeConfig(sEE_I2C, ENABLE);
- #if 0
- /* If number of data to be read is 1, then DMA couldn't be used */
- if ((uint16_t)(*NumByteToRead) < 2)
- {
- /*!< Disable Acknowledgement */
- I2C_AcknowledgeConfig(sEE_I2C, DISABLE);
- /*!< Send STOP Condition */
- I2C_GenerateSTOP(sEE_I2C, ENABLE);
- /*!< Test on EV7 and clear it */
- while (!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_BYTE_RECEIVED))
- {}
- /*!< Read a byte from the EEPROM */
- *pBuffer = I2C_ReceiveData(sEE_I2C);
- /*!< Decrement the read bytes counter */
- (uint16_t)(*NumByteToRead)--;
- /*!< Enable Acknowledgement to be ready for another reception */
- I2C_AcknowledgeConfig(sEE_I2C, ENABLE);
-
-
- }
- #endif
-
- #if 0
- /* DMA could be used for number of data higher than 1 */
- else
- {
-
-
- /* Configure the DMA Rx Channel with the buffer address and the buffer size */
- sEE_LowLevel_DMAConfig((uint16_t)pBuffer, (uint8_t)(*NumByteToRead), sEE_DIRECTION_RX);
- /* Inform the DMA that the next End Of Transfer Signal will be the last one */
- I2C_DMALastTransferCmd(sEE_I2C, ENABLE);
- /* Enable the DMA Rx Channel */
- DMA_Cmd(sEE_I2C_DMA_CHANNEL_RX, ENABLE);
- /* Global DMA Enable */
- DMA_GlobalCmd(ENABLE);
-
- }
- #endif
- }
|