SlideShare a Scribd company logo
1 of 15
How to use peripherals on
MCB1700
MTE241 – Fall2014
Peripherals
• GPIO
• ADC/DAC
• Ethernet
• USB
6/23/2016 MTE241 – Fall2014 2(UM10360, 2014)
Power Control Block
Power is a major concern in ARM-based chips
• By powering down the unused peripherals, considerable
power is saved
Peripheral power control register is referenced from
CMISIS as LPC_SC->PCONP
• LPC_SC is a general system-control register block
• PCONP refers to Power CONtrol for Peripherals
µVision provides the peripherals power through system_17xx.c
6/23/2016 MTE241 – Fall2014 3
Pin Connect Block
Most chip pins can perform up to four different functions
• You must specify what function you want each pin to be used for
Programming a set of registers known as the Pin Connect
Block
• From CMSIS as a struct called LPC_PINCON, with fields called
PINSEL1, PINSEL2, PINMODE1, PINMODE2 and so on.
6/23/2016 MTE241 – Fall2014 4
(UM10360, 2014)
(UM10360, 2014)
Interrupt Service Routine
• Almost all Peripherals can generate interrupts.
• The conditions on generating interrupts are different for each peripherals.
• Interrupt Service Routines in CMIS is just a function with the interrupt source
appended by _IRQHandler
• E.g. ADC_IRQHandler
• CMIS provides APIs for enabling/disabling, prioritizing, and Pending ISRs:
• Interrupts can be fired by writing interrupt number in NVIC->STIR
• But, they are cleared depending on the peripherals caused.
void NVIC_EnableIRQ( IRQn_Type IRQn )
void NVIC_DisableIRQ( IRQn_Type IRQn )
void NVIC_SetPriority( IRQn_Type IRQn, int32_t priority )
uint32_t NVIC_GetPriority( IRQn_Type IRQn )
6/23/2016 MTE241 – Fall2014 5
The chip directly communicates with its environment through pins in
GPIO mode
• The pin can be set for input or output directions
• In case of MCB1700:
• 8 LEDs are connected as output pins
• Joystick and INT0 button are connected as input pins
General-Purpose I/O
6/23/2016 MTE241 – Fall2014 6
Steps to Configure GPIO
Enable the power
Set Pins and their modes
• Selecting the GPIO LPC_PINCON->PINSEL[0-4]
• Input/output direction LPC_GPIO[0-2]->FIODIR
Set appropriate interrupts if needed
• Raising/falling edge LPC_GPIOINT->IO2IntEnF
• Registering NVIC_EnableIRQ( EINT3_IRQn )
• Clearing interrupt LPC_GPIOINT->IO2IntClr
Manipulating the pins
• Set an output pin FIOSET
• Read an input pin FIOPIN
• Clear an output pin FIOCLR
6/23/2016 MTE241 – Fall2014 7
Example 1: Turning On/Off a LED
1) Enable power
LPC_SC->PCONP |= (1 << 15);
2) LED connected to p1.28 is in GPIO mode
LPC_PINCON->PINSEL3 &= ~(3 << 25);
3) LED connected to p1.28 is an output pin
LPC_GPIO1->FIODIR |= (1 << 28);
4) Turning on the LED
LPC_GPIO1->FIOSET |= (1 << 28);
5) Turning off the LED
LPC_GPIO1->FIOCLR |= (1 << 28);
6/23/2016 MTE241 – Fall2014 8
(UM10360, 2014)
Example 2: Intercepting push-button click
1) Enable power
2) Push-button connected to p2.10 is in GPIO mode
LPC_PINCON->PINSEL4 &= ~( 3 << 20 );
3) P2.10 is an input pin
LPC_GPIO2->FIODIR &= ~( 1 << 10 );
4) P2.10 reads the falling edges to generate an interrupt
LPC_GPIOINT->IO2IntEnF |= ( 1 << 10 );
5) IRQ is enabled in NVIC.
NVIC_EnableIRQ( EINT3_IRQn );
6) Clear interrupt condition when it has been fired
LPC_GPIOINT->IO2IntClr |= (1 << 10);
6/23/2016 MTE241 – Fall2014 9
Clocks
• Clock in LPC178 is very flexible to generate different
frequencies at the same time
• Clock source is selected through Clock Source Select
register LPC_SC->CLKSRCSEL:
• Internal 4 MHz RC oscillator (this is the default)
• 12 MHz external oscillator
• 32 kHz real-time clock oscillator
• The input clock is directly fed into PLL to increase
the clock frequency and clock divider to decrease
the clock
• The clock can be divided further for peripheral
clockSetup the PLL and frequency devisors is complex
and involves many registers
• µVision provides a straightforward interface to set the
clock through system_17xx.c
6/23/2016 MTE241 – Fall2014 10
(UM10360, 2014)
Configuring the clock
• Select the Main oscillator
• The main oscillator generates 12 MHz clock,
OSCRANGE has to cover it.
• Select PLL0 to accelerate the clock
• The output frequency of PLL is 2 × M × F ÷ N
• F is input frequency
• 6 ≤ M ≤ 512
• 1 ≤ N ≤ 32
• E.g., 400 MHz = 2 × 100 × 12 ÷ 6
• Pick a proper clock divider for 100 MHz ARM
• CCLKSEL = 4
• Now the clock are ready for peripherals in
100 MHz, 50 MHz, 25 MHz and 12.5 MHz
6/23/2016 MTE241 – Fall2014 11
Analogue to Digital Convertor
• A 12-bit analog to digital converter
• 8 converting channels through 8-input analog mux
• A potentiometer connected to analog input 2
• Three registers are particularly to be configured
• The analog/digital control register LPC_ADC->ADCR
• The analog/digital global data register LPC_ADC->ADGDR
• The analog/digital interrupt enable register LPC_ADC->ADINTEN
6/23/2016 MTE241 – Fall2014 12
ADC configuration steps
• Set Power using PCONP register
• Where is accessible in system_17xx.c
• Set Clock using PCLKSEL0 register
• Already set
• Enable ADC0 pins through PINSEL registers
• Enable interrupts using CMSIS APIs
• Now, start conversion.
• Wait until the ADC status shows the conversion is done after ~52 ticks.
• Response to the interrupt
6/23/2016 MTE241 – Fall2014 13
Example3: Reading Potentiometer
1) Enable power
LPC_SC->PCONP |= ( 1 << 12 );
2) Potentiometer connected to p0.25 is in ADC mode
LPC_PINCON->PINSEL1 &= ~( 0x3 << 18 ); //clear bits
LPC_PINCON->PINSEL1 |= ( 0x1 << 18 ); //set bits
3) Set the ADC control register
LPC_ADC->ADCR = ( 1 << 2 ) | // Select the second channel
( 4 << 8 ) | // ADC clock is 25MHz/(4+1)
( 0 << 24 ) | // Do not start the conversion yet
( 1 << 21 ); // Enable ADC
4) Enable interrupt for all ADC channels
LPC_ADC->ADINTEN = ( 1 << 8);
5) Register interrupt
NVIC_EnableIRQ( ADC_IRQn );
6) Start Conversion
LPC_ADC->ADCR |= ( 1 << 24 );
LPC_SC->PCONP |= ( 1 << 12 );
7) Read the converted value
I. Polling (i.e. busy waiting) to see when the conversion is done. There is
no need to activate and register interrupts in this way.
// wait for conversion complete
while (LPC->ADGDR & 0x8000 == 0);
// read 12 bits result
ADC_Value = (LPC_ADC->ADGDR>>4) & 0xFFF;
II. Response for the interrupt
// Read ADC Status clears the interrupt condition
aDCStat = LPC_ADC->ADSTAT;
ADC_Value = (LPC_ADC->ADGDR >> 4) & 0xFFF;
6/23/2016 MTE241 – Fall2014 14
Resources
• LPC176x/5x User manual. (2014, April 2014). 3.1, 846. NXP Semiconductor.
Retrieved November 1, 2014, from
http://www.nxp.com/documents/user_manual/UM10360.pdf
• Roehl, B. (2011, April 18). Lab Manual for ECE 455. 39. Waterloo, ON, Canada.
Retrieved November 1, 2014, from
http://www.arm.com/files/pdf/ece455labmanual_preliminary.pdf
• Yiu, J. (2009). The Definitive Guide to the ARM® Cortex-M3
6/23/2016 MTE241 – Fall2014 15
@MANUAL {lpc178:usermanual, title = "UM10360: LPC176x/5x User manual",
organization = "NXP Semiconductor", edition = "Rev.3.1", month = "apr", year = "2014" }

