예제 #1
0
void eeprom_page_write(unsigned long addr, unsigned char* buf, unsigned char len)
{
     spi_select(EEPROM_SS_PORT, EEPROM_SS_PIN);
    _delay_us(10);
    
        spi_write(EEPROM_WRITE);    // byte write

        // wyœlij adres 24-bitowy
        spi_write( (addr >> 16) & 0xff);
        spi_write( (addr >> 8)  & 0xff);
        spi_write(  addr        & 0xff);

        // wyœlij bajty do zapisania
        for (unsigned char i=0; i < len; i++)
            spi_write(buf[i]);

    spi_unselect(EEPROM_SS_PORT, EEPROM_SS_PIN);

    //_delay_ms(2);_delay_ms(2);_delay_ms(2);_delay_ms(2); // Twc = 6ms

    // czekaj na zakoñczenie operacji zapisu (Twc=6ms)
    while ( (eeprom_status() & 0x01) ) // Write In Progress (WIP)
        _delay_ms(1);

    return;
}
예제 #2
0
파일: eeprom.c 프로젝트: xwaynec/eplab
/* flash_erase_all - erase all pages on flash memory */
void flash_erase_all()
{
	while (eeprom_status() & 0x01)	/* wait until write cycle done */
		;
	EE_CS = 0;	/* enable SPI slave */
	spi_write_then_read(EE_WREN);	/* write-enable instruction */
	EE_CS = 1;	/* start erase operation */
	EE_CS = 0;	/* start erase operation */
	spi_write_then_read(ERASE_ALL);	/* read instruction */
	EE_CS = 1;	/* start erase operation */
	while (eeprom_status() & 0x00)	/* wait until erase done */
		;
	/* re-enable flash write operation */
	EE_CS = 0;	/* enable SPI slave */
	spi_write_then_read(EE_WREN);	/* write-enable instruction */
	EE_CS = 1;	/* start erase operation */
}
예제 #3
0
파일: eeprom.c 프로젝트: xwaynec/eplab
/* eeprom_read - read single byte from specified address
 * @addr: target address
 */
char eeprom_read(unsigned int addr)
{
	char byte = 0;
	while (eeprom_status() & 0x01)	/* wait until write cycle done */
		;
	EE_CS = 0;	/* active eeprom */
	spi_write_then_read(EE_READ);	/* read instruction */
	spi_write_then_read(addr >> 8);	/* higher byte of addr */
	spi_write_then_read(addr & 0xff);	/* lower byte */
	byte = spi_write_then_read(0); /* read data */
	EE_CS = 1;	/* inactive eeprom */
	return byte;
}
예제 #4
0
파일: eeprom.c 프로젝트: xwaynec/eplab
/* eeprom_write - write a single byte to specified address
 * @addr: target address
 * @byte: writting byte of data
 */
void eeprom_write(unsigned int addr, char byte)
{
	while (eeprom_status() & 0x01)	/* wait until write cycle done */
		;
	EE_CS = 0;	/* active eeprom */
	spi_write_then_read(EE_WREN);	/* write-enable instruction */
	EE_CS = 1;	/* inactive eeprom */
	EE_CS = 0;	/* active eeprom */
	spi_write_then_read(EE_WRITE);	/* write instruction */
	spi_write_then_read(addr >> 8);	/* higher byte of addr */
	spi_write_then_read(addr & 0xff);	/* lower byte */
	spi_write_then_read(byte);	/* write data */
	EE_CS = 1;	/* inactive eeprom */
	EE_CS = 0;	/* active eeprom */
	spi_write_then_read(EE_WRDI);	/* write-disable instruction */
	EE_CS = 1;	/* inactive eeprom */
}
예제 #5
0
void eeprom_chip_erase()
{
    eeprom_enable_write(1);

    spi_select(EEPROM_SS_PORT, EEPROM_SS_PIN);
    _delay_us(10);
    
        spi_write(EEPROM_CE);    // chip erase

    spi_unselect(EEPROM_SS_PORT, EEPROM_SS_PIN);

    // czekaj na zakoñczenie operacji kasowania
    while ( (eeprom_status() & 0x01) ) // Write In Progress (WIP)
        _delay_ms(1);

    eeprom_enable_write(1);
}