49
The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter-Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris® LM3S9B96 Microcontroller - DATA SHEET”

The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Embed Size (px)

Citation preview

Page 1: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

The Cortex-M3 Embedded Systems:

LM3S9B96 Microcontroller – Inter-Integrated Circuit (I2C)

InterfaceRefer to Chapter 15 in the reference book“Stellaris® LM3S9B96 Microcontroller - DATA SHEET”

Page 2: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Inter-Integrated Circuit (I2C) Interface

The Inter-Integrated Circuit (I2C) bus : bi-directional data transfer via a two-wire design:

a serial data line SDA and a serial clock line SCL interfaces to external I2C devices: serial memory,

networking devices, LCDs, tone generators

Page 3: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Inter-Integrated Circuit (I2C) Interface

The LM3S9B96 microcontroller includes two I2C modules: Supports both transmitting and receiving data as

either a master or a slave Four I2C modes: Master/Slave transmit/receive Two transmission speeds: Standard (100 Kbps)

and Fast (400 Kbps) Master and slave interrupt generation Master with arbitration and clock synchronization,

multi-master support, and 7-bit addressing mode

Page 4: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Block Diagram

Page 5: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Functional Description

The I2C bus uses only two signals: SDA and SCL, named I2CSDA and I2CSCL on Stellaris microcontrollers

The bus is considered idle when both lines are High Every transaction on the I2C bus is nine bits long,

i.e., 8 data bits (MSB first) and 1 single acknowledge bit

The number of bytes in one transfer is unrestricted When a receiver cannot receive another complete

byte, it can hold the clock line SCL Low and force the transmitter into a wait state

The data transfer continues when the receiver releases the clock SCL

Page 6: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

I2C Bus Configuration

Rp Rp

VDD

SCLSDA

SDA³ö

SDAÈëSCLÈë

SCL³ö

SCLSDA

Æ÷¼þ1 Æ÷¼þ2

I2C BUS

SCL Output

SDA Output

SCL Input SDA Input

Page 7: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

START and STOP Conditions

The protocol of the I2C bus defines two states to begin and end a transaction: START and STOP A High-to-Low transition on the SDA line while the SCL is

High is defined as a START condition A Low-to-High transition on the SDA line while SCL is High is

defined as a STOP condition

Page 8: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Data Format with 7-Bit Address

After the START condition, a slave address is transmitted

The address is 7 bits long and followed by a direction bit (R/S bit in the I2C Master Slave Address (I2CMSA) register) If R/S is cleared, a transmit operation (send) If R/S is set, a request for data (receive)

A data transfer is always terminated by a STOP condition generated by the master

A master can initiate communications with another device on the bus by generating a repeated START condition and addressing another slave without first generating a STOP condition.

Page 9: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Data Format with 7-Bit Address

A zero in the R/S position of the first byte means that the master transmits (sends) data to the selected slave, and a one in this position means that the master receives data from the slave

Page 10: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Data Validity

The data on the SDA line must be stable during the high period of the clock

The data line can only change when SCL is Low

Page 11: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Acknowledge

All bus transactions have a required acknowledge clock cycle

During the acknowledge cycle, the transmitter (master or slave) releases the SDA line

To acknowledge the transaction, the receiver must pull down SDA during the acknowledge clock cycle When a slave receiver does not ack the slave address, the

master can generate a STOP condition and abort the current transfer.

When the master acting as a receiver, it is responsible for acknowledging each transfer made by the slave

The master receiver controls the number of bytes in the transfer by not generating an acknowledge on the last data byte; slave transmitter will give up the data line

Page 12: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Available Speed Modes

The I2C bus can run in either Standard mode (100 kbps) or Fast mode (400 kbps)

The selected mode should match the speed of the other I2C devices on the bus

The mode is selected by using a value in the I2C Master Timer Period (I2CMTPR) register

The I2C clock rate is determined by the parameters: CLK_PRD is the system clock period SCL_LP is the low phase of SCL (fixed at 6) SCL_HP is the high phase of SCL (fixed at 4) TIMER_PRD is the programmed value in the I2CMTPR

register

Page 13: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Available Speed Modes

SCL_PERIOD = 2 × (1 + TIMER_PRD) × (SCL_LP + SCL_HP) × CLK_PRD