More Related Content

Similar to How to use peripherals on MCB1700

1 PageAlarm Clock Design Using PIC18F45E.docx
1  PageAlarm Clock Design Using PIC18F45E.docx1  PageAlarm Clock Design Using PIC18F45E.docx
1 PageAlarm Clock Design Using PIC18F45E.docxmercysuttle
 
04 adc (pic24, ds pic with dma)
04 adc (pic24, ds pic with dma)04 adc (pic24, ds pic with dma)
04 adc (pic24, ds pic with dma)antonio michua
 
MicrocontrollersII (1).pptx
MicrocontrollersII (1).pptxMicrocontrollersII (1).pptx
MicrocontrollersII (1).pptxnodov66591
 
PSC9131UG_C4_FD
PSC9131UG_C4_FDPSC9131UG_C4_FD
PSC9131UG_C4_FDHaim Amir
 
CAN_controller_integrated_transceiver_microchip_MCP25625.pdf
CAN_controller_integrated_transceiver_microchip_MCP25625.pdfCAN_controller_integrated_transceiver_microchip_MCP25625.pdf
CAN_controller_integrated_transceiver_microchip_MCP25625.pdfVaraPrasadVemula4
 
Introduction to PIC18FX6J Series MCUs
Introduction to PIC18FX6J Series MCUsIntroduction to PIC18FX6J Series MCUs
Introduction to PIC18FX6J Series MCUsPremier Farnell
 
