AN970 STMICROELECTRONICS | Alldatasheet

Document overview

  • Manufacturer or author: Provided By ALLDATASHEET.COM(FREE DATASHEET DOWNLOAD SITE)
  • PDF pages: 10

Technical content

SPI COMMUNICATION BETWEEN ST7 AND EEPROM by 8-Bit Micro Application Team INTRODUCTION The goal of this application note is to present a practical example of communication using the SPI peripheral of the ST7. It shows an easy way of communicating between a ST7 microcontroller and a M95xxx SPI EEPROM. The purpose is to perform, through SPI, a write in the memory, followed by a read of the written data.

1 ST7 / EEPROM SPI INTERFACE

the ST7 datasheet for more details. which devices may be either master or slave. There is only one master at any one time.

  • The MOSI (Master Out Slave In).
  • The MISO (Master In Slave Out).

each device. this can be done in hardware or software mode. EEPROM mode through an output. The ST7 and SPI interface set-up is shown Figure 1. data transfer during a sequence of eight clock pulses. Figure 1. ST7 and SPI Interface Set-Up

SPI COMMUNICATION BETWEEN ST7 AND EEPROM

2 ST72264 CONFIGURATION

2.1 I/O CONTROL

Four pins of the ST72264 are used: - The 3 data and clock SPI pins (SCK, MOSI, MISO). - An output pin to select and deselect the M95xxx. - SS pin to select master or slave mode. In our application, the output for selecting the M95xxx is pin 3 of Port B. It is configured as output push-pull (refer to the datasheet for details).

2.2 SPI PERIPHERAL

2.2.1 General

This peripheral is configured with the SPI Control Register. The output must be enabled (SPE = 1). If the SS pin is high (see SPICSR), the ST72264 can be declared as master by setting the MSTR bit. The transmission speed, in master mode, is selected using the SPR0, SPR1 and SPR2 bits. The CPOL and CPHA bits define the timing characteristics. When the SPIE bit is set, SPI interrupts are enabled (not used in our case). 2.2.2 SS software configuration The SS pin can be fixed by hardware, either connected to Vss (for a slave configuration) or to Vdd (for a master configuration). But it can also be software driven through the SPICSR reg- ister (SSM and SSI bits) : To set the master configuration (as in our case) : SSM=1 and SSI=1 To set the slave configuration: SSM=1 and SSI=0 SPIE SPE SPR2 MSTR CPOL CPHA SPR1 SPR0 SPIF WCOL OVR MODF - SOD SSM SSI

SPI COMMUNICATION BETWEEN ST7 AND EEPROM

2.2.3 Baud rates

First the communication speed must be chosen. As the clock is given by the master, the user has to configure the baud rate of the ST7 SPI (SPR[2-0] bits in the SPICR register). For each CPU frequency, six Baud Rates are available. If fCPU = 8MHz, the baud rate range is 62.5kHz to 2MHz.

2.2.4 Clock phase and polarity

Then the clock polarity and the clock phase have to be chosen. The clock polarity (CPOL bit of the SPCR register) controls the steady state value of the clock when no data is being transferred. The clock phase (CPHA bit of the SPCR register) selects on which clock transition the bit cap- ture is made and consequently on which clock transition data is latched. The user must be careful of the fact that some devices do not allow all timing relationships. For instance, the ST95040 EEPROM device accepts only CPOL,CPHA = (0,0) or (1,1) configura- tions.

3 M95040 EEPROM MANAGEMENT AND CONFIGURATION

3.1 MAIN FEATURES

This is a 4K memory composed of two pages of 2K bytes. All instructions, addresses and data are shifted in and out of the chip MSB first.

3.2 STATUS REGISTER

This device has one status register. this application, both bits are cleared, allowing write access to all the memory. The WEL bit indicates the status of the write enable latch. The WIP bit indicates whether the memory is busy with a write operation.

3.3 INSTRUCTION SET

