|
|
View previous topic :: View next topic |
Author |
Message |
littlet05
Joined: 28 Jun 2009 Posts: 4
|
18F4620 & 24AA512 Serial EEPROM |
Posted: Fri Nov 13, 2009 10:12 am |
|
|
I'm attempting to write data to the Microchip 24AA512 Serial EEPROM fairly quickly for a data logging application. I have problems with data not being read and/or written properly at high speeds in a page write situation.
When I write single bytes infrequently they are written and read just fine.
I'm using MPLAB v8.30 and CCS Compiler 4.3.0.217 and a PICKIT2
Below is a fairly short test program:
Code: |
#include <18F4620.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,MCLR
#use delay(clock=10000000)
#use i2c(master, sda=PIN_C4, scl=PIN_C3)
#use rs232(baud=9600, xmit=PIN_A2, rcv=PIN_A3, ERRORS, stream=PK)
void main()
{
int8 i, j, msb;
char chOut;
for(msb = 0; msb < 10; msb++) //Write
{
i2c_start();
i2c_write(0xA0);
i2c_write(msb);
i2c_write(0x00);
for(i = 0; i < 100; i++)
{
i2c_write(msb+65);
}
i2c_stop();
delay_ms(5);
}
delay_ms(500);
for(msb = 0; msb < 10; msb++) //Read
{
i2c_start();
i2c_write(0xA0);
i2c_write(msb);
i2c_write(0x00);
i2c_start();
i2c_write(0xA1);
for(i = 0; i < 100; i++)
{
chOut = i2c_read();
fprintf(PK, "%s", chOut);
}
i2c_stop();
fprintf(PK, "%c", 0x0A);
fprintf(PK, "%c", 0x0D);
}
go: output_low(PIN_A1); //Sit and blink LED When done
delay_ms(1000);
output_high(PIN_A1);
delay_ms(1000);
goto go;
}
|
I added 5ms delays between each page write to allow it time to flash, and didn't go the whole length of the page just to be sure it wasn't some fence post problem.
The rs232 channel is the UART on the PicKit2, and the output should be 100 chars per line of A-K for each line.
I'm using 4.7k pullups on scl and sda.
I would like to know why my output is either garbled, or when I change the write char offset, the output doesn't write every time.
Help is appreciated,
JT |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 13, 2009 12:55 pm |
|
|
Quote: | for(i = 0; i < 100; i++)
{
chOut = i2c_read();
fprintf(PK, "%s", chOut);
}
i2c_stop(); |
The last i2c read operation in a block of reads, must do a NAK.
If there is only one i2c read, then it is the "last" one and it must
do a NAK. This is part of the i2c specification. Your code doesn't
do that. You do 100 sequential reads without a NAK on the last one.
In CCS, a NAK is done by giving i2c_read() a parameter of zero.
Example:
Code: | chOut = i2c_read(0); |
|
|
|
|
|
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
|