microprocessors b (17.384) spring 2012 lecture...

93
1 Microprocessors B (17.384) Spring 2012 Lecture Outline Class # 06 February 28, 2012 Dohn Bowden

Upload: others

Post on 25-Apr-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

1

Microprocessors B (17.384)

Spring 2012

Lecture Outline

Class # 06

February 28, 2012

Dohn Bowden

Page 2: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

2

Today’s Lecture

• Administrative

• Microcontroller Hardware and/or Interface

• Programming/Software

• Lab

• Homework

Page 3: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

3

Course Admin

Page 4: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

4

Administrative

• Admin for tonight …

– Syllabus Highlights

• Exam #1 NEXT WEEK … March 6th

• Finish Lab #2 this week … and … start Lab #3

– Lab #2 is due in three weeks … Tuesday (March 20th)

• Spring Break in two weeks … March 13th … NO CLASS

• In three weeks … March 20th … NO lecture … Lab only – Attendance is required

Page 5: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

5

Syllabus ReviewWeek Date Topics Lab Lab Report Due

1 01/24/12 PIC pin out, C programming, Watchdog Timer, Sleep

2 01/31/12 General-purpose IO, LED/switch IO, FSM 1

3 02/07/12 Lab 1 con’t

4 02/14/12 Interrupts, Timers, interrupt-driven IO 2

5 02/21/12 Lab 2 con’t 1

6 02/28/12 Asynchronous/Synchronous Serial IO (UART, I2C, SPI) 3

7 03/06/12 Examination 1

X 03/13/12 No Class – Spring Break

8 03/20/12 Lab 3 con’t 2

9 03/27/12 Pulse Width Modulation and DC motor control 4

10 04/03/12 Lab 4 con’t 3

11 04/10/12 Advanced Hardware Topics Project

12 04/17/12 Examination 2

13 04/24/12 Work on Course Project Project 4

14 05/01/12 Final Exam/Course Project Brief and Demonstration Demo

Page 6: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

6

MicrocontrollerHardwareand / or

Interfaces

Page 7: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

7

Input / Output …

Page 8: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

Input / Output Review

• Thus far we have looked at parallel input/output

– Data sent over a group of parallel wires

– Typically … a clock is used for synchronization

• Next ... We shall look at serial input/output

– Data sent one bit at a time … over a single wire

– A clock may or may not be used for synchronization

8

Page 9: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

Parallel and Serial Input / Output

• Parallel …

• Serial …

9

Page 10: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

10

Page 11: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

Baud Rate vs Bits Per Second

• Baud rate is the rate at which signaling events are sent

– Bits per second (bps) is …

• The number of bits transferred per second …

– any type of bits … data … or … overhead bits

11

Page 12: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

Baud Rate vs Bits Per Second

• If only a ‘1’ or ‘0’ is sent for each signaling event … then …

– baud rate = bps

• A signaling protocol that transfers multiple bits per signaling event … i.e. …

– use 4 different voltage levels, send two bits of data per signaling event (00 = -15v, 01= -5v, 10=+5v, 11 = 5v)

• In this case … bit rate will be double the baud rate

• The effective data rate is the rate at which data is transferred … minus the overhead bits (ie ... start and stop bits)

12

Page 13: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

13

Serial Buses …

Page 14: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

Serial Buses

• Serial buses can be either …

– Asynchronous … or … synchronous

• Asynchronous serial connection …

• Data is sent without using a common timing clock signal

• Synchronous serial connection …

• Typically uses a separate clock signal to synchronize the receiver with the sender

14

Page 15: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

Asynchronous Serial Connection

• To align the receiver with the sender …

– There is some sort of start condition …

• To signify when the transmission begins … and …

– A stop condition …

• To indicate the end of transmission

15

Page 16: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

Synchronous Serial Connection

• A synchronous serial connection typically uses a separate clock signal to synchronize the receiver with the sender

• Synchronous connections may also use a start and stop condition to synchronize the receiver and sender …

– After which the sender must send characters one right after the other

16

Page 17: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

Types of Serial Connections

• Full-Duplex …

– A serial interface that can send and receive data at the same time

• Half-Duplex …

– A serial interface that must alternate between sending and receiving data

• Simplex …

– Communication in one direction only

17

Page 18: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

Types of Serial Connections

18

Page 19: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

19

PIC24 Serial On-Chip Peripherals …

Page 20: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

PIC24 Serial On-Chip Peripherals

• UART …

– Universal Asynchronous Receiver Transmitter

– Pronounced … “you-art”

• RS-232 Standard

