Difference between revisions of "PIC"

From HoerupWiki
Jump to: navigation, search
Line 19: Line 19:
 
#Test Buffer Full status bif (BD=SSPSTAT<0>)
 
#Test Buffer Full status bif (BD=SSPSTAT<0>)
 
##Loop until bit is cleared
 
##Loop until bit is cleared
#Test acknowledge bit (ACK=SSPCON<6>)
+
#Test acknowledge bit (ACKSTAT=SSPCON<6>)
 
##if not acknowledged, abort
 
##if not acknowledged, abort
  

Revision as of 12:46, 11 January 2007

Pic 18F452: I2C Programming W/O interrupts

(Remember to set direction SCK/SDA ports)

Initialization

  1. Enable Serial Bit = 1 (SSPEN=SSPCON<5>)
  2. Synchronous Serial Port Mode Select Bits = 1011 (SSPM3-SSPM0=SSPCON<3:0>

Common Start

  1. Start Enable Bit = 1 ( SEN=SSPCON2<0>)
  2. DelayMs(1)
  3. Load Address into SSPBUF
  4. Test Buffer Full status bit (BF=SSPSTAT<0>)
    1. loop until buffer bit is cleared
  5. Test acknowledge bit (ACK=SSPCON2<6>)
    1. if not acknowleded, abort

Write:

  1. Load data byte into SSPBUF
  2. Test Buffer Full status bif (BD=SSPSTAT<0>)
    1. Loop until bit is cleared
  3. Test acknowledge bit (ACKSTAT=SSPCON<6>)
    1. if not acknowledged, abort

Read

  1. Recieve Control Enable bit = 1 (RCEN=SSPCON<3>)
  2. Test Buffer Full status bit (BF=SSPSTAT<0>)
  3. Set acknowledge data=1 if data is recieved (ACKDT=SSPCON2<5>)
  4. Enable Acknowlede bit=1 (ACKEN=SSPCON<4>)
  5. Read data from SSPBUF

Common termination

  1. Stop Enable bit=1 (PEN=SSPCON2<2>)

Repeated start

  1. Repeated start enable bit =1 (RSEN=SSPCON2<1>)