Вот уже рабочий код, и пишет и читает, но с ошибками иногда. *тут смайлик котэ бьющегося о стену*
Если кто желает использовать, не забудьте выполнить функцию at45_power_two() ОДИН РАЗ за всю жизнь флэшки, она навсегда переключает режим адресации с 264байт/страница на 256байт/страница.
Код:
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();
}