– Requires a driver to convert between RS-232 logic levels and CMOS logic levels

20

Page 21: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

PIC24 Serial On-Chip Peripherals

• SPI …

– Serial Peripheral Interface

– Pronounced … “spy”

• I2C Bus …

– Inter-Integrated Circuit

– Pronounced … “eye squared see”

21

Page 22: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

22

UART …

Page 23: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

UART

• UART … Universal Asynchronous Receiver Transmitter

• Hardware module that implements asynchronous serial IO

• Referred to as UARTx …

– As there may be multiple UART modules on one PIC24 μC

• Frees the processor from having to implement software delay loops …

– Receive/transmit done by UART while processor can do other tasks

23

Page 24: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

UART

• Will always use 8-bit no parity for PIC24 asynchronous serial IO

24

Page 25: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

25

RS-232 …

Page 26: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

RS-232

• RS-232 … Recommended Standard 232

– The traditional name for a series of standards for …

• Serial binary single-ended data … and… control signals connecting between …

– a DTE … Data Terminal Equipment … and …

– DCE … Data Circuit-terminating Equipment

• Commonly used in computer serial ports

26

Page 27: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

PIC24 μC to PC Serial Input / Output Connection

27

Page 28: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

RS-232

• An interface standard originally used to connect PCs to modems

• The standard defines voltage levels … cable length … connector pinouts … etc

• There are other signals in the standard beside TX … RX … Gnd

• The other signals are used for modem control (Data Carrier Detect, Ring Indicator, etc) and flow control (flow control signals are used to determine if a device is ready to accept data or not)

• We will not cover the other signals in the RS232 standard

28

Page 29: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

29

SPI …

Page 30: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

SPI

• Another serial bus that is commonly used in embedded systems is the …

– Motorola serial peripheral interface … SPI

30

Page 31: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

SPI

• SPI can operate at data rates up to 1 Mbps

• It can operate in full-duplex mode

– Making it better suited than I2C for applications where data is constantly flowing

31

Page 32: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

SPI

• I2C …

– Uses fewer signals than SPI

– Can communicate over several feet … a meter or more … and …

– Has a well defined specification

32

Page 33: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

SPI

• SPI …

– Has a limited communication length of a few inches

– SPI does not support multiple masters …or … specify a device addressing scheme …

• Therefore … additional hardware signals are needed in order to select specific slaves

– This lack of addressing can be a benefit because it reduces the overhead in single-master … single-slave SPI interfaces

33

Page 34: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

SPI

34

Page 35: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

SPI

• The SPI port requires …

– A minimum of three wires … and … usually 4 … and …

– Is technically duplex … even though most transfers are half-duplex

• Its top speed on the PIC24 μC is 10 MHz

• Best for high-speed serial transfer

• Very simple

35

Page 36: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

SPI and the I2C Comparison

• In contrast to the SPI … the I2C port requires …

– Only two wires regardless of the number of peripherals

– Is half-duplex

• Recall … half-duplex is a serial interface that must alternate between sending and receiving data

– Top speed is 1 MHz

• Best if you are trying to reduce external pin usage

36

Page 37: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

SPI / PIC24 Connections

37

Page 38: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

38

I2C Serial Bus …

Page 39: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

I2C Serial Bus

• I2C ... Inter-Integrated Circuit …

– Pronounced “eye squared see”

• Provides a means of exchanging data between …

– Peripheral devices … and … Microcontrollers …

• Using software addressing

• Only two signals are required …

– Data … Clock39

Page 40: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

I2C Serial Bus

40

Page 41: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

I2C Serial Bus

• I2C

– Does not require much in the way of hardware resources

– Ideal for …

• Low speed

• Short distance communications

41

Page 42: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

I2C Serial Bus

• Created by Philips

• Capable of addressing multiple devices on the same bus …

– Up to 127 devices in Standard-mode

– 1024 in extended mode

42

Page 43: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

I2C Serial Bus

• Various maximum data rates are supported by different revisions to the I2C specification

• These data rates are …

– Up to 100 Kbps for Standard-mode– 400 Kbps for Fast-mode … and …– 3.4 Mbps for High-speed mode

• Devices of different data rates can be mixed on the same bus

43

Page 44: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

I2C Serial Bus

• The I2C specification can be found online at ...

– http://www.semiconductors.philips.com

• More specifically … (also on the course web page)

• http://ics.nxp.com/support/documents/interface/pdf/i2c.bus.specification.pdf

44

Page 45: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

I2C Serial Bus

• Some devices that typically contain I2C bus interfaces are …

– EEPROMs … and …

