12-03-2015 10:10 AM
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?
12-04-2015 12:34 PM
The TI Forums might be a better resource for a question like this, but i suspect that the "*dat" argument is just looking for a pointer to the location you want the data read from the EEPROM to be stored. As you pointed out, it wouldn't make any sense to pass the data you want to read into the read function itself.
I'm not familiar at all with your hardware, so this is speculation, but I would expect something more like this:
Write (0xA0, 5400, 1); //==> Write 5400 into the address 0xA0 with the length of 1
Read(0xA0, &Variable, 1); //==> Give me the data from the address 0xA0 with the length of 1 and store it in "Variable"
Hope this helps
12-04-2015 12:57 PM
Hi Trent!
This is my question as well! And I already dropped my questions in TI Forum as well.
I know that I need to change my READ Function, because that default Read does not give me what I want.
*dat is a pointer that I can use in the write but I believe that as you said the Read does need another argument to read back the data! It is difficult to
understand this and figure this out!
You said &variable, however I I don't know how to use it and call it from the Read!
Somebody on TI said that I need to have the write like this:
char
write_dat[]={5};
iicEEPROM_write(addr,write_dat,1);
And Read function like the following.
However, the iicEEPROM_read() itself I have warnings!
This is getting confusing!
This should not be this much complicated!
uint8_t Read(uint16_t addr)
{
uint8_t value;
iicEEPROM_read(addr, &value, 0);
return
value;
}
12-07-2015 07:57 AM
Hi,
I'm not sure that I understand what you are confused about. That post you referenced looks like it's saying the same thing I did before, only a little less generic. Take the read function that they created:
uint8_t Read(uint16_t addr)
{
uint8_t value;
iicEEPROM_read(addr, &value, 0);
return
value;
}
uint8_t value; //==> Create a variable named "value" of the format uint8_t
iicEEPROM_read(addr, &value, 0); //==> Give me the data from the address "addr" with the length of 0 and store it in "value"
12-08-2015 12:12 PM
Thank you very much for your explanation. Now, the problem is that we think we have the right code but get zero! We should get the ports check by oscope to see what the problem is.
01-05-2016 08:38 AM
CEngineer,
Did you get any further with this? I am having a similar problem.
I am trying to simply write and then read back the stored data.
{ int *write_dat; //created integer pointer int data = 5; //created data to be stored write_dat = &data; //get write_dat to point at the data address iicEEPROM_write(0x20, write_dat, 0); //store what write_dat points at in address 0x20 uint8_t value; iicEEPROM_read(0x20, &value, 1); //read what is stored at 0x20 and store it in value }
Can you either post your working snippet or help me out at all?
Cheers
JSwale1