cancel
Showing results for 
Search instead for 
Did you mean: 

i2c dma eeprom read data the same value

David.Cheng
Associate II
if(strstr(RX_buf, "ux"))
                {
                    //stop_flag = 0;
                    
                    printf("***csv data begin\n");
                    sEE_WriteBuffer((uint8_t *)&write_data, 0x00, 2);
                    
                    //read eeprom and printf
                    for(k_addr = 0; k_addr < write_addr; k_addr +=2)
                    {
                        
                        rd_data = 0;
                        read_cnt = 2;
                        
                        sEE_ReadBuffer((uint8_t *)&rd_data, k_addr, &read_cnt);
                        
                        while(read_cnt > 0) {};
                    
                        printf("%u,%f\n", k_addr, rd_data/100.0);
                        
                    
                    }
                    
                    
                    printf("csv data end\n");
                    // flash record status
                    ////  adddddd internel eeprom write
                    
                    
                }

void sEE_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t* NumByteToRead)
{
  __IO uint32_t timeout = 0xFFFF;
 
  /*!< 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))
  {}
 
  /* 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);
    
    
  }
  /* 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);
    
  }
}

when i test at code begin, it is ok

0 REPLIES 0