AN SPI programming for Philips Bridge ICs. Document information

Similar documents
AVR151: Setup and Use of the SPI. Introduction. Features. Atmel AVR 8-bit Microcontroller APPLICATION NOTE

Implementing SPI Master and Slave Functionality Using the Z8 Encore! F083A

MFRD52x. Mifare Contactless Smart Card Reader Reference Design. Document information

AN LPC1700 timer triggered memory to GPIO data transfer. Document information. LPC1700, GPIO, DMA, Timer0, Sleep Mode

USER GUIDE EDBG. Description

Using the HT46R46 I/O Ports to Implement Half-Duplex SPI Communication

AVR1309: Using the XMEGA SPI. 8-bit Microcontrollers. Application Note. Features. 1 Introduction SCK MOSI MISO SS

UART IP Core Specification. Author: Jacob Gorban

Using Xbee in Serial Communication

AND8336. Design Examples of On Board Dual Supply Voltage Logic Translators. Prepared by: Jim Lepkowski ON Semiconductor.

Introduction the Serial Communications Huang Sections 9.2, 10.2 SCI Block User Guide SPI Block User Guide

Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

Implementing SPI Communication Between MSP430 G2452 and LTC ADC

AN Level shifting techniques in I 2 C-bus design. Document information

AVR317: Using the Master SPI Mode of the USART module. 8-bit Microcontrollers. Application Note. Features. Introduction

ES_LPC4357/53/37/33. Errata sheet LPC4357/53/37/33. Document information

Serial Communications

SC16IS740/750/760. Single UART with I 2 C-bus/SPI interface, 64 bytes of transmit and receive FIFOs, IrDA SIR built-in support

AN Boot mode jumper settings for LPC1800 and LPC4300. Document information

AN UART/SPI/I 2 C code examples. Document information. Abstract Simple code examples are provided for UART0, SPI and I 2 C.

Design and Implementation of Home Monitoring System Using RF Technology

AN LPC1700 RTC hardware auto calibration. Document information. RTC, Hardware Auto Calibration, LPC1700, Graphic LCD

AN10811 Programming SPI flash on EA3131 boards Rev May 2009 Application note Document information Info Content Keywords Abstract

Software User Guide UG-461

AVR319: Using the USI module for SPI communication. 8-bit Microcontrollers. Application Note. Features. Introduction

Using the RS232 serial evaluation boards on a USB port

Elettronica dei Sistemi Digitali Costantino Giaconia SERIAL I/O COMMON PROTOCOLS

AVR305: Half Duplex Compact Software UART. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

MIFARE ISO/IEC PICC

AN10866 LPC1700 secondary USB bootloader

GTS-4E Hardware User Manual. Version: V1.1.0 Date:

Using Altera MAX Series as Microcontroller I/O Expanders

SC16C754B. 1. General description. 2. Features. 5 V, 3.3 V and 2.5 V quad UART, 5 Mbit/s (max.) with 64-byte FIFOs

Objectives. Basics of Serial Communication. Simplex vs Duplex. CMPE328 Microprocessors (Spring ) Serial Interfacing. By Dr.

AT15007: Differences between ATmega328/P and ATmega328PB. Introduction. Features. Atmel AVR 8-bit Microcontrollers APPLICATION NOTE

SC16C652B. 1. General description. 2. Features. 5 V, 3.3 V and 2.5 V dual UART, 5 Mbit/s (max.) with 32-byte FIFOs and infrared (IrDA) encoder/decoder

Serial Communications

A DIY Hardware Packet Sniffer

AN11008 Flash based non-volatile storage

AN LPC24XX external memory bus example. Document information

RS-485 Protocol Manual

Data Sheet. Adaptive Design ltd. Arduino Dual L6470 Stepper Motor Shield V th November L6470 Stepper Motor Shield

ARM Thumb Microcontrollers. Application Note. Software ISO 7816 I/O Line Implementation. Features. Introduction

CP2110-EK CP2110 EVALUATION KIT USER S GUIDE. 1. Kit Contents. 2. Relevant Documentation. 3. Software Setup

Serial Communications (Chapter 10) RS232, SPI, I2C

