Difference between revisions of "PIC"
Line 14: | Line 14: | ||
#Test acknowledge bit (ACK=SSPCON2<6>) | #Test acknowledge bit (ACK=SSPCON2<6>) | ||
##if not acknowleded, abort | ##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 (ACK=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>) |
Revision as of 20:19, 10 January 2007
Pic 18F452: I2C Programming W/O interrupts
(Remember to set directon 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 (ACK=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>)