Blinking Of LEDs On LPC2148 ARM 7 TDMIS Based Microcontroller
Blinking Of LEDs On LPC2148 ARM 7 TDMIS Based MicrocontrollerBlinking Of LEDs On LPC2148 ARM 7 TDMIS Based Microcontroller
Blinking Of LEDs On LPC2148 ARM 7 TDMIS Based MicrocontrollerOmkar Rane
 
Share 'speed control_of_dc_motor_using_microcontroller.pptx'[1][1]
Share 'speed control_of_dc_motor_using_microcontroller.pptx'[1][1]Share 'speed control_of_dc_motor_using_microcontroller.pptx'[1][1]
Share 'speed control_of_dc_motor_using_microcontroller.pptx'[1][1]akmalKhan55
 
microcontroller board ppt
microcontroller board pptmicrocontroller board ppt
microcontroller board pptshashank tiwari
 
PIC Presentation_final updated.pptx
PIC Presentation_final updated.pptxPIC Presentation_final updated.pptx
PIC Presentation_final updated.pptxShabanamTamboli1
 
Training Report on embedded Systems and Robotics
Training Report on embedded  Systems and RoboticsTraining Report on embedded  Systems and Robotics
Training Report on embedded Systems and RoboticsNIT Raipur
 
Industrial training report of embedded system and robotics
Industrial training report of embedded system and roboticsIndustrial training report of embedded system and robotics
Industrial training report of embedded system and roboticsPallavi Bharti
 
embedded system introduction to microcontrollers
embedded system introduction to microcontrollersembedded system introduction to microcontrollers
embedded system introduction to microcontrollersBarER4
 

Similar to How to use peripherals on MCB1700 (20)

1 PageAlarm Clock Design Using PIC18F45E.docx
1  PageAlarm Clock Design Using PIC18F45E.docx1  PageAlarm Clock Design Using PIC18F45E.docx
1 PageAlarm Clock Design Using PIC18F45E.docx
 
