Anda di halaman 1dari 43

Introduction to mbed NXP

LPC 1768 and Hands On

Processor Vs MCU

From Where to Start


LPC17XX
Reason
ARM7TDMI Family
Best for entry point feature use
Free development tool chain is available
(Open source community and Software Vendors)
Support for RTOS

LPC17xx key benefits


Design flexibility through pin-and softwarecompatible solutions
Scalable memory sizes within the same
footprint
Wide selection of high-performance
peripherals including Ethernet, CAN, USB
etc.,
Pin-compatible solutions between ARM7 and
Cortex-M3

Key feature

Advantage

Customer benefit

M3 improved critical path timing


Flash accelerator

Zero wait-state operation from flash


up to 100 MHz

improved price/performance ratio

Wake Up Interrupt Controller (WIC)

Eliminates the need to periodically


wake up the controller and poll the
interrupts

Saving power

True, low-power RTC

Battery current < 1uA over


temperature
Calendar function that does not
require CPU involvement

Saving power
Ease of design

Memory Protection Unit (MPU)

Wide range of peripherals: Ethernet,


USB, CAN, I2C, I2S, SPI, ADC, DAC
and much more one one chip

Allowing memory regions to be


defined as read-only and protect them
from corruption Required
Highest integration of peripherals

Required for safety critical


applications
Save cost and board space
Improved system performance

Features of LPC1768

ARM Cortex-M3 based microcontrollers for embedded applications.


ARM Cortex-M3 is a next generation core.
LPC1768 operate at CPU frequencies of up to 100 MHz
Peripheral complement
512 kB of ash memory
up to 64 kB of data memory,
Ethernet MAC, USB Device/Host/OTG interface,
8-channel general purpose DMA controlle.
4 UARTs, 2 CAN channels, SPI interface, 3 I2C-bus interfaces.
8-channel 12-bit ADC, 10-bit DAC.
Motor control PWM.
with separate battery supply, and up to general purpose I/O pins.

Applications

eMetering
Lighting
Industrial networking
Alarm systems
White goods
Motor control

Embedded C Programming

Most computers having a unified memory space, with the code and data sharing the same
RAM.

8051 has separate memory spaces for code, on-chip data, and external data.

Microcontrollers were originally programmed only in assembly language, but various highlevel programming languages are in common use to target microcontrollers.

These languages are general purpose languages such as the C programming language.

Compilers for general purpose languages will typically have some restrictions as well as
enhancements to better support the unique characteristics of microcontrollers.

Some microcontrollers have environments to aid developing certain types of applications.

Microcontroller vendors often make tools freely available to make it easier to adopt their
hardware.

C for Microcontrollers
Of higher level languages, C is the closest to
assembly languages
bit manipulation instructions
pointers (indirect addressing)

Most microcontrollers have available C


compilers
Writing in C simplifies code development for
large projects.

C Language

Embedded C Language

used for desktop computers

for microcontroller based applications

use the resources of a desktop PC like


memory, OS, etc

use with the limited resources, such as


RAM, ROM, I/Os on an embedded
processor

Compilers for C typically generate OS


dependant executables

compilers files to be downloaded to the


microcontrollers/microprocessors where
it needs to run.

Available C Compilers

Keil integrated with the IDE we have been using for labs.

Keil Software

One of the most complete development tool suites for 8051 software, which is used
throughout industry.

For development of C code, their Developer's Kit product includes their C51 compiler, as well
as an integrated 8051 simulator for debugging.

The C programming language was designed for computers, though, and not embedded
systems. It does not support direct access to registers, nor does it allow for the reading and
setting of single bits, two very important requirements for 8051 software.

Most of software developers are accustomed to writing programs that will by executed by an
operating system, which provides system calls, the program may use to access the hardware.

But code is written for direct use on the processor, without an operating system. To support
this, the Keil compiler has added several extensions to the C language to replace what might
have normally been implemented in a system call, such as the connecting of interrupt
handlers.

Keil For ARM


Complete Tool chain include uvision IDE,
compiler, simulator and debugger.
KEIL also Provide RTX RTOS for ARM
Evaluation version is available for download.

Get to Know Your Board Hardware


Pins

mbed Board Features


SoC Chip - NXP LPC1768 MCU
Low power ARM Cortex-M3 Core
48MHz, 64KB RAM, 512KB FLASH
USB Device, SPI, I2C , UART, ADC, GPIO

Prototyping form-factor
40-pin 0.1" pitch DIP package, 54x26mm
5V USB, 4.5-9V supply or 2.4-3.3V battery
Built-in USB drag 'n' drop FLASH programmer

ARM Cortex-M3 processor


32-bit microprocessor
New features

Thumb-2 instruction set


Nonmaskable interrupts for critical tasks
Highly deterministic nested vector interrupts
Atomic bit manipulation
Memory Protection Unit (MPU).

