LinuxÖÐI2C×ÜÏßÇý¶¯Ìåϵ½á¹¹
×î½üÔÚ¿´Linux 2.6.21Äں˵ÄI2CÇý¶¯£¬Ò²ÔÚÍøÉϲéÁËÒ»ÏÂ×ÊÁÏ£¬ÓдíÒ²Óжԣ¬ÓÐЩÐĵ㬼ǼÏÂÀ´°É¡£ÀïÃæÈÏʶ»òÐí¶àÓв»µ±Ö®´¦£¬»¹¿ÒÇëÖ¸Õý¡£
1. I2C ÐÒé
1.1 I2C×ÜÏß¹¤×÷ÔÀí
I2C×ÜÏßÊÇÓÉÊý¾ÝÏßSDAºÍʱÖÓSCL¹¹³ÉµÄ´®ÐÐ×ÜÏߣ¬¸÷ÖÖ±»¿ØÖÆÆ÷¼þ¾ù²¢ÁªÔÚÕâÌõ×ÜÏßÉÏ£¬Ã¿¸öÆ÷¼þ¶¼ÓÐÒ»¸öΨһµÄµØַʶ±ð£¬¿ÉÒÔ×÷Ϊ×ÜÏßÉϵÄÒ»¸ö·¢ËÍÆ÷¼þ»ò½ÓÊÕÆ÷¼þ(¾ßÌåÓÉÆ÷¼þµÄ¹¦Äܾö¶¨)
1.2 I2C×ÜÏߵļ¸ÖÖÐźÅ״̬
1. ¿ÕÏÐ״̬£ºSDAºÍSCL¶¼Îª¸ßµçƽ¡£
2. ¿ªÊ¼Ìõ¼þ(S)£ºSCLΪ¸ßµçƽʱ£¬SDAÓɸߵçƽÏòµÍµçƽÌø±ä£¬¿ªÊ¼´«ËÍÊý¾Ý¡£
3. ½áÊøÌõ¼þ(P)£ºSCLΪµÍµçƽʱ£¬SDAÓɵ͵çƽÏò¸ßµçƽÌø±ä£¬½áÊø´«ËÍÊý¾Ý¡£
4. Êý¾ÝÓÐЧ£ºÔÚSCLµÄ¸ßµçƽÆڼ䣬 SDA±£³ÖÎȶ¨£¬Êý¾ÝÓÐЧ¡£SDAµÄ¸Ä±äÖ»ÄÜ·¢ÉúÔÚSCLµÄµ×µçƽÆڼ䡣
5. ACKÐźÅ: Êý¾Ý´«ÊäµÄ¹ý³ÌÖУ¬½ÓÊÕÆ÷¼þÿ½ÓÊÕÒ»¸ö×Ö½ÚÊý¾ÝÒª²úÉúÒ»¸öACKÐźţ¬Ïò·¢ËÍÆ÷¼þ·¢³öÌض¨µÄµÍµçƽÂö³å£¬±íʾÒѾÊÕµ½Êý¾Ý¡£
1.3 I2C×ÜÏß»ù±¾²Ù×÷
I2C×ÜÏß±ØÐëÓÉÖ÷Æ÷¼þ£¨Í¨³£ÎªÎ¢¿ØÖÆÆ÷£©¿ØÖÆ£¬Ö÷Æ÷¼þ²úÉú´®ÐÐʱÖÓ£¨SCL£©£¬Í¬Ê±¿ØÖÆ×ÜÏߵĴ«Êä·½Ïò£¬²¢²úÉú¿ªÊ¼ºÍÍ£Ö¹Ìõ¼þ¡£
Êý¾Ý´«ÊäÖУ¬Ê×ÏÈÖ÷Æ÷¼þ²úÉú¿ªÊ¼Ìõ¼þ£¬ËæºóÊÇÆ÷¼þµÄ¿ØÖÆ×Ö½Ú£¨Ç°ÆßλÊÇ´ÓÆ÷¼þµÄµØÖ·£¬×îºóһλΪ¶Áдλ £©¡£½ÓÏÂÀ´ÊǶÁд²Ù×÷µÄÊý¾Ý£¬ÒÔ¼° ACKÏìÓ¦Ðźš£Êý¾Ý´«Êä½áÊøʱ£¬Ö÷Æ÷¼þ²úÉúÍ£Ö¹Ìõ¼þ
2. Linux I2C ½á¹¹·ÖÎö
2.1 ²ã´Î·ÖÎö
1. I2C Core
I2C CoreÓÃÓÚά»¤LinuxµÄI2CºËÐIJ¿·Ö£¬ÆäÖÐά»¤ÁËÁ½¸ö¾²Ì¬µÄList£¬·Ö±ð¼Ç¼ϵͳÖеÄI2C driver½á¹¹ºÍI2C adapter½á¹¹¡£
static LIST_HEAD(adapters);
static LIST_HEAD(drivers);
I2C coreÌṩ½Ó¿Úº¯Êý£¬ÔÊÐíÒ»¸öI2C adatper£¬I2C driverºÍI2C client³õʼ»¯Ê±ÔÚI2C coreÖнøÐÐ×¢²á£¬ÒÔ¼°Í˳öʱ½øÐÐ×¢Ïú¡£¾ßÌå¿ÉÒԲμûi2c_core.c´úÂë¡£
ͬʱ»¹ÌṩÁËI2C×ÜÏ߶Áд·ÃÎʵÄÒ»°ã½Ó¿Ú£¨¾ßÌåµÄʵÏÖÔÚÓëI2C¿ØÖÆÆ÷Ïà¹ØµÄI2C adapterÖÐʵÏÖ£©£¬Ö÷ÒªÓ¦ÓÃÔÚI2CÉ豸Çý¶¯ÖС£
³£ÓõÄÖ÷ÒªÊÇ
i2c_master_send()
i2c_master_recv()
i2c_transfer()
2. I2C bu
Ïà¹ØÎĵµ£º
#include <iostream>
#include <cstdlib>
using namespace std;
class Foo
{
public:
Foo(int ii):i(ii){}
int getInt(){return i;}
private:
int i;
};
class Bar
{
public:
static int FooVal(){c++; return f.getInt();}
int callsFooVal(){return c;}
private:
s ......
ÔÎĵØÖ·£ºhttp://blog.csdn.net/yc0188/archive/2005/02/26/303190.aspx
ÔÚCÓïÑÔÖУ¬½á¹¹ÊÇÒ»ÖÖ¸´ºÏÊý¾ÝÀàÐÍ£¬Æä¹¹³ÉÔªËؼȿÉÒÔÊÇ»ù±¾Êý¾ÝÀàÐÍ£¨Èçint¡¢long¡¢floatµÈ£©µÄ±äÁ¿£¬Ò²¿ÉÒÔÊÇһЩ¸´ºÏÊý¾ÝÀàÐÍ£¨ÈçÊý×é¡¢½á¹¹¡¢ÁªºÏµÈ£©µÄÊý¾Ýµ¥Ôª¡£ÔڽṹÖУ¬±àÒëÆ÷Ϊ½á¹¹µÄÿ¸ö³ÉÔ±°´Æä×ÔÈ»¶Ô½ç£¨alignment£©Ìõ¼þ·ÖÅä¿Õ¼ä¡£¸÷ ......
¡¡I2C×ÜÏß¾ßÓнṹ¼òµ¥Ê¹Ó÷½±ãµÄÌص㡣±¾ÎÄÃèÊöÁËlinuxÏÂI2CÇý¶¯µÄ½á¹¹£¬²¢ÔÚ´Ë»ù´¡Éϸø³öÁËI2CÉ豸Çý¶¯ºÍÓ¦ÓõÄʵÏÖ¡£
¡¡¡¡1 ÒýÑÔ
¡¡¡¡I2C (Inter£Integrated Circuit)×ÜÏßÊÇÒ»ÖÖÓÉPHILIPS¹«Ë¾¿ª·¢µÄÁ½Ïßʽ´®ÐÐ×ÜÏߣ¬ÓÃÓÚÁ¬½Ó΢¿ØÖÆÆ÷¼°ÆäÍâΧÉ豸¡£I2C×ÜÏß×îÖ÷ÒªµÄÓŵãÊÇÆä¼òµ¥ÐÔºÍÓÐЧÐÔ¡£ÓÉÓÚ½Ó¿ÚÖ±½ÓÔÚ×é¼þÖ ......
¡¡I2C×ÜÏß¾ßÓнṹ¼òµ¥Ê¹Ó÷½±ãµÄÌص㡣±¾ÎÄÃèÊöÁËlinuxÏÂI2CÇý¶¯µÄ½á¹¹£¬²¢ÔÚ´Ë»ù´¡Éϸø³öÁËI2CÉ豸Çý¶¯ºÍÓ¦ÓõÄʵÏÖ¡£
¡¡¡¡1 ÒýÑÔ
¡¡¡¡I2C (Inter£Integrated Circuit)×ÜÏßÊÇÒ»ÖÖÓÉPHILIPS¹«Ë¾¿ª·¢µÄÁ½Ïßʽ´®ÐÐ×ÜÏߣ¬ÓÃÓÚÁ¬½Ó΢¿ØÖÆÆ÷¼°ÆäÍâΧÉ豸¡£I2C×ÜÏß×îÖ÷ÒªµÄÓŵãÊÇÆä¼òµ¥ÐÔºÍÓÐЧÐÔ¡£ÓÉÓÚ½Ó¿ÚÖ±½ÓÔÚ×é¼þÖ ......
I2CÊÇPhillips¿ª·¢µÄ2ÏߵĴ®ÐÐ×ÜÏßÐÒ顣ͨ³£Ó¦ÓÃÔÚǶÈëʽϵͳÖÐÈò»Í¬µÄ×é¼þͨÐÅ£¬PCÖ÷°å¿ÉÒÔͨ¹ýI2CÀ´Ó벻ͬµÄ´«¸ÐÆ÷ͨÐÅ¡£ÕâЩ´«¸ÐÆ÷ͨ³£±¨¸æ·çÉÈËٶȣ¬´¦ÀíÆ÷ζȺÍÕû¸öÓ²¼þϵͳµÄÐÅÏ¢£¬Õâ¸öÐÒéÒ²¿ÉÒÔÓÃÔÚRAM chipsÉÏ£¬Ïò²Ù×÷ϵͳÌṩDIMMµÄÐÅÏ¢¡£
ÔÚ2.0ʱI2CµÄkernelÔ´Âë²»ÔÚÄÚºËÀïµÄ£¬2.4Äں˰üÀ¨ÁËÒ»µã¶ÔI2CµÄÖ§³Ö ......