PIC

From HoerupWiki
Revision as of 20:19, 10 January 2007 by 192.168.10.10 (talk)
Jump to: navigation, search

Pic 18F452: I2C Programming W/O interrupts

(Remember to set directon 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 (ACK=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>)