Quantcast
Viewing all articles
Browse latest Browse all 654

EEPROM ---- How to Read Back

Here is the code that MSP430f47197 includes in its code as follows for READ/WRITE Functions.

 

Write:

int iicEEPROM_write(uint16_t addr, void *dat, int len)
{
    int i;
    int j;
    int section_len;
    uint8_t *p;
    uint8_t *q;

    /* If the write spreads across pages in the EEPROM, we need to split the write
       into sections. */
    q = (uint8_t *) dat;
    while (len > 0)
    {
        if (addr + len > ((addr + EEPROM_PAGE_SIZE) & ~(EEPROM_PAGE_SIZE - 1)))
            section_len = ((addr + EEPROM_PAGE_SIZE) & ~(EEPROM_PAGE_SIZE - 1)) - addr;
        else
            section_len = len;
        for (i = 0;  i < MAX_IIC_TRIES;  ++i)
        {
            if (i)
            {
                /* Write FALSE, retry */
                if (test_SDA())
                    continue;
            }

            iic_start();
#if EEPROM_PAGE_SIZE == 32
            if (iic_send(0xA0)  ||  iic_send(addr/0x100)  ||  iic_send(addr))
                continue;
#else
            if (iic_send(0xA0 | ((uint8_t)(addr/0x100)*2))  ||  iic_send(addr))
                continue;
#endif
            p = q;
            for (j = section_len;  j > 0;  j--)
            {
                if (iic_send(*p++))
                    break;
            }
            if (j == 0)
                break;
            iic_stop();
        }
        iic_stop();
        if (i >= MAX_IIC_TRIES)
            return FALSE;
        len -= section_len;
        addr += section_len;
        q += section_len;
    }
    return TRUE;
}

 

Read:

 

int iicEEPROM_read(uint16_t addr, void *dat, int len)
{
    int i;
    int j;
    uint8_t *p;

    for (i = 0;  i < MAX_IIC_TRIES;  ++i)
    {
        if (i)
        {
            /* Read FALSE, retry */
            if (test_SDA())
                continue;
        }
        iic_start();
#if EEPROM_PAGE_SIZE == 32
        if (iic_send(0xA0)  ||  iic_send(addr/0x100)  ||  iic_send(addr))
            continue;
#else
        if (iic_send(0xA0 | ((uint8_t)(addr/0x100)*2))  ||  iic_send(addr))
            continue;
#endif
        p = (uint8_t *) dat;

        iic_start();
#if EEPROM_PAGE_SIZE == 32
        if (iic_send(0xA1))
            continue;
#else
        if (iic_send(0xA1 | ((uint8_t)(addr/0x100)*2)))
            continue;
#endif
        for (j = len;  j > 0;  j--)
            *p++ = iic_receive(TRUE);
        *p = iic_receive(FALSE);
        iic_stop();
        return TRUE;
    }
    iic_stop();
    return FALSE;
}

 

I totally understand the "Write" function. However, for the Read function I do not need to understand the concept behind that. I simply need to write into an address and read it back from this. However, the READ Function does not give me what I want!

I don't understand the concept of having "void *dat" within the arguments! If I knew Dat why should I ask the EEPROM to give me the same data?!!!!

 

I just need the simple thing as follows.

 

 

Write ( 0xA0, 5400, 1);  //==> Write  5400 into the address 0xA0 with the length of 1

Read(0xA0,1);    //==> Give me the data from the address 0xA0 with the length of 1

 

I tried to modify the Read function and got rid of "dat" but what I can retrieve is not what I put when I wrote into!

Can somebody tell me how I can figure this out?


Viewing all articles
Browse latest Browse all 654

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>