Table 1. Instruction Set Notes: A8 = 1, Upper page selected. A8 = 0, Lower page selected.

SPI COMMUNICATION BETWEEN ST7 AND EEPROM

4 ST7 / EEPROM SPI PROTOCOL

The use of the main functions are briefly described below. For a complete description of the protocol, please refer to the M95040 SPI EEPROM data sheet. Write_enable: The memory contains a write enable latch. This latch must be set prior to any WRITE or WRSR operation. Byte_write: This function will write up to 16 bytes of data in the EEPROM. After the WRITE in- struction, the memory address must be specified before sending data. Byte_read: This function reads the memory. After the READ instruction, the memory address is specified. To be able to send the data, the EEPROM must receive the clock from the master: the ST7. This is made by sending a dummy byte. This operation will generate the 8 clock bits needed. The dummy value will not be seen by the EEPROM. Write_SR: Give the proper value to the Status Register prior to any communication. Read_SR: This process is similar to the byte read process. It will be used to check if there is a write in progress (WIP bit of the status register).

5 SPI COMMUNICATION BETWEEN AN ST7 AND AN EEPROM

The software included with this application note is only the SPI driver. The complete software can be found in the software library in the ST internet website. It is of course only an example. It is up to the user to adapt it to his specific application.

5.1 GENERAL DESCRIPTION

The software is a polling SPI communication between the ST72264 and EEPROM. The first part of the software performs to the initialization of the ST72264 (core and SPI periph- eral) and of the EEPROM (value of status register for no protection). Then it executes the write cycles. The «write_loop» writes in the EEPROM (16 bytes at a time for optimization), the values 0 to 111 from the address 0 up to 111. The third part executes the read cycles. The «read_loop» reads the content of the EEPROM at a time from address 0 up to 111. Finally, the software ends in an infinite loop.

5.2 HARDWARE DESCRIPTION

Figure 2. Hardware description pin of ST72264 is software driven (high state for a master device). The SCK pin is connected to the serial clock pin (C) of the E²PROMs. The MOSI pin to the serial input pins (D). The MISO pin to the serial output pins (Q). pin of the EEPROM is connected to the PB3 output pin of ST72264.

5.3 FLOWCHARTS

The flowchart of the application is presented below (Figure 3).

1 VCC

Figure 3. Flowchart: MAIN

5.4 USE OF SEVERAL EEPROMS

same protocol as described before is followed. The main point is to reserve one I/O pin to select each device. A hardware schematic using two devices is given below (Figure 4). The selection of the devices is made using the PB2 and PB3 pins. Figure 4. Hardware schematic for two devices

5.5 SOFTWARE

All the source files in assembly code are given in the zip file with this application note.

SPI COMMUNICATION BETWEEN ST7 AND EEPROM “THE PRESENT NOTE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT OF SUCH A NOTE AND/OR THE USE MADE BY CUSTOMERS OF THE INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.” Information furnished is believed to be accurate and reliable. However, STMicroelectronics assumes no responsibility for the consequences of use of such information nor for any infringement of patents or other rights of third parties which may result from its use. No license is granted by implication or otherwise under any patent or patent rights of STMicroelectronics. Specifications mentioned in this publication are subject to change without notice. This publication supersedes and replaces all information previously supplied. STMicroelectronics products are not authorized for use as critical components in life support devices or systems without the express written approval of STMicroelectronics. The ST logo is a registered trademark of STMicroelectronics  2002 STMicroelectronics - All Rights Reserved. Purchase of I2C Components by STMicroelectronics conveys a license under the Philips I2C Patent. Rights to use these components in an I2C system is granted provided that the system conforms to the I2C Standard Specification as defined by Philips. STMicroelectronics Group of Companies Australia - Brazil - Canada - China - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan Malaysia - Malta - Morocco - Singapore - Spain - Sweden - Switzerland - United Kingdom - U.S.A. http://www.st.com