Pipeline techniques are employed

ARM Single Cycle instruction 3-stage


pipeline operation

Features

On-chip flash program memory


On-chip SRAM
Memory Protection Unit (MPU)
Memory map
Nested Vectored Interrupt Controller (NVIC)
Fast general purpose parallel I/O
SPI serial I/O controller
USB interface
Ethernet
12-bit ADC
10-bit DAC
I2C-bus serial I/O controllers
CAN controller
Pulse width modulator

On-chip flash program memory


512 kB of on-chip flash memory

On-chip SRAM
64 kB on-chip static RAM memory
32 kB SRAM
Two additional 16 kB SRAM

Memory Protection Unit (MPU)


Used to improve the reliability of an embedded system
Allows separating processing tasks.

Memory Map
Several distinct memory regions

Nested Vectored Interrupt Controller


(NVIC)
NVIC is an integral part of the Cortex-M3.
Features
Controls system exceptions and peripheral interrupts
NVIC supports 33 vectored interrupts
32 programmable interrupt priority levels, with
hardware priority level masking
Relocatable vector table
Non-Maskable Interrupt (NMI)
Software interrupt generation

Fast general purpose parallel I/O

Device pins that are not connected to a specific


peripheral function are controlled by the GPIO
registers.
LPC1768 use accelerated GPIO functions:

GPIO registers are a dedicated AHB peripheral and are


accessed through the AHB multilayer bus so that the fastest
possible I/O timing can be achieved.
Mask registers allow treating sets of port bits as a group,
leaving other bits unchanged.
All GPIO registers are byte and half-word addressable.
Entire port value can be written in one instruction.

Features
Bit level set and clear registers allow a single instruction to
set or clear any number of bits in one port.
Direction control of individual bits.
All I/O default to inputs after reset.

SPI serial I/O controller


LPC1768 contain two SPI controller.
SPI is a full duplex serial interface designed to
handle multiple masters and slaves connected
to a given bus.
Features

Compliant with SPI specification.


Synchronous, serial, full duplex communication.
Combined SPI master and slave.
Maximum data bit rate of one eighth of the input clock
rate.
8 bits to 16 bits per transfer.

USB interface
2-wire bus supports communication between a
host and one or more (up to 64) peripherals.
Features
Fully compliant with USB 2.0 specification (full speed).
Supports 32 physical (16 logical) endpoints with a 4 kB
endpoint buffer RAM.
Supports Control, Bulk, Interrupt and Isochronous endpoints.
Scalable realization of endpoints at run time.

USB device controller


Enables 12 Mbit/s data exchange with a USB Host controller.

Ethernet

Ethernet standards support:


Supports 10 Mbit/s or 100 Mbit/s PHY devices including
10 Base- T, 100 Base-TX,100 Base-FX, and 100 Base-T4.
Fully compliant with IEEE standard 802.3.
Fully compliant with 802.3x full duplex flow control and half duplex back
pressure.
Flexible transmit and receive frame options.
Virtual Local Area Network (VLAN) frame support.
Memory management:
Independent transmit and receive buffers memory mapped to shared SRAM.
DMA managers with scatter/gather DMA and arrays of frame descriptors.
Memory traffic optimized by buffering and pre-fetching.
Enhanced Ethernet features:
Automatic collision back-off and frame retransmission.
Multicast and broadcast frame support for both transmit and receive.
Optional automatic Frame Check Sequence (FCS) insertion with Cyclic
Redundancy Check (CRC) for transmit.

12-bit ADC
Contain one ADC(12-bit successive approximation
ADC)
DMA support.

10-bit DAC
Generate a variable analog output.
The maximum output value of the Vi(VREFP .
10-bit DAC
)

I2C-bus serial I/O controllers


The LPC1768 contain two I2C-bus controllers.
I2C-bus is bidirectional for inter-IC control
using only two wires:
Serial Clock line (SCL)
Serial Data Line (SDA)

I2C1 and I2C2 use standard I/O pins with bit


rates of up to 400 kbit/s.
Bidirectional data transfer between masters
and slaves.

CAN controller
The Controller Area Network (CAN) is a serial
communications protocol which efficiently
supports distributed real-time control with a
very high level of security.
The CAN block is intended to support multiple
CAN buses simultaneously.
Features
Data rates to 1 Mbit/s on each bus.
Compatible with CAN specification 2.0B, ISO 11898-1.
Acceptance Filter can provide FullCAN-style automatic
reception for selected Standard Identifiers.

Pulse width modulator


The PWM is based on the standard Timer
block and inherits all of its features.
Ability to separately control rising and falling
edge locations allows the PWM to be used for
more applications.

Steps to use Offline Compiler

