Hi,
Now I am using FRDM-K22F, I2C polling_transfer example of V2.0 SDK example code. My understanding is that, I2C0 work as master to do write/read three-axis accelerometer(slave device). Normally the content of writing and reading should be same, but they don't match as below picture. why?
Hi Kent,
Please remember you are writeing/reading peripheral instead of memory. When accessing peripherals like accelerometer, you are accessing its registers, you cannot gurantee write/read result is the same.
Which specific register you are trying to access?
Hao
HI Cutworth,
Thanks a lot for your remind. Yes, you are right. But I don't study the accelerometer chip data sheet, I just supposed that at least one or two of 32 bytes should be same, also the example that NXP provide have the code to compare write and read data, my understanding is that they should be same, to say that what you wrote into EEPROM are reading correctly by reading. You means that I2C polling_transfer example of V2.0 SDK example code for FRDM-K22F I2C0 master wirte/Read data are not same?
Also I found that I2C_MASTER_SLAVE_ADDR_7BIT is 0x7EU in origin code, but the address is 0x1C in the FRDM-K22F schematic, which address I should use? How to define the I2C_MASTER_SLAVE_ADDR_7BIT(masterXfer.slaveAddress) address?
masterXfer.subaddress = 0; masterXfer.subaddressSize = 0; means what?
Actually I don't want to read accelerometer, just want to write/read I2C E2PROM in my board. Just want to refer any kintis I2C write/reading example. In a word, do you have any example can realize I2C write and reading content same using K22F chip?
Sorry to so many question because I am new for Kinetis chip and SDK.
Best Regards,
Kent
Hi Kent,
Please note the I2C polling transfer demo is made with two I2C instance of K22F, that is why you will see write/read data is the same. The same is true for EEPROM.
The I2C address of course should be changed to the device address you use like 0x1C on FRDM board.
And for the meaning for subaddress and subaddressSize in master transfer struct, it's related to register address of the device you try to communicate. For example, with accelerometer, you will have the I2C device address and you also have the register address inside the accelerometer device. Some device's register is not 8bit, some are 16bit. That's why you also need to know the subaddressSize. These information will be sent after the address stage for I2C communication.
Hao
Cutworth Wang wrote:
And for the meaning for subaddress and subaddressSize in master transfer struct, it's related to register address of the device you try to communicate. For example, with accelerometer, you will have the I2C device address and you also have the register address inside the accelerometer device. Some device's register is not 8bit, some are 16bit. That's why you also need to know the subaddressSize. These information will be sent after the address stage for I2C communication.
Wow, it'd be really nice if this kind of information were in the API document.
Hi Cutworth,
//Write
//Read
Writing and reading both action work well because the function return 0, but seems that write and reading data is not same. Seems that reading data is initial data in E2PROM because all data is 0xff. It means that we don't sucess in writing data to E2PROM?
Kent:Now I use the STM24128 I2C E2PROM, address is 0(E0,E1,E2), and then the device address is 0x00? I don't know how to define it?
Have a good day.
Kent
Have solved the problem:
#1, Device address, need to define base on your chip for application.
#2, subaddressSize, it is device subaddress length, such as1 byte device sub address, subaddressSize is 1; and such as 2 byte device sub address, subaddressSize is 2.