For example: CLK_PRD = 50 ns, TIMER_PRD = 2, SCL_LP=6, SCL_HP=4Therefore, the SCL frequency is : 1/SCL_PERIOD = 333 Khz

Page 14: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Interrupts

The I2C can generate interrupts when the following conditions are observed: Master transaction completed Master transaction error Slave transaction received Slave transaction requested Stop condition on bus detected Start condition on bus detected

The I2C master and I2C slave modules have separate interrupt signals

A module can generate interrupts for multiple conditions but only one single interrupt signal is sent to the interrupt controller

Page 15: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

I2C Master Interrupts

When a transaction completes or when an error occurs during a transaction

To enable the I2C master interrupt, the IM bit in the I2C Master Interrupt Mask (I2CMIMR) register must be set

When an interrupt condition is met, software must check the ERROR bit in the I2C Master Control/Status (I2CMCS) register to verify that an error didn't occur

The interrupt is cleared by writing a 1 to the IC bit in the I2C Master Interrupt Clear (I2CMICR) register

If the application doesn't require the use of interrupts, the raw interrupt status is always visible via the I2C Master Raw Interrupt Status (I2CMRIS) register

Page 16: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

I2C Slave Interrupts

When data has been received or requested This interrupt is enabled by setting the DATAIM bit in the in the

I2C Slave Interrupt Mask (I2CSIMR) register Software determines whether the module should write

(transmit) or read (receive) data from the I2C Slave Data (I2CSDR) register, by checking the RREQ and TREQ bits of the I2C Slave Control/Status (I2CSCSR) register

The interrupt is cleared by setting the DATAIC bit in the I2C Slave Interrupt Clear (I2CSICR) register

In addition, the slave module can generate an interrupt when a start and stop condition is detected (STARTIM and STOPIM bits in I2CSIMR)

If the application doesn't require the use of interrupts, the raw interrupt status is always visible via the I2C Slave Raw Interrupt Status (I2CMRIS) register

Page 17: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Loopback Operation

The I2C modules can be placed into an internal loopback mode for diagnostic or debug work Set the LPBK bit in the I2C Master

Configuration (I2CMCR) register SDA and SCL signals from the master and slave

modules are tied together

Page 18: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

I2C Master Command Sequences

Page 19: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

I2C Master Command Sequences

Page 20: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

I2C Slave Command Sequences

Page 21: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Register Map

The I2C’s base address: I2C Master 0: 0x4002.0000 I2C Slave 0: 0x4002.0800 I2C Master 1: 0x4002.1000 I2C Slave 1: 0x4002.1800

Page 22: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

I2C Master Slave Address (I2CMSA), offset 0x000

Set the slave address of this master and define the transmission direction

Page 23: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

I2C Master Control/Status (I2CMCS), offset 0x004

When read, status register indicating the state of the I2C bus controller; when written, control register configuring the operation of the I2C bus controller

Page 24: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

I2C Master Control/Status (I2CMCS), offset 0x004

When read, status register indicating the state of the I2C bus controller; when written, control register configuring the operation of the I2C bus controller

Page 25: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

I2C Master Data (I2CMDR), offset 0x008

This register contains the data to be transmitted when in the Master Transmit state and the data received when in the Master Receive state

Page 26: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

I2C Master Configuration (I2CMCR), offset 0x020

configures the mode (Master or Slave) and sets the interface for test mode loopback

Page 27: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

I2C Slave Control/Status (I2CSCSR), offset 0x804

This register functions as a control register when written, and a status register when read.

Page 28: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

I2C Slave Control/Status (I2CSCSR), offset 0x804

This register functions as a control register when written, and a status register when read.

Page 29: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Initialization and Configuration

The following example shows how to configure the I2C module to transmit a single byte as a master: 1. Enable the I2C clock by writing a value of 0x00001000 to

the RCGC1 register in the System Control module 2. Enable the clock to the appropriate GPIO module via the

RCGC2 register in the System Control module 3. In the GPIO module, enable the appropriate pins for their

alternate function using the GPIOAFSEL register 4. Enable the I2C pins for Open Drain operation 5. Configure the PMCn fields in the GPIOPCTL register to

assign the I2C signals to the appropriate 6. Initialize the I2C Master by writing the I2CMCR register

