CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PCM Programmer a Question about your code

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Hans Wedemeyer



Joined: 15 Sep 2003
Posts: 226

View user's profile Send private message

PCM Programmer a Question about your code
PostPosted: Fri Feb 27, 2004 9:33 am     Reply with quote

I found your external eeprom code (thanks) and it works fine except for the block write.
Block write trashes data.

Reading the data sheet for the chip (Microchip 24LC256) The delay of 6mS should be enough time for the write to complete.

As the single byte write and block read are working fine I have to assume the IC2 is also working OK, which bring me to my questions:

Are there any code changes to the block write function ?
Do you know of any other problems with external eeprom block write ?

Thanks
Hans W




//-------------------------------------------------------------------------------
// This will write a block of bytes. The length can be from 1 to the page length.
// If the starting address and count are such that the bytes extend past the page,
// then the eeprom will internally wrap the address ptr around, and overwrite the
// bytes at the start of the page.

void write_eeprom_block(long addr, char block_len, char* in_buffer)
{
char i;

if(block_len == 0)
return;

i2c_start();
i2c_write(EEPROM_I2C_WRITE_ADDR);
i2c_write((char)(addr >> 8));
i2c_write((char)addr);

for(i = 0; i < block_len; i++)
{
i2c_write(*in_buffer++);
}

i2c_stop();
delay_ms(6); // Wait enough time for the write to occur
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 27, 2004 12:32 pm     Reply with quote

Can you post a small test program that shows how you are
calling the block_write() function ? Can you show the
variable declarations for the parameters that you are
passing to the function, and also show the values of
the parameters. Tell me in what way the data is
getting trashed. Then I'll test it on my demo board.
Hans Wedemeyer



Joined: 15 Sep 2003
Posts: 226

View user's profile Send private message

soon
PostPosted: Fri Feb 27, 2004 2:01 pm     Reply with quote

That's a good point, I should write a stand alone version that only writes block data and reads it back.

I'm due to head for field testing on Monday and will be gone for about 3 days.

In the mean time here is the modified way I'm using your code.

It can write to as many as 8 chips. I use the same code for FRAM and simply bypass the delay at the end.

The data appear to be OK for 1 or two bytes. It appear the first few bytes of each block are OK before it falls apart.

At the moment the code it writing one byte at a time and that works OK, but I would like to speed up the process.

I'll post a test program next week...
Thanks...
hansw


void write_eprom_block(int chip, long addr, long block_len, char* in_buffer, int type)
{
long i;

if(block_len == 0)
return;

i2c_start();
i2c_write( (0xa0|(unsigned char)(chip<<1))&0xFE );
i2c_write((char)(addr >> 8));
i2c_write((char)addr);


for(i = 0; i < block_len; i++)
{
i2c_write( in_buffer[i]);
}

i2c_stop();
if(type == EPROM)
{
delay_ms(6);
}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 27, 2004 2:35 pm     Reply with quote

I guess you won't be back for a while, but when you do, I need to know:

1. The part number of the chip that caused the failure. Also what
was the Vdd voltage used for the chip ?

2. What were the values of the parameters passed to the function
when the failure occurred ?

3. What code was used to read back the data, so as to determine
that a failure had occurred ? Can you post it ?

4. Was the WP pin left floating ? This can be done with a 24LC256,
because it has an internal pull-down. Some Ramtron chips, such
as FM24C256 have the same feature, but others, such as FM24C64
must have the WP pin externally tied low. It must not be left
floating.
Hans Wedemeyer



Joined: 15 Sep 2003
Posts: 226

View user's profile Send private message

part number
PostPosted: Fri Feb 27, 2004 4:38 pm     Reply with quote

24LC256-I/SM

The entire system is using 3.3V

WP is hard wired to GND. There is only one FRAM in the system it is at chip address 0 the other 7 chips are Microchip 24LC256-I/SM

Code to read back is your code for single byte read, and it works fine.

The data is binary data from the ADC, however the data should look like a sine wave but does not when I use the block write.

I think a standalone program will reveal what is wrong, and I can save an array of known data and compare that when read back.

I'll keep you posted.

hansw
Tomi
Guest







Page boundaries?
PostPosted: Sat Feb 28, 2004 5:10 am     Reply with quote

Hi Hans,
24LC256 has 64-byte pages. You have to terminate and restart I2C session when you reach a boundary. Additionally if you want to increase your speed then poll for the write's end instead of that poor delay. I use something like this:
void TerminateIIC()
{
StopIIC();
do {
StartIIC();
WriteIIC(0xA0); // try to open for read
} while (ACKSTAT); // not ACK'd while busy
StopIIC(); // ACKd so close it
}

void IncPutAddr() // to increment the write addess pointer
{
putaddr++;
if (!(putaddr & 0x3F)) { // we are at boundary
TerminateIIC(); // close the session
StartIIC(); // and re-open
WriteIIC(0xA0);
WriteIIC(putaddrH);
WriteIIC(putaddrL);
}
}


Brg,
Tomi
Hans Wedemeyer



Joined: 15 Sep 2003
Posts: 226

View user's profile Send private message

Thanks I'll try that next week...
PostPosted: Sat Feb 28, 2004 11:35 pm     Reply with quote

as per subject line... thanks.
Guest








For Tomi
PostPosted: Wed Mar 10, 2004 7:57 am     Reply with quote

I re-read your post and tried to implement it.

Comments:
The original code already stops the Ic2 at each block.
Your code to monitor ACKSTAT does not seem to work, it hangs in a loop.

Conclusion:
I would like to implement the ACKSTAT idea, sounds like a winnner.

Stopping IC2 at each block boundary happened in the original code any way and therefore can't be the problem.


I'm off to the do more field testing (covered in sun screen and bug spray. I love Texas !) and will write a stand alone program to further test .
thanks

hansw
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group