마이크로칩 8월
This page was machine-translated and may differ from the original. View original

[MCU Q&A] 2. How do I connect EEPROM to MCU?

Google 우선 소스Published2016.01.25 15:19
< MCU Q&A ②. Microcontrollers (MCUs) are core components that are used in a variety of applications, from rice cookers in our daily lives to cutting-edge automobiles. So how much do we know about MCUs? Do we choose products based only on the basic specifications that fit the system we want to use? Or do we wonder how to connect EEPROM to MCU, what the difference is between MCU and DSP, and what the criteria are for selecting MCU peripherals? e4ds News will serialize MCU Q&A over four parts. I hope that the information you were curious about or overlooked will help you choose a product.


Masaru Sugai
STMicroelectronics (www.st.com)


1. What criteria should I use when choosing an MCU?
2nd: How do I connect EEPROM to MCU?
3: What is the difference between MCU and DSP?
Part 4: MCU Peripheral Components Selection Guide Power


< Q UESTION>

I want to connect an Electrically Erasable Programmable Read-Only Memory (EEPROM) to my MCU for use as external memory. I've heard there are many ways to connect it. Could you explain the different options?

< E XPLANATION>

For EEPROM, there are several different data access methods available, including Serial Peripheral Interface (SPI), Inter-Integrated Circuit (I2C), Microwire, and 1-Wire. Since many MCUs include SPI and I2C as peripheral functions, these two methods are mainly used. As an example, let's look at how to connect an EEPROM manufactured by STMicroelectronics (ST) to an STM8L series MCU. The I2C bus has only two bidirectional NMOS open-drain signal lines with pull-up resistors. Figure 1(a) shows an MCU connected to an M24xxx series EEPROM that uses I2C as its bus standard.

There are four types of SPI signal lines: SCK, MISO, MOSI, and SS. Figure 1(b) shows an example of an MCU connected to an M95xxx series EEPROM. Since the terminal names are different from the SPI signal names, the signal lines are indicated by the SPI signal names.


Figure 1. Connecting EEPROM to MCU

The MCU hardware performs basic communication control for both the I2C bus and the SPI bus, but additional software is required. The operation of the control software varies depending on the type of MCU used, so refer to the relevant user manual for details.

Interfacing the MCU and EEPROM

EEPROM data access methods can be divided into two types: serial bus method and parallel bus method. Since the parallel bus method requires the use of a large number of signal lines - for example, 8 bits for data signals and several bits (depending on the memory size) for address signals - the serial bus method is most commonly used. Common serial bus standards include SPI, I2C, Microwire, and 1-Wire. Most modern MCUs include SPI and I2C as peripheral functions, and one of them is mainly used as an interface for the MCU.

Address data and operation codes (op-codes) are exchanged through device-to-device communication. The op-codes are different for each EEPROM and include Write Enable/Disable, Register Read/Write, and Data Read/Write. These signals are controlled using MCU software.

I2C

I2C is a serial bus that supports a communications protocol developed by Philips. Each node is assigned a 7-bit address. Addresses for 16 nodes are reserved, but the rest (theoretically up to 112) can be connected to a single bus.


Figure 2. I2C module of STM8L series MCU

The I2C communication protocol basically follows the protocol used by Philips, but each MCU uses the protocol in a slightly different way. To understand this protocol more clearly, let's look at the I2C function of the STM8L series MCU as an example (Figure 2).

First, let's look at the communication flow (Figure 2(a)). The master device generates a clock signal (SCL), and when the start condition occurs, data transmission begins, and then when the stop condition occurs, data transmission ends.

The software installed on the master device generates both the start condition and the stop condition. When the MCU accesses the EEPROM, the MCU is the master device. It can recognize its own address and the universal call address in slave mode. Data and address are transmitted in 8-bit data units (1 byte) with the MSB first. The first byte transmitted after the start condition occurs contains the address. The address is always transmitted from the master device. After the byte consisting of 8 clock cycles is transmitted, the ninth clock pulse is generated. During this interval, the receiver must transmit an acknowledgment bit (ACK) to the transmitter.