with a value of 0x00000010

Page 30: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®
Page 31: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Initialization and Configuration

7. Set the desired SCL clock speed of 100 Kbps by writing the I2CMTPR register with the correct value:

(System Clock/(2*(SCL_LP + SCL_HP)*SCL_CLK))-1;= (20MHz/(2*(6+4)*100000))-1;= 9

8. Specify the slave address of the master and that the next operation is a Transmit by writing the I2CMSA register with a value of 0x00000076, which sets the slave address to 0x3B

9. Place data (byte) to be transmitted in the data register by writing the I2CMDR register with the desired data

10. Initiate a single byte transmit of the data from Master to Slave by writing the I2CMCS register with a value of 0x00000007 (STOP, START, RUN)

11. Wait until the transmission completes by polling the I2CMCS register’s BUSBSY bit until it has been cleared.

Page 32: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

PCA9557: REMOTE 8-BIT I2C AND SMBus LOW-POWER I/O EXPANDER

Page 33: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Reference

“REMOTE 8-BIT I2C AND SMBus LOW-POWER I/O EXPANDER WITH RESET AND CONFIGURATION REGISTERS”

Page 34: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Chip Description and Key Features

8-bit I/O expander for I2C bus I2C to parallel port expander 400-kHz fast I2C bus 3 hardware address pins allow for use of up to 8 devices on I2C Noise filter on SCL/SDA inputs

General-purpose remote I/O expansion for most microcontroller families

At power on, the I/Os are configured as inputs The I/Os can be programmed by I2C master to be as either

inputs or outputs Latched outputs with high current drive maximum capability for

directly driving LEDs Data for each input or output is kept in the corresponding input or

output register The polarity of the input port register can be inverted with the

polarity inversion register

Page 35: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Package & Pins

Top-side marking: PD557

Page 36: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Logic Diagram

Page 37: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

I2C Protocol Review

Two lines: the serial clock (SCL) and serial data (SDA) Connected to a positive supply through a pull-up resistor

Communication is initiated by a master sending a start condition A high-to-low transition on the SDA & the SCL input is high

After the start condition, the device address byte is sent Most-significant bit (MSB) first Followed by the data direction bit (R/W)

After receiving the valid address byte, the device having this address responds with an ACK A low on the SDA during the high of the ACK-related clock

pulse

Page 38: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

I2C Protocol Review Cont.

Data transfer begins Only one data bit is transferred during each clock pulse Any number of data bytes can be transferred from the

transmitter to the receiver Each byte of eight bits is followed by one ACK bit

The transmitter must release the SDA line The receiver must pull down the SDA line during the ACK clock

pulse

Master will stop the transmission by issuing a stop condition A low-to-high transition on the SDA & the SCL input is high

Page 39: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Device Address

The address of the PCA9557 is shown as follows

R/~W: a high (1) indicates a read operation, while a low (0) selects a write operation, from the perspective of the Master.

Page 40: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Control Register & Command Byte

After the successful ACK of the address type, the bus master sends a command byte that is stored in the control register in the PCA9557

Command bytes are used to specify the operation and the internal registers that will be affected

Page 41: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Input Port Register

Reflects the incoming logic levels of the pins All pins no matter whether a pin is an input or an

output The default value is determined by the externally

applied logic level

Page 42: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Output Port Register

Shows the outgoing logic levels of the pins defined as outputs Bit values in this register have no effect on pins defined as

inputs reads from this register reflect the value that is in the flip-

flop controlling the output selection, not the actual pin value

Page 43: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Polarity Inversion Register

Inverts the polarity of input pins If a bit in this register is set, the corresponding port pin's

polarity is inverted If a bit in this register is cleared, the corresponding port

pin's original polarity is retained

Page 44: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Configuration Register

Configures the directions of the I/O pins If a bit in this register is set to 1, the corresponding port pin

is enabled as an input If a bit in this register is cleared, the corresponding port pin

is enabled as an output

Page 45: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Write Operation

Page 46: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Write Operation

Page 47: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Read Operation

0 0

Page 48: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

I2C on S700

Page 49: The Cortex-M3 Embedded Systems: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I2C) Interface Refer to Chapter 15 in the reference book “Stellaris®

Digital LED Tubes on S700