Signing up or Logging In
Connect mbed board to
host machine using a USB
cable
Board presents itself as a
flash drive named MBED
To sign up or log in, double
click on html file in MBED
drive
Sign up or Log in using your
existing username &
password

Using the Compiler


After log in, Double Click on Compiler in
upper right corner of mbed webpage
Open and Name a new program in Program
Workspace on left
Write application code in file new program
using source code window on right
Save entire program and Compile
Compiler outputs
Errors and warnings with a downloadable
compiled binary
Save binary in any desired directory on your
machine
Drag and drop it into the MBED drive

Running Your Applications


Once compiled binary has been dropped into
MBED drive, it needs to execute on the onchip processor
Press reset button on mbed board module
Your code will start running!

Know Your mbed Pin Numbers

Keep mbed board facing you with USB port pointing left
Start with Pin 1 at bottom left extreme, move from left to
right (incrementing pin numbers on the way), to Pin 20.
Then crossover to upper right to Pin 21, move from right
to left, incrementing pin numbers on the way, to Pin 40
Pin 1 0.0 V (GND)
Pin 40 3.3 V (VDD)
Pin 39 5.0 V (USB Source)

Blink External LEDs

Use of LED
Longer pin is positive or anode
Shorter is negative or cathode

#include "mbed.h
DigitalOut led(p5);
int main()
{
led = 1;
led = 0;
}

// Handles startup code, C


Library and Firmware //
// Pin 5, a Digital Out object
with object name led

// LED whose anode is


connected to Pin 5 lights up

Two Digital GPIO pins drive LED anodes mbed Pins 5 & 6
Connect both LED cathodes to GND, which is mbed Pin 1
mbed Interface DigitalOut in code configures Pins 5 and 6 as
Digital Outputs
Code:

#include "mbed.h"
DigitalOut redled(p5);
DigitalOut greenled(p6);
int main() {
while(1) {
redled = 1; greenled = 0;
wait(0.9);
redled = 0; greenled = 1;
wait(0.9);
}
}

7-segment Display
Use common-anode 7-segment display
Identify 7-segment Display pins
LED segments, including decimal point
Pins 3 or 8 are common-anode pins
Pins 1, 2, 4, 5, 6, 7, 9 and 10 are cathodes

Connect Hardware (7-segment Display) to mbed .


Connect LED common-anode pin 3 or 8 to mbed pin
40.
mbed Interface BusOut in code configures mbed
pins 5 to 12 as a Digital Output Bus.
Digit

dp G F E D C B A

HEX Combination

1000000

C0

1111001

F9

0100100

A4

0110000

B0

0011001

99

0010010

92

0000010

82

1111000

F8

0000000

80

0010000

90

Pin Connections between mbed board and 7seg Display.


Mbed Pin

7-Seg Pin Number

7-seg Pin Name

10

11

10

12

Dp

40

3 or 8

CA

#include "mbed.h"
BusOut Disp1(p5,p6,p7,p8,p9,p10,p11,p12);
/ / ABCDEFGdp
int main() {
while (1) {
// infinite loop
Disp1 = 0xC0; wait(0.9)
// Displays '0'
Disp1 = 0xF9; wait(0.9)
// Displays '1'
Disp1 = 0xA4; wait(0.9)
// Displays 2'
Disp1 = 0xB0; wait(0.9)
// Displays 3'
Disp1 = 0x99; wait(0.9)
// Displays 4
Disp1 = 0x92; wait(0.9)
// Displays 5'
Disp1 = 0x82; wait(0.9)
// Displays 6'
Disp1 = 0xF8; wait(0.9)
// Displays 7'
Disp1 = 0x80; wait(0.9)
// Displays 8'
Disp1 = 0x90; wait(0.9)
// Displays 9'
}
}

Use of Modular Programming


Always Make Your Code Modular
Improves Readability
Reduces code size, makes it easy to follow and
understand what you have written

Improves Efficiency
Uses HW/SW machine resources efficiently, may even
speed up performance

Reuse
Helps to develop new code rapidly using chunks
(modules) of previously written code

Main while loop has two statements repeated ten times


Disp1 = 0xC0 RHS (Hex Value) changes each time
wait(0.9) Remains the very same all ten times

Create a module (int array) of stored RHS (Hex values)


int Hex[] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80,
0x90};
Use a for-loop; Cathode-status combination for a number to be
displayed is in array element with number as index
for (int i = 0; I <= 9; i++)
{
Disp1 = Hex[i];
wait(0.9);
}

#include "mbed.h"
BusOut Disp1(p5,p6,p7,p8,p9,p10,p11,p12);
// ABCDEFGDP
int Hex[ ] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80,
0x90};
// Module - Array
int main()
{
while (1)
{
// infinite loop
for (int i = 0; i <= 9; i++)
{
Disp1 = Hex[i];
wait(0.9);
}
}
}

Anda mungkin juga menyukai