06 - NuMicro I2C
06 - NuMicro I2C
06 - NuMicro I2C
I2C
NuMicro@nuvoton.com
1
Agenda
General Description
Features
Protocol
Register Description
Application
2
General Description
3
Features (1/2)
4
Features (2/2)
5
I2C Protocol
Normally, a standard communication consists of 4 stages:
START or Repeated START signal generation
Slave address transfer
Data transfer
STOP signal generation
SCL 1 2 7 8 9 1 2 3-7 8 9
P
NACK
SDA A6 A5 A4 - A1 A0 R/W ACK D7 D6 D5 - D1 D0
ACK
S P Sr
MSB LSB MSB LSB
or or
Sr Sr
6
START, Repeated START and STOP
When the bus is free, I2C Hardware can initiate a transfer by sending a
START signal.
The master can use a Repeated START to continue a next transmission
without releasing the bus.
The master can terminate the communication by generating a STOP
signal.
SCL 1 2 7 8 9 1 2 3-7 8 9
P
NACK
SDA A6 A5 A4 - A1 A0 R/W ACK D7 D6 D5 - D1 D0
ACK
S P Sr
MSB LSB MSB LSB
or or
Sr Sr
7
Slave Address Transfer
The first byte transferred by the master after the START signal is the
slave address.
This is a 7-bit slave address followed by a R/W bit.
No two slaves have the same address.
SCL 1 2 7 8 9 1 2 3-7 8 9
P
NACK
SDA A6 A5 A4 - A1 A0 R/W ACK D7 D6 D5 - D1 D0
ACK
S P Sr
MSB LSB MSB LSB
or or
Sr Sr
8
Data Transfer
When successful slave addressing has been achieved, the data transfer
can proceed on byte-by-byte basis in the direction specified by the R/W
bit.
The data length is based on actual application.
SCL 1 2 7 8 9 1 2 3-7 8 9
P
NACK
SDA A6 A5 A4 - A1 A0 R/W ACK D7 D6 D5 - D1 D0
ACK
S P Sr
MSB LSB MSB LSB
or or
Sr Sr
9
Acknowledge
Acknowledge
Position clock pulse for
acknowledgement
SCL FROM
MASTER
1 2 8 9
DATA OUTPUT BY
TRANSMITTER
NACK: High level
not acknowledge
DATA OUTPUT BY
RECEIVER
S
START acknowledge
condition
ACK: Low level
10
Register Description
I2C has 7 function registers:
I2CON (I2C Control Register)
I2DAT (I2C Data Register)
I2STATUS (I2C Status Register)
I2CLK (I2C Clock Rate Register)
I2ADDRx, x=0~3 (I2C Address Register)
I2ADRMx, x=0~3 (I2C Address Mask Register)
I2TOC (I2C Time-out Counter Register)
11
I2C Control Register
7 6 5 4 3 2 1 0
EI ENSI STA STO SI AA Reserved Reserved
DATA1
[0,0,1,0] [0,0,1,0]
[1,0,0,x] [0,0,1,0] [0,1,1,0]
13
I2C Status Register
26 possible status codes.
All I2C status codes correspond to defined I2C states.
Ex: When a START has been transmitted, the status code is 08H.
14
Application
15
Application
Flash
I2C0SCL I2C_CLK
Cortex-M0 I2C I2C_DATA 24LC64
I2C0SDA
NUC1XX
16
I2C Sample Code (1/6)
/*----------------------------------------------------------------------------
MAIN function
----------------------------------------------------------------------------*/
int32_t main (void)
{
uint32_t Temp_Value;
uint32_t u32HCLK;
17
I2C Sample Code (2/6)
18
I2C Sample Code (3/6)
void Write_24LC64(uint32_t address, uint8_t data)
{
/* send i2c start */
DrvI2C_Ctrl(I2C_PORT0, 1, 0, 0, 0); //set start
while (I2C0->CON.SI == 0); //poll si flag
19
I2C Sample Code (4/6)
/* send low byte of address */
I2C0->DATA = address&0XFF;
DrvI2C_Ctrl(I2C_PORT0, 0, 0, 1, 0); //clr si
while( I2C0->CON.SI == 0 ); //poll si flag
20
I2C Sample Code (5/6)
uint8_t Read_24LC64(uint32_t address)
{
uint8_t flash_data;
22
I2C – EEPROM (24LC64)
I2C
GPA10 SDA
GPA11 SCL
NUC140V3AN
I2C-EEPROM
(24LC64)
23
Run “Smpl_24LC64” Code
Customer_CD Readme.txt
NUC1xx BSP
NUC1xx_BSP Driver Reference Guide
NuvotonPlatform_Keil
Sample
NUC1xx-LB_002
24
Q&A
Thank You
25