реклама на сайте
подробности

 
 
> Запись в Serial EEprom.
Jenya7
сообщение Apr 11 2016, 13:01
Сообщение #1


Профессионал
*****

Группа: Участник
Сообщений: 1 778
Регистрация: 29-03-12
Пользователь №: 71 075



Записывая в память нужно следить чтобы не перейти страницу.
Код
#define USE_STATUS_REG 0   //doesn't help any way

void LOGGER_PageWrite(uint32_t address, uint32_t length, uint8_t *buffer)
{
    #if USE_STATUS_REG
    uint32_t timer;
    #endif
    volatile uint32_t page_limit=0;
    volatile uint32_t bytes_to_fit=0;
    volatile uint32_t bytes_to_write=0;

    //find a page limit for the address
    while (address > page_limit)
    {
        page_limit += 64;
    }
    //actual page limit
    page_limit--;

    bytes_to_fit = page_limit - address;
    bytes_to_write = bytes_to_fit;

    // Note!!!Every write operation demands a write enable!!!
    SPI_CSlow();
    SPI_SendByte(SPIEEPROM_CMD_WREN);
    SPI_CShigh();

    // start write
    SPI_CSlow();
    // send write command
    SPI_SendByte(SPIEEPROM_CMD_WRITE);
    // send address
    SPI_SendByte(address>>8);
    SPI_SendByte(address&0x00FF);
    while(bytes_to_write--)
    {
        // send data to be written
         SPI_SendByte(*buffer++);
    }
    // stop write
    SPI_CShigh();

    #if USE_STATUS_REG
    timer = LOGGER_DELAY;
    //wait for write operation to complete
    while(SPIEEPROM_ReadStatus() & SPIEEPROM_STATUS_WIP)
    {
        if(!--timer)
           break;
    }
    #else
    //needs 5ms for page write
    Delay_us_sys(5000);
    #endif

    if (bytes_to_fit <= length)
    {
        address += bytes_to_fit+1;
        bytes_to_write = length - bytes_to_fit;

         // Note!!!Every write operation demands a write enable!!!
        SPI_CSlow();
        SPI_SendByte(SPIEEPROM_CMD_WREN);
        SPI_CShigh();

        // start write
        SPI_CSlow();
        // send write command
        SPI_SendByte(SPIEEPROM_CMD_WRITE);
        // send address
        SPI_SendByte(address>>8);
        SPI_SendByte(address&0xFF);
        while(bytes_to_write--)
        {
            // send data to be written
            SPI_SendByte(*buffer++);
        }
        // stop write
        SPI_CShigh();

        #if USE_STATUS_REG
        timer = LOGGER_DELAY;
        //wait for write operation to complete
        while(SPIEEPROM_ReadStatus() & SPIEEPROM_STATUS_WIP)
        {
            if(!--timer)
                break;
        }
        #else
        //needs 5ms for page write
        Delay_us_sys(5000);
        #endif
    }
}

проверяю. пишу по середине большое количество байт чтоб перейти на другую страницу.
Код
uint8_t rxbuffer[50];
for (int i=0; i < 50; i++)
{
    rxbuffer[i] = i+1;
}
LOGGER_PageWrite(80, 50, rxbuffer);

и потом считываю.
Код
uint8_t txbuffer[50];
LOGGER_Read(80, 50,txbuffer);

результаты такие:
в адрессе 80-127 я вижу данные 1-47 и это правильно
в адрессе 128-130 я вижу /0, 48, 49

то есть первый адресс следующей страницы не прописывается. целый день бьюсь над проблемой не могу понять в чем дело.
Go to the top of the page
 
+Quote Post
3 страниц V  < 1 2 3  
Start new topic
Ответов (30 - 33)
jcxz
сообщение Apr 13 2016, 06:33
Сообщение #31


Гуру
******

Группа: Свой
Сообщений: 5 228
Регистрация: 3-07-08
Из: Омск
Пользователь №: 38 713



Цитата(Jenya7 @ Apr 13 2016, 12:29) *
бит 0-й но насколько я понял чтобы получить статус регистор надо каждый раз передавать команду. если передергивать слейв селект надо вводить задержку.

Откройте диаграмму чтения слова состояния в даташите. Там обычно рисуют что после последнего клока остаётся состояние последнего выдвинутого бита сколько угодно долго. Вопрос только в том - выводится ли там текущее состояние бита занятости или защёлкнутое в момент перепада SCLK.
Go to the top of the page
 
+Quote Post
Jenya7
сообщение Apr 13 2016, 06:50
Сообщение #32


Профессионал
*****

Группа: Участник
Сообщений: 1 778
Регистрация: 29-03-12
Пользователь №: 71 075



Цитата(jcxz @ Apr 13 2016, 12:33) *
Откройте диаграмму чтения слова состояния в даташите. Там обычно рисуют что после последнего клока остаётся состояние последнего выдвинутого бита сколько угодно долго. Вопрос только в том - выводится ли там текущее состояние бита занятости или защёлкнутое в момент перепада SCLK.

там написано так.
Цитата
To read the status register, the host simply sends a RDSR command. After receiving the last bit of the command, the CAT25256 will shift out the contents of the status register on the SO pin (Figure 10). The status register may be read at any time, including during an internal write cycle. While the internal write cycle is in progress, the RDSR command will
output the full content of the status register (New product, Rev. E) or the RDY (Ready) bit only (i.e., data out = FFh) for previous product revisions C, D (Mature product). For easy detection of the internal write cycle completion, both during writing to the memory array and to the status register, we
recommend sampling the RDY bit only through the polling routine. After detecting the RDY bit “0”, the next RDSR instruction will always output the expected content of the status register.

они рекомендуют поллинг то есть обращение к регистру в цикле. непонятно только что делать с ногой слейв селект.
Go to the top of the page
 
+Quote Post
aaarrr
сообщение Apr 13 2016, 16:41
Сообщение #33


Гуру
******

Группа: Свой
Сообщений: 10 713
Регистрация: 11-12-04
Пользователь №: 1 448



Цитата(Jenya7 @ Apr 13 2016, 09:50) *
непонятно только что делать с ногой слейв селект.

Цитата

Every communication session between host and CAT25256 must be preceded by a
high to low transition and concluded with a low to high transition of the CS input.
Go to the top of the page
 
+Quote Post
jcxz
сообщение Apr 13 2016, 17:01
Сообщение #34


Гуру
******

Группа: Свой
Сообщений: 5 228
Регистрация: 3-07-08
Из: Омск
Пользователь №: 38 713



Автор совершенно не желает читать даташит..... sad.gif
Go to the top of the page
 
+Quote Post

3 страниц V  < 1 2 3
Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 18th July 2025 - 21:25
Рейтинг@Mail.ru


Страница сгенерированна за 0.01389 секунд с 7
ELECTRONIX ©2004-2016