Global Sources
EE Times-India
Stay in touch with EE Times India
 
EE Times-India > Processors/DSPs
 
 
Processors/DSPs  

STR71x BSPI used as an UART

Posted: 08 Dec 2004     Print Version  Bookmark and Share

Keywords:embedded 

PDF document

AN1800/0904 1/7

Rev. 2.0

AN1800

APPLICATION NOTE

STR71x BSPI

USED AS AN UART

INTRODUCTION

This document presents a standard communication interface between a STR71x microcon-

troller and a PC. This communication is done through the STR71x BSPI peripheral and a serial

port of the PC using the RS232 protocol.

1

2/7

STR71x BSPI USED AS AN UART

1 BSPI COMMUNICATION

The main features of the BSPI communication peripheral are summarized below. Refer to the

STR71x datasheet for more details.

1.1 MAIN FEATURES

The Buffered Serial Peripheral Interface (BSPI) offers a flexible means of full-duplex data ex-

change with external equipment requiring an industry standard synchronous serial data

format.

The BSPI allows a very wide range of baud rates with different baud rates for transmission and

reception.

For BSPI, only four signals are needed, the first for transmission (MOSI), the second for re-

ception (MISO), the third is the clock and the other is slave select (SS).

1.2 BAUD RATES

Transmission and reception can be driven by their own baud rate generator. However be

aware that to communicate correctly, the receiver must have a reception baud rate strictly

equal to the transmission baud rate of the transmitter. As long as this condition is met, a wide

range of baud rates is possible.

1.3 FRAMES

The length of a data word can be 8 or 16 bits, these bits are transmitted Most Significant Bit

first.Data and Clock signals

2

3/7

STR71x BSPI USED AS AN UART

2 RS232 COMMUNICATION WITH A PC

2.1 MAIN FEATURES

The electrical and protocol characteristics of RS232 are different from those of the STR71X

BSPI peripheral. In RS232 communication, high level is typically +7V and low level is typically

-7V, while the BSPI peripheral works with (0, +3.3V).

Furthermore, the polarities are different. A '1' bit coming from the BSPI corresponds to a '0' bit

in RS232, and a '0' bit to a '1' bit. So it is necessary to implement a conversion between the PC

and the BSPI peripheral. In this application a MAX232 is used for this purpose.

Also the BSPI transmits Most Significant Bit first but the PC receives the Least Significant Bit

first. That's why we must invert the order before transmitting the data.

2.2 PC CONFIGURATION

The PC will be used as a terminal. The description below refers to the Windows environment.

This terminal application is called hyperterminal.

Under Windows, open the +hyperterminal; application. To configure it, go to the communica-

tion parameters menu. The options of this window must be the same as the ones defined with

your STR71x.

After selecting the right serial communication port, select the same baud rate as the one con-

figured in the microcontroller. As the PC accepts only one baud rate, transmission and recep-

tion baud rates will have the same value. Data word length will be 7 bits, and choose to use 1

stop bits. +Flow control; can be either Xon/Xoff or none. The PC is then correctly configured.

4/7

STR71x BSPI USED AS AN UART

3 STR71X CONFIGURATION

This application was implemented with a STR71X. This microcontroller uses a 16 MHz ex-

ternal clock (quartz). A description of the baud rate selection is given later in this application

note.

3.1 GENERAL INITIALIZATION

Four pins of the STR71x are used:

the MOSI pin (Master Output Slave Input).

the MISO pin (Master Input, Slave Output).

the CLK clock pin.

the SS slave select pin.

The MOSI, MISO and CLK pins must be initialized as Push-Pull (please refer to the Reference

Manual).

3.2 BSPI CONFIGURATION

The peripheral is configured as a master by using function BSPI_MasterEnable, and the Baud

Rate is fixed by using function BSPI_ClockDividerConfig (please refer to the Reference

Manual for more information).

3.2.1 EXAMPLE

Then the baud rates must be selected. We should always have the same baud rates in the PC

and in the BSPI.

Baud Rate Clock Divider

19200 0xCF

38400 0x67

57600 0x40

115200 0x20

5/7

STR71x BSPI USED AS AN UART

4 COMMUNICATION BETWEEN STR71x AND PC VIA RS232

The software for this application is the BSPI driver. The complete software can be found in the

the ST internet website. It is of course only an example. It is up to you to adapt it to your spe-

cific application.

4.1 GENERAL DESCRIPTION

In this application, an STR71x is connected to a PC. The communication is performed using

the +hyperterminal; application of Windows. Characters are sent by the STR71x in ASCII

code to the PC with a baudrate set to 19200 bps (ClockDivider = 0xCF) and 1 stop bit.

The first part of the program performs the initialization of the STR71x, core and the BSPI pe-

ripheral.

4.2 HARDWARE

The STR71x BSPI peripheral cannot be directly connected to a PC, as it uses the RS232 pro-

tocol.

The conversion between BSPI and RS232 can be done using a MAX232. An overview sche-

matic is presented in the figure below:

Figure 1. Hardware Overview

Be sure that the three main devices (PC, STR71x, MAX232) have the same electrical refer-

ence (GND).

The Receive Data pin (RD) of the serial port of the PC must correspond to the MOSI pin of the

MISO pin.

GND

TD

RD

GND

IN

OUT

MISO

MOSI

GND

IN

OUT

MAX232

STR71x

VCC SS

RS232 interface

6/7

STR71x BSPI USED AS AN UART

4.3 SOFTWARE

Figure 2. Application flowchart

Configure the BSPI pin to Push-Pull

Initialize BSPI peripheral

Configure the clock divider

Enable the BSPI peripheral

BSPI_Init (BSPI1) ;

{

...

GPIO_Config (GPIO0, 0x0077, GPIO_AF_PP);

Select BSPI master mode

Configure the clock

Enable capturing the first data sample on the

first edge of SCK or the second edge

Set the word length

END

BSPI_ClkActiveHigh(BSPI1, DISABLE);

BSPI_8bLEn(BSPI1, ENABLE);

BSPI_WordSend(BSPI1, 0x41);

BSPI_ClockDividerConfig (BSPI1, 0xCF);

BSPI_MasterEnable (BSPI1, ENABLE);

BSPI_Enable (BSPI1 , ENABLE);

BSPI_ClkFEdge(BSPI1, ENABLE);

...

}

Send word (invert the order before the trans-

mission of the data)

BEGIN

7/7

STR71x BSPI USED AS AN UART

"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 express written approval of STMicroelectronics.

The ST logo is a registered trademark of STMicroelectronics.

All other names are the property of their respective owners

) 2004 STMicroelectronics - All rights reserved

STMicroelectronics group of companies

Australia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan -

Malaysia - Malta - Morocco - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America

www.st.com





Comment on "STR71x BSPI used as an UART"
Comments:  
*  You can enter [0] more charecters.
*Verify code:
 
 
Webinars

Seminars

Visit Asia Webinars to learn about the latest in technology and get practical design tips.

 

Go to top             Connect on Facebook      Follow us on Twitter      Follow us on Orkut

 
Back to Top