Introduction to PIC.pptx
Introduction to PIC.pptxIntroduction to PIC.pptx
Introduction to PIC.pptx
 
04 adc (pic24, ds pic with dma)
04 adc (pic24, ds pic with dma)04 adc (pic24, ds pic with dma)
04 adc (pic24, ds pic with dma)
 
MicrocontrollersII (1).pptx
MicrocontrollersII (1).pptxMicrocontrollersII (1).pptx
MicrocontrollersII (1).pptx
 
PSC9131UG_C4_FD
PSC9131UG_C4_FDPSC9131UG_C4_FD
PSC9131UG_C4_FD
 
Analog to Digital Converter
Analog to Digital ConverterAnalog to Digital Converter
Analog to Digital Converter
 
chapter 4
chapter 4chapter 4
chapter 4
 
89c5131datasheet
89c5131datasheet89c5131datasheet
89c5131datasheet
 
CAN_controller_integrated_transceiver_microchip_MCP25625.pdf
CAN_controller_integrated_transceiver_microchip_MCP25625.pdfCAN_controller_integrated_transceiver_microchip_MCP25625.pdf
CAN_controller_integrated_transceiver_microchip_MCP25625.pdf
 
Timers and Endge-aligned PWM
Timers and Endge-aligned PWMTimers and Endge-aligned PWM
Timers and Endge-aligned PWM
 
Introduction to PIC18FX6J Series MCUs
Introduction to PIC18FX6J Series MCUsIntroduction to PIC18FX6J Series MCUs
Introduction to PIC18FX6J Series MCUs
 
Blinking Of LEDs On LPC2148 ARM 7 TDMIS Based Microcontroller
Blinking Of LEDs On LPC2148 ARM 7 TDMIS Based MicrocontrollerBlinking Of LEDs On LPC2148 ARM 7 TDMIS Based Microcontroller
Blinking Of LEDs On LPC2148 ARM 7 TDMIS Based Microcontroller
 
Share 'speed control_of_dc_motor_using_microcontroller.pptx'[1][1]
Share 'speed control_of_dc_motor_using_microcontroller.pptx'[1][1]Share 'speed control_of_dc_motor_using_microcontroller.pptx'[1][1]
Share 'speed control_of_dc_motor_using_microcontroller.pptx'[1][1]
 
microcontroller board ppt
microcontroller board pptmicrocontroller board ppt
microcontroller board ppt
 
PIC Presentation_final updated.pptx
PIC Presentation_final updated.pptxPIC Presentation_final updated.pptx
PIC Presentation_final updated.pptx
 
digital clock atmega16
digital clock atmega16digital clock atmega16
digital clock atmega16
 
Training Report on embedded Systems and Robotics
Training Report on embedded  Systems and RoboticsTraining Report on embedded  Systems and Robotics
Training Report on embedded Systems and Robotics
 
Industrial training report of embedded system and robotics
Industrial training report of embedded system and roboticsIndustrial training report of embedded system and robotics
Industrial training report of embedded system and robotics
 
embedded system introduction to microcontrollers
embedded system introduction to microcontrollersembedded system introduction to microcontrollers
embedded system introduction to microcontrollers
 
Digital stop watch
Digital stop watchDigital stop watch
Digital stop watch
 

Recently uploaded

What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?Watsoo Telematics
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 

Recently uploaded (20)

What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 