DECT Module UM-9802 Datasheet

UM Discrete Class D High Power Audio Amplifier. Document information

PC Base Adapter Daughter Card UART GPIO. Figure 1. ToolStick Development Platform Block Diagram

Computer Organization and Components

SPI I2C LIN Ethernet. u Today: Wired embedded networks. u Next lecture: CAN bus u Then: wireless embedded network

Application Note 83 Fundamentals of RS 232 Serial Communications

IP4234CZ6. 1. Product profile. Single USB 2.0 ESD protection to IEC level General description. 1.2 Features. 1.

How To Add A Usb Secondary Ipo Bootloader To An Lpc23Xx Flash Device To A Flash Device

Pmod peripheral modules are powered by the host via the interface s power and ground pins.

In-System Programmer USER MANUAL RN-ISP-UM RN-WIFLYCR-UM

Raspberry Pi. Hans- Petter Halvorsen, M.Sc.

Software Real Time Clock Implementation on MC9S08LG32

SafeSPI - Serial Peripheral Interface for Automotive Safety

RN-131-PICTAIL & RN-171-PICTAIL Evaluation Boards

The Secrets of RS-485 Half-duplex Communication

AN1991. Audio decibel level detector with meter driver

MF1 IC S General description. Functional specification. 1.1 Contactless Energy and Data Transfer. 1.2 Anticollision. Energy

USB2.0 <=> I2C V4.4. Konverter Kabel und Box mit Galvanischetrennung

Programming Audio Applications in the i.mx21 MC9328MX21

AN10860_1. Contact information. NXP Semiconductors. LPC313x NAND flash data and bad block management

RC2200DK Demonstration Kit User Manual

PAC52XX Clock Control Firmware Design

Design and Verification of Nine port Network Router

SMARTCARD XPRO. Preface. SMART ARM-based Microcontrollers USER GUIDE

AN2680 Application note

ZL30136 GbE and Telecom Rate Network Interface Synchronizer

CAN bus board. EB018

AN2824 Application note

GSM Interfacing Board

How To Use A Watt Saver On A Microcontroller (Watt Saver) On A Cell Phone Or Mp3 Player

HEF4021B. 1. General description. 2. Features and benefits. 3. Ordering information. 8-bit static shift register

AN3265 Application note

Block 3 Size 0 KB 0 KB 16KB 32KB. Start Address N/A N/A F4000H F0000H. Start Address FA000H F8000H F8000H F8000H. Block 2 Size 8KB 16KB 16KB 16KB

Quad 2-input NAND Schmitt trigger

HEF4011B. 1. General description. 2. Features and benefits. 3. Ordering information. 4. Functional diagram. Quad 2-input NAND gate

UNIT 4 Software Development Flow

Microcomputer Protocol Implementation at Local Interconnect Network Georgi Krastev

Planar PIN diode in a SOD323 very small plastic SMD package.

QorIQ espi Controller Register Setting Considerations and Programming Examples

Manual Serial PCI Cards

AN141 SMBUS COMMUNICATION FOR SMALL FORM FACTOR DEVICE FAMILIES. 1. Introduction. 2. Overview of the SMBus Specification. 2.1.

3.2 inch QVGA TFT Color LCD User s Guide Version 1 & 2

AVR311: Using the TWI Module as I2C Slave. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

Freescale Semiconductor, Inc. Product Brief Integrated Portable System Processor DragonBall ΤΜ

Embedded Systems Design Course Applying the mbed microcontroller

TURBO PROGRAMMER USB, MMC, SIM DEVELOPMENT KIT

HANDLING SUSPEND MODE ON A USB MOUSE

LINDY ELECTRONICS LIMITED & LINDY-ELEKTRONIK GMBH - SECOND EDITION

The Programming Interface

AN3998 Application note

UART Boot Loader Design on the Kinetis E Series

