Exemplo n.º 1
0
/*==============================================================================
Name    : eeprom_read
--------------------------------------------------------------------------------
Purpose : Reads data from EEPROM
Input   : EEPROM address where the data must be read
Output  : 8 Bit data
Notes   :
==============================================================================*/
uint8_t eeprom_read(uint16_t ui_address)
{
#if !defined(_ATXMEGA_DEVICE_)
   /* FOR TINY / MEGA EEPROM ACCESS */
   /* Wait for completion of previous write */
   while(EECR & (1<<EEPE));
   /* Set up address register */
   #if defined ( __ICCAVR__ )
      EEAR = ui_address;
   #elif defined( __GNUC__ ) /* defined ( __ICCAVR__ ) */
      EEARL = ui_address;
   #endif /* defined( __GNUC__ ) */
   /* Start eeprom read by writing EERE */
   EECR |= (1<<EERE);
   /* Return data from Data Register */
   return EEDR;
#else
   /* FOR XMEGA EEPROM ACCESS */
   /* Wait for pending NVM operation */
   do{} while(( NVM.STATUS & NVM_NVMBUSY_bm ) == NVM_NVMBUSY_bm );
   /* Load address for reading */
   NVM.ADDR0 = ui_address & 0xFF;
   NVM.ADDR1 = (ui_address >> 8) & 0x1F;
   NVM.ADDR2 = 0x00;
   /* Command - Read EEPROM */
   NVM.CMD = NVM_CMD_READ_EEPROM_gc;
   /* Command - Execute */
   NVM_EXEC();
   /* Data available */
   return NVM.DATA0;
#endif
}
Exemplo n.º 2
0
/*! \brief Flush temporary FLASH page buffer. 
 * 
 *  This function flushes the FLASH page buffers. 
 */ 
void FLASH_FlushFlasPageBuffer(void) 
{ 
    NVM.CMD = NVM_CMD_ERASE_FLASH_BUFFER_gc; 
    NVM_EXEC(); 

    // Wait until NVM is not busy 
    FLASH_WaitForNVM(); 
}   // FLASH_FlushFlasPageBuffer 
Exemplo n.º 3
0
/*==============================================================================
Name    : eeprom_write
--------------------------------------------------------------------------------
Purpose : Write data to EEPROM
Input   : Address where the data must be saved, data
Output  :
Notes   :
==============================================================================*/
void eeprom_write(uint16_t ui_address, uint8_t ui_data)
{
#if !defined(_ATXMEGA_DEVICE_)
   /* FOR TINY / MEGA EEPROM ACCESS */
   /* Wait for completion of previous write */
   while(EECR & (1<<EEPE));
   /* Set up address and Data Registers */
   #if defined ( __ICCAVR__ )
      EEAR = ui_address;
   #elif defined( __GNUC__ ) /* defined ( __ICCAVR__ ) */
      #if defined (__AVR_MEGA__)
       EEAR = ui_address;
	 #else
	   EEARL = (uint8_t)ui_address;
	 #endif
   #endif /* defined( __GNUC__ ) */
   EEDR = ui_data;
   EEPROM_WRITE();
#else
   /* FOR XMEGA EEPROM ACCESS */
   /* Wait for pending NVM operation */
   do{} while(( NVM.STATUS & NVM_NVMBUSY_bm ) == NVM_NVMBUSY_bm );
   if ((NVM.STATUS & NVM_EELOAD_bm) != 0) {
      /* Command - Erase eeprom buffer */
      NVM.CMD = NVM_CMD_ERASE_EEPROM_BUFFER_gc;
      /* Command - Execute */
      NVM_EXEC();
   }
   /* Command - Load EEPROM buffer */
   NVM.CMD = NVM_CMD_LOAD_EEPROM_BUFFER_gc;
   /* Load address to write to. */
   NVM.ADDR0 = ui_address & 0xFF;
   NVM.ADDR1 = (ui_address >> 8) & 0x1F;
   NVM.ADDR2 = 0x00;
   /* Load data to write */
   NVM.DATA0 = ui_data;
   /* Load Atomic write command */
   NVM.CMD = NVM_CMD_ERASE_WRITE_EEPROM_PAGE_gc;
   NVM_EXEC();
   /* Wait for pending NVM operation */
   do{} while(( NVM.STATUS & NVM_NVMBUSY_bm ) == NVM_NVMBUSY_bm );
#endif
}