AT45DB081D скажите что делаю не так

Дисплеи, датчики и прочие функциональные узлы, управляемые МК.
Ответить
Родился
Сообщения: 2
Зарегистрирован: Вт авг 28, 2012 10:18:34
Откуда: Санкт-Петербург

Сообщение Batson »

Буфер флэшки пишется и читается, но во флэш не записывается. Для теста пишу в нулевую страницу, пробывал писать в другие страницы с тем же результатом, вроде все правильно делаю. :shock:

Код: Выделить всё

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(); 
}
Реклама
Родился
Сообщения: 2
Зарегистрирован: Вт авг 28, 2012 10:18:34
Откуда: Санкт-Петербург

Сообщение Batson »

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

Вернуться в «Периферия»