I2C clock
Posted: Sat Apr 02, 2016 11:17 pm
I'm going to use the I2C support on a MK20DX256VLH7 chip. So I started by looking at the implementation (currently I'm using flabbergast's fork, but now that it's merged I will probably soon start using the contrib version). But I think I found some bugs for the clock setting.
I'm not experience with microcontroller programming, so rather than doing a pull request, I ask more experienced people here first. The code calculates the divisor using the sysclock frequency, but if I'm reading the documentation right it should be the bus frequency. So is this a bug?
The code also doesn't take advantage of the multiplier, which would make it possible to support more exact speeds. Since the SCL divider values are closer together for low values, I think the highest possible divider should be applied first, before trying to find the best fitting value.
Finally the code doesn't expose the fact that you can tune the hold times. I don't know how important that is in practice, but maybe it would be a good idea to let the user be able to set the frequency register manually too if he wants to, for example by making a clock value of 0 a special value, and adding another field to the configuration?
I'm not experience with microcontroller programming, so rather than doing a pull request, I ask more experienced people here first. The code calculates the divisor using the sysclock frequency, but if I'm reading the documentation right it should be the bus frequency. So is this a bug?
The code also doesn't take advantage of the multiplier, which would make it possible to support more exact speeds. Since the SCL divider values are closer together for low values, I think the highest possible divider should be applied first, before trying to find the best fitting value.
Finally the code doesn't expose the fact that you can tune the hold times. I don't know how important that is in practice, but maybe it would be a good idea to let the user be able to set the frequency register manually too if he wants to, for example by making a clock value of 0 a special value, and adding another field to the configuration?