AT24C1024 full capacity read and write NXPLPC11XX source program[Copy link]
AT24C1024 full capacity read and write program, as long as the read and write start address and read and write length, the program automatically crosses pages, absolutely original, absolutely easy to use, including test program.
*pData++=I2C_Recieve_Byte(1); // The response bit is ACK, do not release the bus, continue reading
nBytes--;
}
*pData++=I2C_Recieve_Byte(0); // The response bit is NACK, stop reading, and release the bus
I2C_Stop(); // Generate a stop condition
delay_us(10); // This delay is the minimum time interval when reading two segments of data at any address, ensuring that the next start bit is generated normally after the stop bit.
while(nBytes != 0) // All data has been sent, exit the loop
{
StartAddr_L = StartAddr & 0x0000ff; // Calculate the low address
StartAddr_H = (StartAddr >> 8) & 0x0ff; // Calculate the high address
P0 = (StartAddr / 0x10000) << 1; // Calculate the 17th bit, which is P0
I2C_Send_Ctrl(AT24C1024_Addr | P0); // Send device address with P0
I2C_Send_Byte(StartAddr_H); // Send high address
I2C_Send_Byte(StartAddr_L); // Send low address
while(nBytes != 0) // Data is not sent yet, loop
{
I2C_Send_Byte(*pData);
pData++;
nBytes--;
StartAddr++;
if((StartAddr & 0x00ff) == 0) // Cross page, terminate the current page loop, and rewrite the new address
break;
}
I2C_Stop(); // Generate a stop condition
delay_ms(3); // This delay is the minimum interval between two read and write operations. Do not delete it. It is useful when writing a large amount of data continuously.
union Initial_Value{uint8 Val_Hex[400];float Val_Float[100];}Init; //Define a floating point array for writing and reading. A floating point number uses 4 bytes.
uint16 i;
float j;
SysCLK_config(); // Clock configuration
I2C_Init(0); // Initialize I2C fast mode
delay_ms(10);
for(i=0; i<100; i++) // Initialize the floating-point array to 0-99 respectively.