https://static.assets-stash.eet-china.com/album/old-resources/2009/6/9/d698dc9c-fa7a-46e5-8141-92ae3eaaef1f.rar
最近在做一个CPLD(MAX II EMP240)的小项目,要写一个I2C Slave模块,来代替原来的IO-expander,代码两天写好了,调试却花了三个礼拜,遇到的问题其实只有一个,分两步解决:
1、老板非要在打板之前把代码验证好,所以手工制作了一个demo板,代码在上面调试了两个礼拜,一直在改代码,后来才发现代码的问题不大,原来是自己制作的demo板有问题,不是我焊的不好,而是手工搭的干扰太大,导致内部的一个计数器错误计数,正好原来的主板上已经有一颗CPLD了,就把代码下到主板上的那个CPLD上,出错的概率降低了一百倍,但还是有错误,不能用在量产上。
2、既然计数器错误计数那就是触发它的clk有问题,但scl只有20K,我们都不认为这会影响到计数器。可事实上确实是这样,在scl上下拉了一个30pF的陶瓷电容,问题没有了。起初为是overshoot或undershoot对计数器产生了影响,但通过示波器观察电容只是影响了scl的上升沿,对其他特性到没多大影响,这就让人很难理解了,但问题确实解决了。
为什么呢?!为什么是一个电容呢???
代码是我参考一随书光盘的例子,但不能直接编译,需要修改,需要说明的是那个主体的状态机是对的,有兴趣的可以看看。
后记:电容不是真正的原因,板子打出来了,加上电容作用不大。将上拉电阻减小效果明显,但稳定性不敢保证,后来偶然把MAXII的引脚施密特触发器加上问题全部解决了。
今天看到了这么一段话,来自Altera官网的一个I2C 控制器(master)的参考设计文档,摘录如下:This design uses the I2C SCL signal as a clock. This requires that the SCL signal have clean, fast edges on both the rising and falling edges of this signal. Slow rise and fall times on this signal can show noise effects which can cause improper clocking of registers within the Stratix FPGA. If the loading of the SCL signal in the system is such that the rise and fall times are slow (>20nS), external buffers such as Schmitt Triggers will be required to interface to the FPGA
用户80674 2010-1-4 20:40
用户1447181 2009-7-13 00:04
用户220317 2009-7-10 10:07
tengjingshu_112148725 2009-6-12 09:53