– Real-time clock chips

45

Page 46: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

I2C Serial Bus

• The two I2C bus signals are …

– Serial data (SDA) … and …

– Serial clock (SCL)

• The master on the bus initiates all transfers …

– Other devices on the bus are called slaves

46

Page 47: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

I2C Serial Bus

• On the next slide …

– The microprocessor is the master … and …

– The other devices are the slaves

• Both master and slaves can receive and transmit data on the bus

• The master …

– Initiates transactions on the bus and controls the clock signal

47

Page 48: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

I2C Serial Bus

48

Page 49: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

I2C Serial Bus

• Below is the format of an I2C bus transaction

• All data on the bus is communicated most significant bit first (MSB)

49

Page 50: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

I2C Serial Bus

50

Page 51: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

I2C Communications

1. Master initiates a start condition

2. Master sends the 7-bit unique address of the device

3. Master outputs the read or write bit

4. Slave sends an acknowledge bit

5. Byte of data is exchanged followed by an acknowledgement• Continues until all data is sent

6. Transaction ends with the master device causing a stop condition

51

Page 52: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

I2C Bus Signaling

52

Page 53: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

I2C Communications

1. Master initiates a start condition

– An I2C bus data transaction begins by the master initiating a start condition

– A start condition occurs when the master causes a high-to-low transition on the data line while the clock line is held high

53

Page 54: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

I2C Communications

2. Master sends the 7-bit unique address of the device

– 7-bit unique address of the device is sent out by the master device

– Each device on the bus checks this address with its own to determine whether the master is communicating with it

– I2C slave devices come with a predefined device address

• The lower bits of this address are sometimes configurable in hardware

54

Page 55: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

I2C Communications

3. Master outputs the read or write bit

– The master outputs the read or write bit

• If the bit is high … the transaction is a read …

– Where data goes from the slave to the master device

• If the bit is low … the transaction is a write …

– From the master to the slave device

55

Page 56: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

I2C Communications

4. Slave sends an acknowledge bit

– For the acknowledge bit …

• The data line is kept low while the clock signal is high

• Acknowledge bits always are sent by the slave device

56

Page 57: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

I2C Communications

5. Byte of data is exchanged followed by an acknowledgement

– Depending on the type of transaction … read … or … write

• The transmitter … which can be slave or master … begins sending a byte of data … starting with the MSB

• At the end of the data byte … the receiver … either slave or master … issues an acknowledge bit

– This pattern is continued until all of the data has been transferred

57

<Unknown User>
Pencil
Page 58: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

I2C Communications

6. Transaction ends with the master device causing a stop condition

– A stop condition occurs when the master causes a low-to-high transition on the data line while holding the clock line high

• Note that the I2C protocol supports multiple masters

58

Page 59: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

EEPROM Interface

• We shall look into using the I2C bus to communicate with a serial EEPROM

• The EEPROM is the 24LC515

59

Page 60: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

EEPROM - 24LC515

• Is a 64K x 8 (512K bit) Serial Electrically Erasable PROM …

• capable of operation across a broad voltage range (1.8V to 5.5V)

• Has both byte write and page write capability of up to 64 bytes of data

• Capable of both random and sequential reads

• Reads may be sequential within address boundaries …

– 0000h to 7FFFh … and … & 8000h to FFFFh

60

Page 61: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

EEPROM - 24LC515

• Functional address lines allow up to four devices on the same data bus

– This allows for up to 2 Mbits total system EEPROM memory

61

Page 62: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

EEPROM - 24LC515

62

Page 63: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

63

Page 64: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

64

Page 65: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

65

Page 66: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

66

A Great Reference …

Page 67: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

Reference

• On the class webpage … there is a link to the following …

• Microchip Technology Presentation on using the MSSP module in Master I2C mode (similar to what we are using) ...

67

Page 68: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

68

Programming/Software

Page 69: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

Baud Rate Register

• FCY = 7.37 MHz (internal clock speed)• FSCL = I2C Clock Speed = 100kHz• 12C1BRG = Baud Rate Register

12C1BRG = (FCY/(4*FSCL)) – 1

For an I2C Clock Speed of 100kHz …

12C1BRG = (7.37MHz)/(4*100kHz)) – 1

= (7,370,000)/(4*100,000)) – 1 = 17 decimal

69

<Unknown User>
Pencil
Page 70: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

Error Noted

• It has been observed that following a Power-on Reset …

– I2C mode may not initialize properly by just configuring the SCL and SDA pins as either inputs or outputs

70

Page 71: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

Error Noted

• Work around …

