Philips AN10369 Application Note

Uart/spi/i2c code examples

Advertisement

Quick Links

AN10369
2
UART/SPI/I
C code examples
Rev. 01 — 06 April 2005
Document information
Info
Content
Keywords
UART, SPI, I
Abstract
Simple code examples are provided for UART0, SPI and I
2
C
Application note
2
C.

Advertisement

Table of Contents
loading

Summary of Contents for Philips AN10369

  • Page 1 AN10369 UART/SPI/I C code examples Rev. 01 — 06 April 2005 Application note Document information Info Content Keywords UART, SPI, I Abstract Simple code examples are provided for UART0, SPI and I...
  • Page 2 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 © Koninklijke Philips Electronics N.V. 2005. All rights reserved. Application note Rev. 01 — 06 April 2005 2 of 17...
  • Page 3: Introduction

    Suite) v1.2 compiler. Though the below code samples have been successfully tested on the LPC2106 it should work fine on rest of the Philips LPC2000 family devices after some minor modifications. Minor modifications could be setting the Stack pointer correctly (depending upon the SRAM present on chip), using the correct header files etc.
  • Page 4: C Code

    PINSEL0=0x5; /* Enable FIFO's and reset them */ U0FCR=0x7; /* Set DLAB and word length set to 8bits */ U0LCR=0x83; © Koninklijke Philips Electronics N.V. 2005. All rights reserved. Application note Rev. 01 — 06 April 2005 4 of 17...
  • Page 5: Terminal Program Settings

    Fig 1. Tera Term serial port settings 2.4 Output The output of the above code should be similar to the screen shown in Fig 2. © Koninklijke Philips Electronics N.V. 2005. All rights reserved. Application note Rev. 01 — 06 April 2005...
  • Page 6: Spi

    /* Include header file depending upon part used */ #include"LPC2….h" void Initialize(void); /* Macro Definitions */ #define SPIF (1<<7) #define DATA 0xC1 /************************* MAIN *************************/ int main() © Koninklijke Philips Electronics N.V. 2005. All rights reserved. Application note Rev. 01 — 06 April 2005 6 of 17...
  • Page 7: Output

    /* Set to highest speed for SPI at 10 MHz- > 1.25 MHz */ SPCCR=0x8; /* Device selected as master */ SPCR=0x20; /*********************************************************/ 3.3 Output Waveforms from Oscilloscope are shown in Fig 3. © Koninklijke Philips Electronics N.V. 2005. All rights reserved. Application note Rev. 01 — 06 April 2005 7 of 17...
  • Page 8: Calculation Of Bit Frequency

    I C has been classified as an IRQ interrupt. LPC2106 is being used as a Master Transmitter and a Philips port expander PCF8574 is used as a slave device. Waveforms are shown to help the user to understand the communication better.
  • Page 9: Setting Of The Slave Address

    Fig 4. State diagram code flow 4.4 Code The files used here are as follows: 1. Interrupt Vector table © Koninklijke Philips Electronics N.V. 2005. All rights reserved. Application note Rev. 01 — 06 April 2005 9 of 17...
  • Page 10: Interrupt Vector Table

    ; The following dummy handlers do not do anything useful in ; this example. They are set up here for completeness. Undefined_Handler Undefined_Handler SWI_Handler SWI_Handler Prefetch_Handler Prefetch_Handler Abort_Handler Abort_Handler © Koninklijke Philips Electronics N.V. 2005. All rights reserved. Application note Rev. 01 — 06 April 2005 10 of 17...
  • Page 11: C Code

    MSR cpsr_c, R0 ; Jump to C code LDR lr, =__main MOV pc, lr 4.4.2 C code #include"LPC210x.h" void Initialize(void); © Koninklijke Philips Electronics N.V. 2005. All rights reserved. Application note Rev. 01 — 06 April 2005 11 of 17...
  • Page 12 VICCNTL0= 0x29; /* highest priority and enabled */ VICVADDR0=(unsigned long) I2C_ISR; /* ISR address written to the respective address register*/ © Koninklijke Philips Electronics N.V. 2005. All rights reserved. Application note Rev. 01 — 06 April 2005 12 of 17...
  • Page 13 /* Slave address + write */ I2DAT=0x74; /* Clear SI and Start flag */ I2CONCLR=0x28; /* Port Indicator */ IOSET=0x10; © Koninklijke Philips Electronics N.V. 2005. All rights reserved. Application note Rev. 01 — 06 April 2005 13 of 17...
  • Page 14: Linking Notes For I C Code

    C ISR located in the C file. 4.5 Output waveforms In the output waveform the following are shown • Start condition • Stop condition © Koninklijke Philips Electronics N.V. 2005. All rights reserved. Application note Rev. 01 — 06 April 2005 14 of 17...
  • Page 15 (i.e. while(1) loop in C main()) is interrupted and IRQ interrupts are serviced. Channel D1 and channel D0 indicate SDA and SCLK respectively. Fig 5. Waveforms © Koninklijke Philips Electronics N.V. 2005. All rights reserved. Application note Rev. 01 — 06 April 2005...
  • Page 16: Disclaimers

    Application information — Applications that are described herein for any of at their own risk and agree to fully indemnify Philips Semiconductors for any these products are for illustrative purposes only. Philips Semiconductors damages resulting from such application.
  • Page 17: Table Of Contents

    Output waveforms..........14 Disclaimers ............16 Contents.............17 © Koninklijke Philips Electronics N.V. 2005 All rights are reserved. Reproduction in whole or in part is prohibited without the prior written consent of the copyright owner. The information presented in this document does not form part of any quotation or contract, is believed to be accurate and reliable and may be changed without notice.

Table of Contents