How to use peripherals on MCB1700

  • 1. How to use peripherals on MCB1700 MTE241 – Fall2014
  • 2. Peripherals • GPIO • ADC/DAC • Ethernet • USB 6/23/2016 MTE241 – Fall2014 2(UM10360, 2014)
  • 3. Power Control Block Power is a major concern in ARM-based chips • By powering down the unused peripherals, considerable power is saved Peripheral power control register is referenced from CMISIS as LPC_SC->PCONP • LPC_SC is a general system-control register block • PCONP refers to Power CONtrol for Peripherals µVision provides the peripherals power through system_17xx.c 6/23/2016 MTE241 – Fall2014 3
  • 4. Pin Connect Block Most chip pins can perform up to four different functions • You must specify what function you want each pin to be used for Programming a set of registers known as the Pin Connect Block • From CMSIS as a struct called LPC_PINCON, with fields called PINSEL1, PINSEL2, PINMODE1, PINMODE2 and so on. 6/23/2016 MTE241 – Fall2014 4 (UM10360, 2014) (UM10360, 2014)
  • 5. Interrupt Service Routine • Almost all Peripherals can generate interrupts. • The conditions on generating interrupts are different for each peripherals. • Interrupt Service Routines in CMIS is just a function with the interrupt source appended by _IRQHandler • E.g. ADC_IRQHandler • CMIS provides APIs for enabling/disabling, prioritizing, and Pending ISRs: • Interrupts can be fired by writing interrupt number in NVIC->STIR • But, they are cleared depending on the peripherals caused. void NVIC_EnableIRQ( IRQn_Type IRQn ) void NVIC_DisableIRQ( IRQn_Type IRQn ) void NVIC_SetPriority( IRQn_Type IRQn, int32_t priority ) uint32_t NVIC_GetPriority( IRQn_Type IRQn ) 6/23/2016 MTE241 – Fall2014 5
  • 6. The chip directly communicates with its environment through pins in GPIO mode • The pin can be set for input or output directions • In case of MCB1700: • 8 LEDs are connected as output pins • Joystick and INT0 button are connected as input pins General-Purpose I/O 6/23/2016 MTE241 – Fall2014 6
  • 7. Steps to Configure GPIO Enable the power Set Pins and their modes • Selecting the GPIO LPC_PINCON->PINSEL[0-4] • Input/output direction LPC_GPIO[0-2]->FIODIR Set appropriate interrupts if needed • Raising/falling edge LPC_GPIOINT->IO2IntEnF • Registering NVIC_EnableIRQ( EINT3_IRQn ) • Clearing interrupt LPC_GPIOINT->IO2IntClr Manipulating the pins • Set an output pin FIOSET • Read an input pin FIOPIN • Clear an output pin FIOCLR 6/23/2016 MTE241 – Fall2014 7
  • 8. Example 1: Turning On/Off a LED 1) Enable power LPC_SC->PCONP |= (1 << 15); 2) LED connected to p1.28 is in GPIO mode LPC_PINCON->PINSEL3 &= ~(3 << 25); 3) LED connected to p1.28 is an output pin LPC_GPIO1->FIODIR |= (1 << 28); 4) Turning on the LED LPC_GPIO1->FIOSET |= (1 << 28); 5) Turning off the LED LPC_GPIO1->FIOCLR |= (1 << 28); 6/23/2016 MTE241 – Fall2014 8 (UM10360, 2014)
  • 9. Example 2: Intercepting push-button click 1) Enable power 2) Push-button connected to p2.10 is in GPIO mode LPC_PINCON->PINSEL4 &= ~( 3 << 20 ); 3) P2.10 is an input pin LPC_GPIO2->FIODIR &= ~( 1 << 10 ); 4) P2.10 reads the falling edges to generate an interrupt LPC_GPIOINT->IO2IntEnF |= ( 1 << 10 ); 5) IRQ is enabled in NVIC. NVIC_EnableIRQ( EINT3_IRQn ); 6) Clear interrupt condition when it has been fired LPC_GPIOINT->IO2IntClr |= (1 << 10); 6/23/2016 MTE241 – Fall2014 9
  • 10. Clocks • Clock in LPC178 is very flexible to generate different frequencies at the same time • Clock source is selected through Clock Source Select register LPC_SC->CLKSRCSEL: • Internal 4 MHz RC oscillator (this is the default) • 12 MHz external oscillator • 32 kHz real-time clock oscillator • The input clock is directly fed into PLL to increase the clock frequency and clock divider to decrease the clock • The clock can be divided further for peripheral clockSetup the PLL and frequency devisors is complex and involves many registers • µVision provides a straightforward interface to set the clock through system_17xx.c 6/23/2016 MTE241 – Fall2014 10 (UM10360, 2014)
  • 11. Configuring the clock • Select the Main oscillator • The main oscillator generates 12 MHz clock, OSCRANGE has to cover it. • Select PLL0 to accelerate the clock • The output frequency of PLL is 2 × M × F ÷ N • F is input frequency • 6 ≤ M ≤ 512 • 1 ≤ N ≤ 32 • E.g., 400 MHz = 2 × 100 × 12 ÷ 6 • Pick a proper clock divider for 100 MHz ARM • CCLKSEL = 4 • Now the clock are ready for peripherals in 100 MHz, 50 MHz, 25 MHz and 12.5 MHz 6/23/2016 MTE241 – Fall2014 11
  • 12. Analogue to Digital Convertor • A 12-bit analog to digital converter • 8 converting channels through 8-input analog mux • A potentiometer connected to analog input 2 • Three registers are particularly to be configured • The analog/digital control register LPC_ADC->ADCR • The analog/digital global data register LPC_ADC->ADGDR • The analog/digital interrupt enable register LPC_ADC->ADINTEN 6/23/2016 MTE241 – Fall2014 12
  • 13. ADC configuration steps • Set Power using PCONP register • Where is accessible in system_17xx.c • Set Clock using PCLKSEL0 register • Already set • Enable ADC0 pins through PINSEL registers • Enable interrupts using CMSIS APIs • Now, start conversion. • Wait until the ADC status shows the conversion is done after ~52 ticks. • Response to the interrupt 6/23/2016 MTE241 – Fall2014 13
  • 14. Example3: Reading Potentiometer 1) Enable power LPC_SC->PCONP |= ( 1 << 12 ); 2) Potentiometer connected to p0.25 is in ADC mode LPC_PINCON->PINSEL1 &= ~( 0x3 << 18 ); //clear bits LPC_PINCON->PINSEL1 |= ( 0x1 << 18 ); //set bits 3) Set the ADC control register LPC_ADC->ADCR = ( 1 << 2 ) | // Select the second channel ( 4 << 8 ) | // ADC clock is 25MHz/(4+1) ( 0 << 24 ) | // Do not start the conversion yet ( 1 << 21 ); // Enable ADC 4) Enable interrupt for all ADC channels LPC_ADC->ADINTEN = ( 1 << 8); 5) Register interrupt NVIC_EnableIRQ( ADC_IRQn ); 6) Start Conversion LPC_ADC->ADCR |= ( 1 << 24 ); LPC_SC->PCONP |= ( 1 << 12 ); 7) Read the converted value I. Polling (i.e. busy waiting) to see when the conversion is done. There is no need to activate and register interrupts in this way. // wait for conversion complete while (LPC->ADGDR & 0x8000 == 0); // read 12 bits result ADC_Value = (LPC_ADC->ADGDR>>4) & 0xFFF; II. Response for the interrupt // Read ADC Status clears the interrupt condition aDCStat = LPC_ADC->ADSTAT; ADC_Value = (LPC_ADC->ADGDR >> 4) & 0xFFF; 6/23/2016 MTE241 – Fall2014 14
  • 15. Resources • LPC176x/5x User manual. (2014, April 2014). 3.1, 846. NXP Semiconductor. Retrieved November 1, 2014, from http://www.nxp.com/documents/user_manual/UM10360.pdf • Roehl, B. (2011, April 18). Lab Manual for ECE 455. 39. Waterloo, ON, Canada. Retrieved November 1, 2014, from http://www.arm.com/files/pdf/ece455labmanual_preliminary.pdf • Yiu, J. (2009). The Definitive Guide to the ARM® Cortex-M3 6/23/2016 MTE241 – Fall2014 15 @MANUAL {lpc178:usermanual, title = "UM10360: LPC176x/5x User manual", organization = "NXP Semiconductor", edition = "Rev.3.1", month = "apr", year = "2014" }