– Before configuring the module for I2C operation …

• Configure the SCL and SDA pins as outputs by clearing their corresponding TRIS bits

• Force SCL and SDA low by clearing the corresponding LAT bits

• While keeping the LAT bits clear … configure SCL and SDA as inputs by setting their TRIS bits

– Once this is done … use the SSPCON1 and SSPCON2 registers to configure the proper I2C mode as before

71

Page 72: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

Programming/Software

• I2C basic routines

72

Page 73: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

void wait_For_Idle()

void wait_For_Idle(){

while(I2C1CON & 0x1F); // Acknowledge sequence not in progress// Receive sequence not in progress// Stop condition not in progress// Repeated Start condition not in progress// Start condition not in progress

while(I2C1STATbits.TRSTAT); // Bit = 0 … Master transmit is not in progress}

73

Page 74: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

void start()

void start(){

wait_For_Idle();I2C1CONbits.SEN = 1; //Initiate Start conditionwhile(I2C1CONbits.SEN); // Hardware clear at end of master Start sequence

// 0 = Start condition not in progress}

74

Page 75: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

void stop()

void stop(){

wait_For_Idle();I2C1CONbits.PEN = 1; //Initiate Stop condition on SDAx and SCLx pins

// Hardware clear at end of master Stop sequence

while(I2C1CONbits.PEN); // bit = 0 --- Stop condition not in progress

}

75

Page 76: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

void restart()

void restart(){

wait_For_Idle();I2C1CONbits.RSEN = 1; // Initiate Repeated Start condition on SDAx and SCLx pins

// Hardware clear at end of master Repeated Start sequence

while(I2C1CONbits.RSEN); // bit = 0 --- Repeated Start condition not in progress

}

76

Page 77: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

void ack()

void ack(){

wait_For_Idle();I2C1CONbits.ACKDT = 0; // 0 = Send ACK during AcknowledgeI2C1CONbits.ACKEN = 1; // 1 = Initiate Acknowledge sequence on SDAx and SCLx pins and

// transmit ACKDT data bit// Hardware clear at end of master Acknowledge sequence

while(I2C1CONbits.ACKEN); // bit = 0 --- Acknowledge sequence not in progress

}

77

Page 78: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

void nack()

void nack() // Acknowledge Data bit{

wait_For_Idle();I2C1CONbits.ACKDT = 1; // 1 = Send NACK during AcknowledgeI2C1CONbits.ACKEN = 1; // 1 = Initiate Acknowledge sequence on SDAx and SCLx pins and

// transmit ACKDT data bit// Hardware clear at end of master Acknowledge sequence

while(I2C1CONbits.ACKEN); // bit = 0 --- Acknowledge sequence not in progress

}

78

Page 79: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

void init_I2C()

void init_I2C(){

I2C1BRG = 0x128; // Baud Rate GeneratorI2C1CONbits.I2CEN = 0; // 0 = Disables the I2Cx module. All I2C pins are controlled by

// port functionsI2C1CONbits.DISSLW = 0; // 0 = Slew rate control enabled

}

79

<Unknown User>
Pencil
Page 80: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

IdleI2C()

void IdleI2C(){

while (I2C1STATbits.TRSTAT); //Wait for bus Idle}

80

Page 81: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

81

Lab

Page 82: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

82

Peer Review of Software …

Page 83: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

Peer Review of Software Developed

• How did you write your code?

• What problems did you encountered?

• Any questions that you need resolved?

83

Page 84: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

84

Lab #3 …

Page 85: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

Lab #3

• I2C interface with a serial EEPROM

– Will write data to the EEPROM

– Then read data from the EEPROM

• Display the data on a Bar Graph display

– Could add a LCD display to perform the same function

85

Page 86: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

86

Next Class

Page 87: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

87

Next Class Topics

• Exam #1

– Up to … but … not including today’s material

• In two weeks … March 13th … No class – Spring break

• In three weeks … March 20th … continue with Lab #3

Page 88: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

88

Homework

Page 89: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

Homework

• Study for Exam #1 … next week … March 6th

• Labs …– Code development for Lab #3– Lab #2 Report … due March 20th

89

Page 90: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

90

Time to start the lab …

Page 91: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

Lab

• Continue Lab #2, if needed

• Start Lab #3

91

Page 92: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

92

References

Page 93: Microprocessors B (17.384) Spring 2012 Lecture Outlinefaculty.uml.edu/dbowden/ClassPages/2012_Spring_CSO... · 2. Master sends the 7-bit unique address of the device 3. Master outputs

93

References

1. None