I looked at the official example code and found an I2C_Master_Int example code, which also uses I2C to control the 24C02 memory chip.
After I connected the line, I found that the serial port would only have this situation and could not continue to run downwards
So I looked up the usage of the 24C01 chip and found that when A1, A2, and A3 are all connected to GND, the device address is 0XA0
So I looked at the address in the sample code and found that it was defined as 0x10
So I changed the device address to 0xa0 and ran it again and found that the result did not change
It was still stuck there and didn't finish running, so I added serial port output functions to various places in the code to determine where it was stuck.
But I found that it didn't get stuck after adding the output function, so I guessed that it might be due to the lack of delay, so I added a delay function
After adding it, I found that it can run normally until the end.
At this time, I found that the output is incorrect
Output
So the written data and the output data are inconsistent.
So I added
The output result is as shown in the figure (the front is the read data, and the back is the written data)
It turned out that the data was wrong, but I found out from multiple test data and some information on the Internet that
This may be caused by inconsistency in the locations where data is written and read.
So I tried to define the write position and read position, but unfortunately it failed.
I haven't found any information about this, and I really don't know how to do it.
But I found out from the information on the Internet that when writing data, if you write to the end of a page, then when reading, it will start reading from the initial position of this page.
So I changed the size of the data written
The blog I found used a size of 8, but I found it was 16 through experimentation
Then I ran it again
The written data is consistent with the read data;
At this point, the writing and reading of the memory chip is completed.
But obviously this is not correct. What I want is to write data and read data. I need to know where I wrote the data and where I should read the data from. I did not find any information about this in the sample code.
There are also some information on how to write data to a specified location on the Internet, but I found that their method is like this
Send the memory address to be written after sending the address and write bit
But I found
I2C_7bit_Addr_Send(I2C1, EEPROM_ADDRESS, I2C_DIRECTION_SEND);
I2C_Data_Send(I2C1, address); // 发送内存地址
I2C_Data_Send(I2C1, data); // 发送数据
It's always like this. I'm curious why sending memory addresses like this is not considered as sending normal data.
And it also needs to be sent when reading, I don’t understand it either
In short, I just haven’t learned it, is there any big guy who can help me
|