You are on page 1of 12

EC3462

EMBEDDED
SYSTEMS
ENGINEERING
LECTURE 10 –
SERIAL
C O M M U N I C AT I O N
WITH MSP430FR5739
– I2C

Nushara Wedasingha
Mphil(AI) Candidate, Bsc.(Hons) EEE
Department of Electrical and Electronic
Engineering
Faculty of Engineering
Sri Lanka Institute of Information Technology
WHAT IS I2C?

• It is known as the Inter Intergrated Circuit.


• It uses a single clock signal provided by the master to comminicate with
each other.
• It is a serial communication protocol.
• It was found in 1982 by Philips.
• The cost is really low.
• It takes only 2 pins.
• It is used in IOT, Automotive, and Industrial Applications.
I2C SPEED CATEGORIES
Speed Category Clock Frequency Bus Direction
Standard Mode Up to 100 KHz Bi-Directional
Fast Mode Up to 400 KHz Bi-Directional
Fast Mode Pluse Up to 1 MHz Bi-Directional
High Speed Mode Up to 3.4 MHz Bi-Directional
Ultra Fast Mode Up to 5 MHz Uni-Directional
I2C WAVE FORM
Start Slave Address R/W ACK Data NACK Stop

6 5 4 3 2 1 0 7 6 5 4 3 2 1 0

Address Byte Data Byte


Partition Number of Bits Operation
Start 1 Start I2C Communication
Slave Address 7 Address of the Slave
R/W 1 0 – Read , 1 - Write
ACK/NCK 1 0 – Acknowledge
1 - Do not Acknowledge
Data 8 Data sent to receivved
Stop 1 Stop I2C Communication
M S P 4 3 0 S E R I A L C O M M U N I C AT I O N A R C H I T E C T U R E
MSP430 PINOUT
MSP430 REGISTERS INVOLVED WITH I2C

Register Purpose of the Register


UCB0CTL0 Controling Register
UCB0CTL1 Controling Register
UCB0R0 Setting the Baud Rate
UCBR0RXBUF Receiving Buffer
UCBR0TXBUF Transmitting Buffer
UCB0I2COA Getting the Own Address
UCB0I2CSA Getting the Slave Address
UCB0TBCNT Length of the data sent through I2C
UCB0IE Enabling Interrupts
UCB0CTL0 REGISTER

Name of the Internal No. of Bits Allocated for Operation of the Register
Register the Register
UCA10 1 0 – Own address length is 7 bits
1 – Own address length is 10 bits
UCSLA10 1 0 – Slave address length is 7 bits
1 – Slave address length is 10 bits
UCMM 1 0 – Single Master, 1– Multiple Masters
Unused 1 Unused
UCMST 1 0 – Selecting Slave, 1 – Selecting Master
UCMODEx 2 00 – 3 Pin SPI
01 – 4 Pin SPI (Master/Slave enable if STE =1)
01 – 4 Pin SPI (Master/Slave enable if STE =0)
11 – I2C
UCSYNC 1 0 – Asynchronus, 1- Synchronus
UCB0CTL1 REGISTER

Name of the Internal No. of Bits Allocated for Operation of the Register
Register the Register
UCSSELx 2 00 – UCLK1
01 – ACLK
10 – SMCLK
11 – SMCLK
Unused 1 Unused
UCTR 1 0 – Reveiver, 1– Transmitter
UCTXNACK 1 0 – Acknowledge, 1– Not Acknowledge
UCTXSTP 1 0 – Stop is disabled, 1 – Stop is enabled
UCTXSTT 1 0 – Diable Start, 1 – Enable Start
UCSWRST 1 0 – Disable Reset, 1- Enable Reset (Operation
State)
SETTING UP MASTER MODE IN MSP430

UCB0CTL1 |= UCSWRST; // put eUSCI_B in reset state


UCB0CTLW0 |= UCMODE_3 + UCMST; // I2C master mode
UCB0BRW = 0x0008; // baudrate = SMCLK / 8
UCB0CTLW1 = UCASTP_2; // autom. STOP assertion
UCB0TBCNT = 0x07; // TX 7 bytes of data
UCB0I2CSA = 0x0012; // address slave is 12hex
P2SEL |= 0x03; // configure I2C pins (device specific)
UCB0CTL1 &= ^UCSWRST; // eUSCI_B in operational state
UCB0IE |= UCTXIE; // enable TX-interrupt
GIE; // general interrupt enable
...
// inside the eUSCI_B TX interrupt service routine
UCB0TXBUF = 0x77; // fill TX buffer
SETTING UP SLAVE MODE IN MSP430
UCB0CTL1 |= UCSWRST; // eUSCI_B in reset state
UCB0CTLW0 |= UCMODE_3; // I2C slave mode
UCB0I2COA0 = 0x0012; // own address is 12hex
P2SEL |= 0x03; // configure I2C pins (device specific)
UCB0CTL1 &= ^UCSWRST; // eUSCI_B in operational state
UCB0IE |= UCTXIE + UCRXIE; // enable TX&RX-interrupt
GIE; // general interrupt enable
...
// inside the eUSCI_B TX interrupt service routine
UCB0TXBUF = 0x77; // send 077h
...
// inside the eUSCI_B RX interrupt service routine
data = UCB0RXBUF; // data is the internal variable
THANK YOU
!

You might also like