PIC
Revision as of 12:46, 11 January 2007 by 195.181.54.254 (talk)
Pic 18F452: I2C Programming W/O interrupts
(Remember to set direction SCK/SDA ports)
Initialization
- Enable Serial Bit = 1 (SSPEN=SSPCON<5>)
- Synchronous Serial Port Mode Select Bits = 1011 (SSPM3-SSPM0=SSPCON<3:0>
Common Start
- Start Enable Bit = 1 ( SEN=SSPCON2<0>)
- DelayMs(1)
- Load Address into SSPBUF
- Test Buffer Full status bit (BF=SSPSTAT<0>)
- loop until buffer bit is cleared
- Test acknowledge bit (ACK=SSPCON2<6>)
- if not acknowleded, abort
Write:
- Load data byte into SSPBUF
- Test Buffer Full status bif (BD=SSPSTAT<0>)
- Loop until bit is cleared
- Test acknowledge bit (ACKSTAT=SSPCON<6>)
- if not acknowledged, abort
Read
- Recieve Control Enable bit = 1 (RCEN=SSPCON<3>)
- Test Buffer Full status bit (BF=SSPSTAT<0>)
- Set acknowledge data=1 if data is recieved (ACKDT=SSPCON2<5>)
- Enable Acknowlede bit=1 (ACKEN=SSPCON<4>)
- Read data from SSPBUF
Common termination
- Stop Enable bit=1 (PEN=SSPCON2<2>)
Repeated start
- Repeated start enable bit =1 (RSEN=SSPCON2<1>)