ULC Technology: High-performance gate array package using multiple metal layer CMOS technology featuring sub-micron channel lengths (0.

Low-power configurable multiple function gate

10 ma LED driver in SOT457

74HC377; 74HCT General description. 2. Features and benefits. 3. Ordering information

Transcription:

Rev. 01 1 June 2006 Application note Document information Info Keywords Abstract Content P89LPC935 to SC16IS750, SPI to UART, SPI programming, microcontroller, embedded processor The programming of Philips Bridge ICs such as SC16IS750 through SPI-bus is discussed in this application note. In addition, the source code in C language, containing SPI communication routines between Philips P89LPC935 microcontroller and the SC16IS750 Bridge IC is provided and also discussed. This application note is also applicable to other Bridge ICs such as SC16IS740, SC16IS760, SC16IS752 and SC16IS762.

Revision history Rev Date Description 01 20060601 application note; initial version Contact information For additional information, please visit: http://www.semiconductors.philips.com For sales office addresses, please send an email to: sales.addresses@www.semiconductors.philips.com _1 Application note Rev. 01 1 June 2006 2 of 9

1. Introduction 2. Hardware connection The Philips Bridge ICs are a new generation of interface solutions for managing high-speed serial data communication among various bus interfaces such as SPI, I 2 C-bus, and UARTs including RS-232 and RS-485. The Bridge IC is commonly used to overcome the limitation of the host bus interface to peripherals and provides an easy method to interface with existing different serial bus interfaces. The description of the hardware connection and firmware programming are described in the next paragraphs for users to quickly understand the implementation of Philips P89LPC935 microcontroller with SPI-bus interface to Philips Bridge IC serial interface for RS-232 point-point communication, RS-485 multi-drop application, IrDA wireless links, and GPIO interface. The source code in C language is provided to show how to write a simple communication program between the microcontroller and the Bridge IC serial interface. The goal is to help users to design the Bridge IC in their application and also shorten their product development cycle. The block diagram depicted in Figure 1 shows the circuit connection of a Philips Bridge IC such as SC16IS750 interfacing with Philips P89LPC935 microcontroller through the SPI-bus. The Bridge IC offers simple, flexible, and minimal connection to the microcontroller. The Bridge IC allows the microcontroller to easily control with few wires connection through SPI-bus, which is a widely-used serial bus interface. When the I2C/SPI pin is at logic 0, the SPI-bus interface is selected and the Bridge IC can interface to the microcontroller with a 4-wire connection. The signals on the 4 wires are MISO (Master Input Slave Output), MOSI (Master Output Slave Input), CS (active LOW Chip Select), and SPICLK (SPI Clock). The SPI-bus is a 4-wire full-duplex synchronous serial data link. Devices connected to the SPI-bus are classified as master or slave devices. The master device initiates the data transfer on the SPI-bus and also controls the slave devices with the chip select pins. The slave devices are active only when selected. The interconnected devices share the same V CC and GND. After the microcontroller and Bridge IC are wired properly and their connection is established, the microcontroller can send data to, and receive data from, UART devices via the Bridge IC. The Bridge IC receives the SPI data from the microcontroller then sends the data to the following devices: serial devices via RS-232 or RS-485 such as a modem, wireless devices via IrDA such as a remote control, and general-purpose input/output devices such as an LED and keypad. When the Bridge IC receives the data from the devices, it will notify the microcontroller by generating an interrupt (IRQ) output signal, then the microcontroller can access the data from the Bridge IC via the SPI-bus interface. _1 Application note Rev. 01 1 June 2006 3 of 9

Philips microcontroller Philips Bridge ICs transceivers (optional) SPICLK TxD P89LPC935 MOSI SC16IS740 MISO SC16IS750 SC16IS760 CS SC16IS752 IRQ SC16IS762 I2C/SPI RxD RTS CTS RS-232 RS-485 002aac364 Fig 1. SPI interface to Philips Bridge IC block diagram 3. Firmware programming The firmware code for the P89LPC935 microcontroller is written in C language. It can be compiled by using an embedded C compiler. The firmware code consists of three major blocks, which are Main Loop program, Interrupt service routine, and Bus interface layer, as described in Section 3.1, Section 3.2 and Section 3.3. 3.1 Main Loop The Main Loop function is to program the microcontroller s SPI port as a master by initializing the SPI control register, interrupt handler, and chip select as shown in the following sample code: void mcu_spi_init (void) { // Set port 2.0 for MOSI, MISO, /SS and SPICLK P2M1 &= 0x42; P2M2 &= 0x42; SPCTL = 0x90; // Set LPC935 SPI port to Master SPCTL &= ~0x08; // CPOL=0; SCK is low when idle SPI mode 0 SPCTL &= ~0x04; // CPHA=0; shift triggered on leading edge of clock SPCTL = 0x11; // 00=clk/4, 01=clk/16, 10=clk/64, 11=clk/128 SPI_SS = 0; // Enable slave chip select for SC16IS7x0 SPI_SS = 1; // Disable slave chip select for SC16IS7x0 // Set SPI interrupt priority to 0 IP1 &= ~0x08; IP1H &= ~0x08; ESPI = 1; SPCTL = 0xC0; // SPI Interrupt // Enable SPI, ignore SS _1 Application note Rev. 01 1 June 2006 4 of 9

The next step is to initialize the Bridge IC by writing its internal control registers to program, for example, UART baud rate, data line, and FIFO for transmitter and receiver. void init_sc16is750 (void) { SPI_write (LCR, 0x80); SPI_write (DLL, 0x30); SPI_write (DLM, 0x00); SPI_write (LCR, 0xBF); SPI_write (EFR, 0X10); SPI_write (LCR, 0x03); SPI_write (FCR, 0x06); SPI_write (FCR, 0x01); // 0x80 to program baud rate // 0x30=19.2K, 0x08 =115.2K with X1=14.7456 MHz // divisor = 0x0008 for 115200 bps // access EFR register // enable enhanced registers // 8 data bit, 1 stop bit, no parity // reset TXFIFO, reset RXFIFO, non FIFO mode // enable FIFO mode Inside the Main Loop, the microcontroller can use one of the two methods for communicating to the Bridge IC. The first method is polling the status register of the Bridge IC regularly. It keeps checking the event flags such as data available in receiver, and passes to the appropriate subroutine for further processing. void spi_polling (void) { char data, polling=1; while (polling) { if (SPI_read (LSR) && 0x01)) { // data in receiver data = SPI_read (RHR); if (data == 27) polling = 0; // receive ESC char to exit from polling mode The second method is using an interrupt handler in the Interrupt Service Routine until the Bridge IC generates an interrupt output (IRQ) signal. If using the interrupt handler, the microcontroller and the bus interrupt bits must be enabled and the IRQ pin of the Bridge IC must be connected to an external interrupt pin of the microcontroller (for example, the INT1 pin of the P89LPC935). 3.2 Interrupt Service Routine (ISR) The microcontroller uses the Interrupt Service Routine to handle an interrupt generated by the Bridge IC. As soon as the Bridge IC generates an interrupt output (IRQ) signal, the ISR checks the interrupt status of the Bridge IC to determine the interrupt type and sets up proper event flags to inform the Main Loop routine for processing the interrupt request. void mcu_interrupt1(void) interrupt 2 { // external interrupt 1 char data; switch (SPI_read (IIR) & 0x0f) { // check interrupt status register case 0x06: // receiver line status (LSR) if (SPI_read(LSR) && 0x01) // data in receiver data = SPI_read(RHR); break; case 0x0C: // receiver time-out interrupt case 0x04: // receive hold register (RHR) interrupt data = SPI_read (RHR); break; _1 Application note Rev. 01 1 June 2006 5 of 9

case 0x02: default: // transmit hold register (THR) interrupt SPI_write(THR, data); break; 3.3 Bus interface layer The Bus Interface layer handles the SPI-bus interface between the microcontroller and the Bridge IC for transmitting and receiving the SPI data. The three functions in the bus interface layer are: SPI_send The microcontroller transmits data to the SPI-bus and waits until the end of SPI data transmission. SPI_read The Bridge IC receives the data from peripherals, then the microcontroller retrieves the data from the Bridge IC vial SPI-bus and stores the data for further processing. SPI_write The microcontroller writes data to the Bridge IC via SPI-bus, then the Bridge IC will transmit the data to peripherals. char SPI_send (char byte) { SPDAT = byte; while(!spi_tx_completed); SPSTAT &= ~0x80; SPI_tx_completed = 0; return SPDAT; // mcu sends a byte to spi bus // data is sent // wait end of transmission // clear mcu spi interrupt flag (SPIF) // clear transmit spi interrupt flag // receive data on spi read char SPI_read (char register) { // mcu reads a register from SC16IS750 SPI_SS = 0; // enable slave chip select SPI_send((register<<3) 0x80); // register address is sent register = SPI_send(0); // dummy data is sent for spi read SPI_SS = 1; // disable slave chip select return register; // receive the read data void SPI_write (char address, char data) { // mcu writes data to SC16IS750 SPI_SS = 0; // enable slave chip select SPI_send (address<<3); // address is sent SPI_send (data); // data is sent SPI_SS = 1; // disable slave chip select _1 Application note Rev. 01 1 June 2006 6 of 9

4. Conclusion 5. Abbreviations Philips Bridge IC provides easy interface to a host controller such as Philips P89LPC935 microcontroller and enables seamless high-speed SPI to RS-232 or RS-485 protocols convergence including GPIO for general-purpose input/output and IrDA for wireless links. Also, the Bridge IC offers low voltage operation, low power consumption, and compact design, which is suitable for battery-operated applications. In addition, the Bridge IC reduces software overhead, frees up the host controller s resources, increases design flexibility, and improves overall system performance. For more details about Philips Bridge ICs, please visit the Philips Semiconductors web site to download the data sheets. Table 1. Acronym SPI UART IrDA IC GPIO LED FIFO Abbreviations Description Serial Peripheral Interface Universal Asynchronous Receiver/Transmitter Infrared Data Association Integrated Circuit General Purpose Input/Output Light Emitting Diode First In, First Out _1 Application note Rev. 01 1 June 2006 7 of 9

6. Legal information 6.1 Definitions Draft The document is a draft version only. The content is still under internal review and subject to formal approval, which may result in modifications or additions. Philips Semiconductors does not give any representations or warranties as to the accuracy or completeness of information included herein and shall have no liability for the consequences of use of such information. 6.2 Disclaimers General Information in this document is believed to be accurate and reliable. However, Philips Semiconductors does not give any representations or warranties, expressed or implied, as to the accuracy or completeness of such information and shall have no liability for the consequences of use of such information. Right to make changes Philips Semiconductors reserves the right to make changes to information published in this document, including without limitation specifications and product descriptions, at any time and without notice. This document supersedes and replaces all information supplied prior to the publication hereof. Suitability for use Philips Semiconductors products are not designed, authorized or warranted to be suitable for use in medical, military, aircraft, space or life support equipment, nor in applications where failure or malfunction of a Philips Semiconductors product can reasonably be expected to result in personal injury, death or severe property or environmental damage. Philips Semiconductors accepts no liability for inclusion and/or use of Philips Semiconductors products in such equipment or applications and therefore such inclusion and/or use is for the customer s own risk. Applications Applications that are described herein for any of these products are for illustrative purposes only. Philips Semiconductors makes no representation or warranty that such applications will be suitable for the specified use without further testing or modification. 6.3 Trademarks Notice: All referenced brands, product names, service names and trademarks are the property of their respective owners. I 2 C-bus logo is a trademark of Koninklijke Philips Electronics N.V. _1 Application note Rev. 01 1 June 2006 8 of 9

7. Contents 1 Introduction............................ 3 2 Hardware connection.................... 3 3 Firmware programming................... 4 3.1 Main Loop............................. 4 3.2 Interrupt Service Routine (ISR)............. 5 3.3 Bus interface layer...................... 6 4 Conclusion............................. 7 5 Abbreviations........................... 7 6 Legal information........................ 8 6.1 Definitions............................. 8 6.2 Disclaimers............................ 8 6.3 Trademarks............................ 8 7 Contents............................... 9 Please be aware that important notices concerning this document and the product(s) described herein, have been included in section Legal information. For more information, please visit: http://www.semiconductors.philips.com. For sales office addresses, email to: sales.addresses@www.semiconductors.philips.com. Date of release: 1 June 2006 Document identifier: _1