Home

AN10369 UART/SPI/I2C code examples

image

Contents

1. 4 of 17 Philips Semiconductors AN1 0369 Philips ARM LPC microcontroller family Baud rate set to 9600 UODLL 0x10 UODLM 0x0 Clear DLAB UOLCR 0x3 IRI C RIOR ICICI TOR TCR IO I RIK eK 2 3 Terminal Program settings This code was tested on Tera Term Pro v2 3 and the settings for the serial port are shown below x Tera Term Serial port setup J Port CA Baud rate 3600 Data abit gt Cancel Parity none gt Stop ibt x Help Flow control none gt Transmit delay fo msecjchar o msecjline 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 5 of 17 Philips ARM LPC microcontroller family Philips Semiconductors AN1 0369 A W Tera Term COM2 T E oix File Edit Setup Control Window Help Fig 2 Code output 3 SPI The following code sample configures the SPI as a master and transmits data bytes on the MOSI pin Output waveforms are captured on the oscilloscope and shown below Since no slave device is physically connected to the master SSEL should be driven high does not apply to the LPC213x family MISO is not being used in this example Also the VPB clock is set to system clock 10MHz and SPI is run at maximum
2. 6 evaluation board which uses a 10 MHz crystal system clock The on chip PLL has not been used for the sample code examples given below If the user uses the code for a different crystal setting then be sure to set the baud rate speed of the peripheral accordingly before running the example code Speed calculations equations are provided for each peripheral All the code samples are configured to run from SRAM and they were compiled using the ADS ARM Development 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 If the end user wishes to run the code from the on chip Flash then a signature is to be placed at 0x14 and the code has to be linked differently in addition to other changes 2 1 The below code sample configures UARTO to interface to a Terminal program running on a host machine maybe Tera Term Or HyperTerminal at a baud rate of 9600 The code simply prints Philips LPC on the host machine terminal program forever since it is included in a while 1 loop VPB Divider value is at its reset settings and hence the peripheral clock is one fourth of the system clock The VPB clock would then be 2 5MHz Steps on calculating the divisor value are shown be
3. AN10369 UART SPI I C code examples Semiconductors Rev 01 06 April 2005 Application note a Document information Info Content Keywords UART SPI 1 C Abstract Simple code examples are provided for UARTO SPI and C PHILIPS AN10369 Philips ARM LPC microcontroller family Philips Semiconductors Revision history 01 20050406 Initial version Contact information For additional information please visit http Awww 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 Philips Semiconductors AN10369 Philips ARM LPC microcontroller family 1 Introduction 2 UARTO This application note provides code samples which will enable the user to get a jump start into using some of the serial communication interfaces of the LPC2000 family In this application note code samples are provided for UARTO SPI and I C bus For detailed description on the peripheral please refer to the User manual of the respective device The basic startup assembly code is only shown for the I C bus peripheral For UARTO and SPI the basic startup code should setup the stack pointer for the Supervisor mode which could be done using the LDR Load Register instruction LDR SP 0x4 The code was tested on a LPC210
4. e 8 4 2 Setting of the slave address 9 4 3 State Diagram with regard to C states 9 4 4 Solo e ia si ca chad A 4 4 1 Interrupt Vector table 4 4 2 C COQ ieai eea alive Haste tise 4 4 3 Linking notes for KORS CA 14 4 5 Output waveformS eneen 14 5 Disclaimers sssssneeneeneeennnrennnrnnnnnnnnnnrnnnnrnnnnnn nn 16 6 CONteNtS ee 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 No liability will be accepted by the publisher for any PHILIPS consequence of its use Publication thereof does not convey nor imply any license under patent or other industrial or intellectual property rights Date of release 06 April 2005 Published in The Netherlands
5. following are shown e Start condition e Stop condition Koninklijke Philips Electronics N V 2005 All rights reserved Application note Rev 01 06 April 2005 14 of 17 Philips ARM LPC microcontroller family Philips Semiconductors AN1 0369 E e Slave address e Data byte In the code three port indicators were used which are shown in the waveforms below For instance consider IC state 8H void ISR 8 Port Indicator IOCLR 0x10 IOSET 0x10 The results of the two statements are shown in the oscilloscope as channel D3 labeled S_8 Similarly D4 indicates state 18H and D5 indicates state 28H Channel D2 shows all the instances when the IRQ interrupt is triggered and normal program flow i e while 1 loop in C main is interrupted and IRQ interrupts are serviced Channel D1 and channel DO indicate SDA and SCLK respectively T a Fig 5 Waveforms Koninklijke Philips Electronics N V 2005 All rights reserved Application note Rev 01 06 April 2005 15 of 17 Philips Semiconductors AN10369 5 Disclaimers Life support These products are not designed for use in life support appliances devices or systems where malfunction of these products can reasonably be expected to result in personal injury Philips Semiconductors customers using or selling these products for use in such applications do so at their own risk and agree to fully indemnify Philips Semiconduc
6. low Calculating Baud rate Baud rate is calculated using the following formula Required baud rate VPB clock 16 Divisor value 9600 2 5MHz 16 x x 16 2 0x10 after discarding the decimal part Koninklijke Philips Electronics N V 2005 All rights reserved Application note Rev 01 06 April 2005 3 of 17 Philips Semiconductors AN1 0369 2 2 Philips ARM LPC microcontroller family This value needs to be entered into the UODLL register as shown below C Code Include header file depending upon device been used finclude LPC2 h void Initialize void Macro Definitions define TEMT 1 lt lt 6 define LINE FEED OxA define CARRIAGE RET 0xD ROR RK KK MAIN FORO RO RK RK KK int main int i char c Philips LPC Initialize Print forever while 1 i 0 Keep Transmitting until Null character 0 is reached while c i UOTHR c i itt UOTHR LINE FEED UOTHR CARRAIGE RET Wait till UOTHR and UOTSR are both empty while U0LSR amp TEMT KEK RRR RRR KERR KK System Initialization FOI RK EK void Initialize Initialize Pin Select Block for Tx and Rx PINSELO 0x5 Enable FIFO s and reset them UOFCR 0x7 Set DLAB and word length set to 8bits UOLCR 0x83 Koninklijke Philips Electronics N V 2005 All rights reserved Application note Rev 01 06 April 2005
7. ndler B Prefetch Handler Abort Handler B Abort Handler Koninklijke Philips Electronics N V 2005 All rights reserved Application note Rev 01 06 April 2005 10 of 17 Philips Semiconductors AN1 0369 Philips ARM LPC microcontroller family FIQ Handler B FIQ Handler END AREA asm code CODE New Code section CODE32 ARM code IMPORT main main not defined in this section EXPORT start global symbol referenced in ivt s Enable interrupts MSR cpsr_c 0x13 Set SP for Supervisor mode Depending upon the available memory the application needs to set the SP accordingly LDR SP 0x4 Setting up SP for IRQ mode Change mode to IRQ before setting SP irg and then switch back to Supervisor mode RS RO CPSR BIC R1 RO 0x1F ORR R1 R1 0x12 SR cpsr_c Rl LDR SP 0x4 SR cpsr_c RO Jump to C code LDR lr main OV pc Ir END 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 AN10369 Philips ARM LPC microcontroller family Philips Semiconductors 1 ISR __irg void 1 C _ISR void Master Transmitter states void ISR 8 void void ISR 18 void void ISR 28 void FOI RK KK MAIN FOIA KK int main Initialize system Initialize Send start bit 1 C ONSET 0x60 D
8. o forever while 1 IOCLR 0x40 IOSET 0x40 KERR RR KKK RRR KK System Initialization KKKKEKKKKKKKKK void Initialize Z nterrupt vectors to SRAM 0x2 Remap i MEMMAP Initial IODIR 0 IOSET 0 ize GPIO ports to be used as indicators xF0 xF0 jalize Pin Connect Block 0x50 Init PINSELO I2CONCLR 0x6c nitialize I c clearing all flags I2CONSET 0x40 enabling I c I2SCLH 0xC 100 KHz I2SCLL 0xD Initialize VIC for I C use VICINTSEL 0x0 selecting IRQ VICINTEN 0x200 enabling I C VICCNTLO 0x29 highest priority and enabled VICVADDR0 unsigned long 12C_ISR ISR address written to the respective address register Koninklijke Philips Electronics N V 2005 All rights reserved 12 of 17 Application note Rev 01 06 April 2005 Philips Semiconductors AN10369 Philips ARM LPC microcontroller family FOR RR KK 1C ISR FORO I KR KK KK __irg void 12C_ISR int temp 0 temp I2STAT switch temp case 8 ISR 8 break case 24 ISR_18 break case 40 ISR _28 break default break VICVADDR 0xFF 1 C states Start condition transmitted void ISR 8 Port Indicator OCLR 0x10 Slave address write 2DAT 0x74 Clear SI and Start flag 2CONCLR 0x28 Port Indicator OSET 0x10 Koninklijke Philips Electr
9. onics N V 2005 All rights reserved Application note Rev 01 06 April 2005 13 of 17 Philips Semiconductors AN1 0369 Ey Philips ARM LPC microcontroller family Acknowledgement received from slave for slave address void ISR_18 Port Indicator OCLR 0x20 Data to be transmitted 2DAT 0x55 clear SI 2CONCLR 0x8 Port Indicator OSET 0x20 Acknowledgement received from slave for byte transmitted from master Stop condition is transmitted in this state signaling the end of transmission void ISR _28 Port Indicator OCLR 0x80 Transmit stop condition 2CONSET 0x10 clear SI 2CONCLR 0x8 Port Indicator OSET 0x80 FIR IIR ROR TCROROICROIO KR I KK m 4 4 3 Linking notes for I C code Since the interrupt vectors need to be remapped to SRAM hence the interrupt vector table should be linked to 0x40000000 Remaining files could be linked after the interrupt vector table The first instruction to be executed will be the instruction located at 0x40000000 which would be LDR PC start PC gets transferred to the assembly code and from there to the main C code On an IRQ interrupt PC will execute the instruction located at the IRQ interrupt vector in the interrupt vector table LDR PC PC 0xFF0 On execution of this instruction PC will start executing the I C ISR located in the C file 4 5 Output waveforms In the output waveform the
10. sed but they have been used for this example IC 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 VPB Divider value is at its reset settings and hence the peripheral clock is one fourth of the system clock 10 MHz Calculation of Bit frequency Bit Frequency pclk I CSCLH I CSCLL Since the maximum speed the PCF8574 could interface to the LPC2106 is100 KHz 100KHz 2 5MHz I7CSCLH I 7CSCLL Therefore I CSCLH CSCLL 25 We select I CSCLH 13 amp I CSCLL 12 Koninklijke Philips Electronics N V 2005 All rights reserved Application note Rev 01 06 April 2005 8 of 17 Philips Semiconductors AN10369 Philips ARM LPC microcontroller family 4 2 Setting of the slave address PCF8574A has the following address 0 1 A1 AO In the test setup A1 was driven high A2 and AO are driven low 4 3 State Diagram with regard to I7C states Only three IC states are considered in this example namely 0x8 0x18 and 0x28 The code flow is shown below For detailed description on the I C states please refer to the User Manual of the respective device The section describing I C has been recently updated for the LPC213x User Manual and this section will be updated for all LPC 2000 Family devices in future revi
11. sions of the User Manual Slave acknowledges Slave acknowledges Start condition transmitted IC master enters State 8H and transmits slave address Write bit IC master enters State 18H and transmits data byte 55H IC master enters State 28H and transmits Stop condition 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 Philips Semiconductors AN10369 4 4 1 Philips ARM LPC microcontroller family 2 Startup Assembly code 3 Main C file 4 Header file 5 Tool specific file not shown here Only the first three files are discussed and shown below Interrupt Vector table AREA IVT CODE New Code section CODE32 ARM code IMPORT start start symbol not defined in this section Entry Defines entry point R PC start R PC Undefined Addr LDR PC SWI Addr R PC Prefetch_Addr R PC Abort Addr LDR PC PC 0xFF0 LDR PC FIQ Addr Undefined Addr DCD Undefined Handler SWI Addr DCD SWI Handler Prefetch Addr DCD Prefetch Handler Abort_Addr DCD Abort Handler FIQ Addr DCD FIQ Handler The following dummy handlers do not do anything useful in this example They are set up here for completeness Undefined Handler B Undefined Handler SWI Handler B SWI Handler Prefetch Ha
12. speed SPCCR 0x8 CPOL and CPHA both are set to 0 3 1 Speed Calculation Speed of SPI VPB clock SPCCR value 10MHz 8 1 25 MHz 3 2 C Code Include header file depending upon part used include LPC2 h void Initialize void Macro Definitions define SPIF 1 lt lt 7 define DATA 0xC1 FOR RK KK MAIN FOI KKK KK int main Koninklijke Philips Electronics N V 2005 All rights reserved Application note Rev 01 06 April 2005 6 of 17 Philips Semiconductors AN1 0369 Ey Philips ARM LPC microcontroller family Initialize Do forever while 1 Write data out SPDR DATA Wait for transfer to be completed while SPSR amp SPIF RRR RRR KK RRR K System Initialization FOI RK KK void Initialize Configure Pin Connect Block PINSELO 0x5500 Set pclk to same as cclk VPBDIV 0x1 Set to highest speed for SPI at 10 MHz gt 1 25 MHz SPCCR 0x8 Device selected as master SPCR 0x20 IRI G IO RIORG ICRC CIORGICR IOR CTOR TCR IO I KI KK 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 AN10369 Philips Semiconductors if Philips ARM LPC microcontroller family Fig 3 Waveforms 4 1 In the above code examples for UART and SPI interrupts have not been u
13. tors for any damages resulting from such application Right to make changes Philips Semiconductors reserves the right to make changes in the products including circuits standard cells and or software described or contained herein in order to improve design and or performance When the product is in full production status Production Philips ARM LPC microcontroller family relevant changes will be communicated via a Customer Product Process Change Notification CPCN Philips Semiconductors assumes no responsibility or liability for the use of any of these products conveys no licence or title under any patent copyright or mask work right to these products and makes no representations or warranties that these products are free from patent copyright or mask work right infringement unless otherwise specified Application information Applications that are described herein for any of these products are for illustrative purposes only Philips Semiconductors make no representation or warranty that such applications will be suitable for the specified use without further testing or modification Koninklijke Philips Electronics N V 2005 All rights reserved Application note Rev 01 06 April 2005 16 of 17 Philips Semiconductors AN1 0369 E Philips ARM LPC microcontroller family 6 Contents 1 2 2 1 2 2 2 3 2 4 3 3 1 3 2 3 3 4 4 1 Calculation of Bit frequency cee

Download Pdf Manuals

image

Related Search

Related Contents

Operação - TV Zakupy  Bedienungsanleitung  EnrEgistrEz votrE produit vatErra En lignE  ualité Web : le site qualité Flunc hh  Siliconcoach Pro7  Altinex MT109-100 User's Manual  ストーブ火災に注意!!  UC-15I Use and Care Guide - Sub-Zero  ADMS-Urban RML User Guide  130-Thymovar, mode d`emploi  

Copyright © All rights reserved.
Failed to retrieve file