Вт авг 28, 2012 10:31:35
void at45_init(void)
{
reset_spi1_high();
cs_spi1_high();
wp_spi1_high();
}
void at45_write_page(unsigned int addr)
{
volatile unsigned int i;
cs_spi1_low();
send_spi1_byte(0x84);
send_spi1_byte(0x00);
send_spi1_byte(0x00);
send_spi1_byte(0x00);
for(i = 0;i < 264; i++)
{
send_spi1_byte((char)(i));
}
cs_spi1_high();
wait(10000);
cs_spi1_low();
send_spi1_byte(0x83);
send_spi1_byte(0x00);
send_spi1_byte(0x00);
send_spi1_byte(0x00);
cs_spi1_high();
wait(1000000);
}
void at45_read_page(unsigned int addr)
{
volatile unsigned int i;
cs_spi1_low();
send_spi1_byte(0x53);
send_spi1_byte(0x00);
send_spi1_byte(0x00);
send_spi1_byte(0x00);
cs_spi1_high();
wait(10000);
cs_spi1_low();
send_spi1_byte(0xD4);
send_spi1_byte(0x00);
send_spi1_byte(0x00);
send_spi1_byte(0x00);
send_spi1_byte(0x00);
for(i = 0;i < 264; i++)
{
send_spi1_byte(0);
at45_read_buf[i] = read_spi1_byte();
}
cs_spi1_high();
}
Пт авг 31, 2012 14:12:36
void at45_init(void)
{
reset_spi1_high();
cs_spi1_high();
wp_spi1_high();
}
void at45_power_two(void)
{
cs_spi1_low();
send_spi1_byte(0x3D);
send_spi1_byte(0x2A);
send_spi1_byte(0x80);
send_spi1_byte(0xA6);
cs_spi1_high();
}
void at45_write_page(unsigned int addr)
{
volatile unsigned char low_addr, high_addr;
volatile unsigned int i;
low_addr = (char)(addr & 0x000000FF);
high_addr = (char)(addr >> 8);
cs_spi1_low();
send_spi1_byte(0x82);
send_spi1_byte(high_addr);
send_spi1_byte(low_addr);
send_spi1_byte(0x00);
for(i = 0;i < 256; i++)
{
send_spi1_byte(at45_write_buf[i]);
}
cs_spi1_high();
wait(100000);
}
void at45_read_page(unsigned int addr)
{
volatile unsigned char low_addr, high_addr;
volatile unsigned int i;
low_addr = (char)(addr & 0x000000FF);
high_addr = (char)(addr >> 8);
cs_spi1_low();
send_spi1_byte(0xD2);
send_spi1_byte(high_addr);
send_spi1_byte(low_addr);
send_spi1_byte(0x00);
send_spi1_byte(0x00);
send_spi1_byte(0x00);
send_spi1_byte(0x00);
send_spi1_byte(0x00);
send_spi1_byte(0x00);
at45_read_buf[0] = read_spi1_byte();
for(i = 0;i < 256; i++)
{
at45_read_buf[i] = read_spi1_byte();
}
cs_spi1_high();
}