Hi,
Recently i've been trying to implement non-blocking I2C transfers on my FRDM-k22f but i'm struggling to make proper transfers.
As example i'm trying to send slave adress, register address and 2 data bytes but at the end i end up with 5 bytes instead of 4. I double check and i write to data register only 4 times so it seems analyzer sees random states on the bus as a byte?
I checked how much interrupts i get and there is 1 caused by STARTF, 4 caused by TCF and one by STOPF which seems to correct using this way of thinking:
1. startf - slaveaddress
2. regaddress
3. data
4. data
5. no data to send - generate stop condition
6. stopf interrupt
Now the problem starts because even i got interrupt by stopf i cannot get correct stop condition on the bus?
At 5th interrupt i use my I2C_stop function to generate stop condition:
void I2C_stop(I2C_Type *base)
{
base->C1 &= ~(I2C_C1_MST_MASK|I2C_C1_TX_MASK|I2C_C1_TXAK_MASK);
}
That's how it looks on analyzer:
Any ideas what might be wrong? I followed block schematic from k22f manual to properly handle interrupts but it's still not enough to get it going.
已解决! 转到解答。
Hi Brian Smith,
From your description, I think your problem still in the software side.
I highly recommend you refer to the official SDK code, which can be downloaded from this link:
Welcome | MCUXpresso SDK Builder
If you want to generate 4 times clock, you can just send 4 times in the code.
You can check the official I2C code at first, if the official code also have problem in your side.
Just let me know.
Have a great day,
Kerry
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Hi Brian
Take a look at appendix A of http://www.utasker.com/docs/uTasker/uTasker_I2C.pdf to see the I2C interrupts and states (use the non-buffered reference for the K22).
Also try https://github.com/uTasker/uTasker-Kinetis since it includes I2C simulation which also aids in tracing the operation, interrupts and identifying what may not yet be correct.
Did you write the I2C_stop() function or is it from a library? Resetting the TX bit is possibly a mistake.
Regards
Mark
Complete Kinetis solutions for professionals, training and support: http://www.utasker.com/kinetis.html
Kinetis K22:
- http://www.utasker.com/kinetis/FRDM-K22F.html
- http://www.utasker.com/kinetis/TWR-K22F120M.html
- http://www.utasker.com/kinetis/BLAZE_K22.html
- http://www.utasker.com/kinetis/tinyK22.html
Problem is that i clock is generated 5 times even i write to Data register only 4 times, no read operation and afaik only write/read operations to data registers actually generate clock? I will try to make it without start and stop interrupts as in single buffered from your pdf and let you know if that helped.
I2C stop is my own but i tried with and without resetting TX bit, result is almost the same, value of extra byte at the end is just different.
Hi Brian Smith,
From your description, I think your problem still in the software side.
I highly recommend you refer to the official SDK code, which can be downloaded from this link:
Welcome | MCUXpresso SDK Builder
If you want to generate 4 times clock, you can just send 4 times in the code.
You can check the official I2C code at first, if the official code also have problem in your side.
Just let me know.
Have a great day,
Kerry
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------