Figure 3. I2C communication protocol of STM8L series MCU

Next, let’s look at Figure 2(b). The figure shows the I2C module structure inside the MCU. Here, SDA is the data signal and SCL is the clock. The module contains a data shift register that shifts data bit by bit for output or input. The user can access the transmitted/received data through the data register. The module also has a built-in comparator that checks the address and PEC values. “PEC” stands for “Packet Error Check.” This is additional information used to check whether the data has been transmitted normally.

The communication speed is determined by the SCL frequency, which is 100 kbps in standard mode. However, STM8L provides a Fast Mode that can achieve a communication speed of 400 kbps.

Software is required to control the transmission sequence. The STM8L comes with a user manual with a sequence diagram as shown in Figure 3. By generating software that follows these sequences, we can perform communication operations.

Following the I2C procedure, you can communicate the address, data, and op-code (Write Enable/Disable, Register Read/Write, Data Read/Write) specified for each EEPROM.

SPI

SPI is a communication standard proposed by Motorola (now Freescale Semiconductor, Inc.). The physical function of SPI is the same as clock-synchronous serial communication. SPI uses four types of communication signals: clock (SCLK), master output/slave input (MOSI), master input/slave output (MISO), and slave select (SS). SCK is a synchronous clock that is output from the master device, MOSI and MISO are data signals synchronized to SCK, and SS is a slave recognition signal. When the master device outputs a low signal, the slave receives SS as an input, and if the state is low, the slave acknowledges the selection. This signal is similar to the chip select (CS).

The SPI communication protocol basically follows the protocol used by Motorola, but each MCU uses the protocol in a slightly different way. To understand the SPI function more clearly, let's take a look at the STM8L series MCU again (Figure 4).


Figure 4. SPI module for STM8L series MCUs

As shown in Figure 4(a), the timing of data latching with respect to the clock phase can be determined by two parameters: clock polarity (CPOL) and clock phase (CPHA). The STM8L includes a built-in data shift register that shifts data bit by bit for output or input. Transmitted data is stored in the Tx buffer, and received data is stored in the Rx buffer. The CPU accesses the transmitted and received data through the Rx and Tx buffers.

The data transfer rate is determined by the SCK frequency. Since the STM8L has a built-in baud rate generator, this frequency can be set to any desired value. The maximum rate for the STM8L is 8MHz, but the specifications vary depending on the MCU used, so refer to the data sheet provided with the MCU in question.

Unlike I2C, SPI communication is basically the same as clock-synchronous serial communication, so SPI does not require the user to control the transmission sequence. One byte is transmitted at a rate of one bit per clock cycle.

You can communicate the address, data, and op-code (Write Enable/Disable, Register Read/Write, Data Read/Write) specified for each EEPROM in the same manner as synchronous serial communication.

Reference information

For a practical way to connect an EEPROM to an MCU, see:

(1) M24LR-Discovery: EEPROM (M24LR) and MCU (STM8L) are mounted on a 4.5cm × 9.0cm PCB. This board can perform communication operations between EEPROM and MCU via I2C. Circuit diagrams and information about this software are available for free download at:
http://www.st.com/web/en/catalog/tools/FM116/SC1444/PF253360?sc=m24lr04e-discovery

(2) Application Note AN2014: This document describes how to connect ST EEPROM to a standard MCU. You can also find detailed instructions for connecting using I2C, SPI, and Microwire. The PDF file can be downloaded for free from the following site:
http://www.st.com/web/en/resource/technical/document/application_note/CD00042024.pdf
본 기사에 대한 정정·반론·추후보도 청구는 보도 청구 안내를, 그간 게재된 보도문은 정정·반론보도 모아보기를 참고해 주세요.
명세환 기자
명세환 기자