Hello,
I am using ke02z custom board. I have problem reading with DS1307 on board. I2C connected to I2C0, SDA PTA2, SCL PTA3. I had no problem with processor expert component DS1307. Now I am trying to move out of PE project because of the large library size after initializing all the peripherals. The problem is that I cannot read from I2C.
My code is as below.
sI2C_Config.u16Slt = 0; | |
sI2C_Config.u16F = 0x1F; | |
sI2C_Config.sSetting.bIntEn = 0; | |
sI2C_Config.sSetting.bI2CEn = 1; |
I2C_Init(I2C0,&sI2C_Config );
I2C_MasterReadWait(I2C0, 0x68, &dsbuffer[0], 9);
I am getting random values when reading. The reading also corrupts first 3 address locations in ds1307. (0x00, 0x01, 0x02).
I am running in FEE mode, external crystal 32khz, configured to run at 16.7MHz. I tried some other values of I2C Frequency Divider Register. Still getting random values and corrupting target. I have attached my project. DS1307 address is 0x68. I need to read values from address 0x00 to 0x09h. I also tried the interrupt mode . I have attached the project. I started the project from example file in driver_lib. Using KDS 3.2.
Please help. Thank you.
Original Attachment has been moved to: ds1307_read_test.zip
I read the i2c_masterreadwait() function.
It is transmitting 0x68<<1. It the proceeds to read directly , without writing the slave register address (in my case 0x00) and 0x68 |0x01.
Similar is the case for i2c_mastersendwait() function.
Is there a problem me using the library or should I insert some code.?
Hi Suraj,
It seems so weird, I don't think the root cause is from the library.
And according to the DS1307's datasheet, you can see that the slave address would be sent directly without plus send a 0x00.
And I'd highly recommend you to use the oscilloscope or logic analyzer to capture the wave, it can illustrate the root cause intuitively.
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
But is there a way to send slave address using the library? I am tried a lot of things but I haven't got an oscilloscope. I am currently using a library which creates problem if ds1307 is damaged/not inserted.
Thank you
Hi Suraj,
Regarding to the statement, the previous code which was generated by the PE had worked it out, however the current code failed.
So I'd highly recommend you to compare the initialization configuration of I2C in the previous and current code
Had you ever used the oscilloscope or logic analyzer to capture the wave when KE02 read the values from the DS1307?
If yes, I think you can figure out the root cause of the issue easily, as the wave can illustrates the I2C operations clearly.
Hope it helps.
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hello Jeremy,
Thank you for the replay.
The initialization seems OK.
I do not have an oscilloscope. But I tried the code from Kinetis I2C Driver by Jan Richter. That code is working, except that it is based on interrupt. But occasionally I get wrong values using his library, probably because of other isr? Keeping the same initialization code, and disabling i2c0 isr, I tried i2c_masterreadwait function as mentioned in the original post. But I am still getting random values. I have spent a few days on this, but it's still not working. Is there something I am missing in my code?
Hi Suraj,
Thanks for your reply.
I was wondering if you can tell me what the random values look like, and what the correctly values should be.
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hello Jeremy,
The seconds register reads like 40,27,248,178 etc where it should look like 1,2,3,….9,16,17..(it is BCD). I tried it with a wrong device address 0x50 and I get a constant 161. Again I tried with wrong address 0xD0, I get constant 161. So I guess the code is working upto the point where address is sent.