Thiết kế ứng dụng với ngắt GPIO .... Lập trình ứng dụng với GPIO .... Lập trình ứng dụng ngắt GPIO .... Mô tả chi tiết - Các sysctl API được chia thành tám nhóm chức năng: Nhóm cung cấp
Trang 11
Tài liệu Arm Cotex M3
Contents
1 Giới thiệu sản phẩm 2
1.1 Hiệu năng của kiến trúc RISC 32-Bit 2
1.2 Bộ nhớ nội (Internal Memory) 2
1.3 ARM FiRM-compliant Watchdog Timer 3
1.4 Controller Area Network (CAN) 3
1.5 10/100 Ethernet Controller 3
1.6 Synchronous Serial Interface (SSI) 3
1.7 UART 4
1.8 ADC 4
1.9 Analog Comparators 4
1.10 I2C 4
1.11 PWM 4
1.12 QEI 5
1.13 GPIOs 5
1.14 Power 6
2 Thư viện điều khiển ngoại vi Stellaris® 8
2.1 Điều khiển hệ thống (19 System Control) 8
2.2 Điều khiển vào/ra 9 GPIO 9
2.3 Điều khiển ngắt 10
2.4 Điều khiển LCD OLED 10
2.5 Chuyển đổi tương tự - số ADC 10
3 Các bước thiết kế ứng dụng 12
3.1 Thiết kế ứng dụng với GPIO 12
3.2 Thiết kế ứng dụng với ngắt GPIO 13
3.3 Thiết kế ứng dụng với LCD OLED 128x96x4 14
3.4 Thiết kế ứng dụng với ADC 14
3.5 Thiết kế ứng dụng với Timer 15
4 Các bài tập thiết kế ứng dụng 18
4.1 Lập trình ứng dụng với GPIO 18
4.2 Lập trình ứng dụng ngắt GPIO 18
4.3 Lập trình điều khiển LCD OLED 18
4.4 Lập trình đọc ADC 18
4.5 Lập trình với Timer 18
Trang 22
1 Giới thiệu sản phẩm
Product Features
The LM3S8962 microcontroller includes the following product features:
1.1.Hiệu năng của kiến trúc RISC 32-Bit
– 32-bit ARM® Cortex™-M3 v7M architecture optimized for small-footprint embedded applications
– System timer (SysTick), providing a simple, 24-bit clear-on-write, decrementing, wrap-on-zero
counter with a flexible control mechanism
– Thumb®-compatible Thumb-2-only instruction set processor core for high code density – 50-MHz operation
– Hardware-division and single-cycle-multiplication
– Integrated Nested Vectored Interrupt Controller (NVIC) providing deterministic interrupt handling
– 36 interrupts with eight priority levels
– Memory protection unit (MPU), providing a privileged mode for protected operating system
functionality
– Unaligned data access, enabling data to be efficiently packed into memory
– Atomic bit manipulation (bit-banding), delivering maximum memory utilization and streamlined
peripheral control
1.2.Bộ nhớ nội (Internal Memory)
– 256 KB single-cycle flash
• User-managed flash block protection on a 2-KB block basis
• User-managed flash data programming
• User-defined and managed flash-protection block
– 64 KB single-cycle SRAM
■ General-Purpose Timers
– Four General-Purpose Timer Modules (GPTM), each of which provides two 16-bit timers Each GPTM can be configured to operate independently:
• As a single 32-bit timer
• As one 32-bit Real-Time Clock (RTC) to event capture
• For Pulse Width Modulation (PWM)
• To trigger analog-to-digital conversions
– 32-bit Timer modes
• Programmable one-shot timer
• Programmable periodic timer
• Real-Time Clock when using an external 32.768-KHz clock as the input
• User-enabled stalling in periodic and one-shot mode when the controller asserts the CPU Halt flag during debug
Trang 33
• ADC event trigger
– 16-bit Timer modes
• General-purpose timer function with an 8-bit prescaler
• Programmable one-shot timer
• Programmable periodic timer
• User-enabled stalling when the controller asserts CPU Halt flag during debug
• ADC event trigger
– 16-bit Input Capture modes
• Input edge count capture
• Input edge time capture
– 16-bit PWM mode
• Simple PWM mode with software-programmable output inversion of the PWM signal
1.3 ARM FiRM-compliant Watchdog Timer
– 32-bit down counter with a programmable load register
– Separate watchdog clock with an enable
– Programmable interrupt generation logic with interrupt masking
– Lock register protection from runaway software
– Reset generation logic with an enable/disable
– User-enabled stalling when the controller asserts the CPU Halt flag during debug
1.4 Controller Area Network (CAN)
– Supports CAN protocol version 2.0 part A/B
– Bit rates up to 1Mb/s
– 32 message objects, each with its own identifier mask
– Maskable interrupt
– Disable automatic retransmission mode for TTCAN
– Programmable loop-back mode for self-test operation
1.5 10/100 Ethernet Controller
– Conforms to the IEEE 802.3-2002 Specification
– Hardware assistance for IEEE 1588-2002 Precision Time Protocol (PTP)
– Full- and half-duplex for both 100 Mbps and 10 Mbps operation
– Integrated 10/100 Mbps Transceiver (PHY)
– Automatic MDI/MDI-X cross-over correction
– Programmable MAC address
– Power-saving and power-down modes
1.6 Synchronous Serial Interface (SSI)
– Master or slave operation
– Programmable clock bit rate and prescale
– Separate transmit and receive FIFOs, 16 bits wide, 8 locations deep
– Programmable interface operation for Freescale SPI, MICROWIRE, or Texas Instruments synchronous serial interfaces
Trang 44
– Programmable data frame size from 4 to 16 bits
– Internal loopback test mode for diagnostic/debug testing
1.7 UART
– Two fully programmable 16C550-type UARTs with IrDA support
– Separate 16x8 transmit (TX) and 16x12 receive (RX) FIFOs to reduce CPU interrupt service
loading
– Programmable baud-rate generator allowing speeds up to 3.125 Mbps
– Programmable FIFO length, including 1-byte deep operation providing conventional double-buffered interface
– FIFO trigger levels of 1/8, 1/4, 1/2, 3/4, and 7/8
– Standard asynchronous communication bits for start, stop, and parity
– False-start-bit detection
– Line-break generation and detection
1.8 ADC
– Single- and differential-input configurations
– Four 10-bit channels (inputs) when used as single-ended inputs
– Sample rate of 500 thousand samples/second
– Flexible, configurable analog-to-digital conversion
– €Four programmable sample conversion sequences from one to eight entries long, with
corresponding conversion result FIFOs
– Each sequence triggered by software or internal event (timers, analog comparators, PWM
or GPIO)
– On-chip temperature sensor
1.9 Analog Comparators
– One integrated analog comparator
– Configurable for output to: drive an output pin, generate an interrupt, or initiate an ADC sample
sequence
– Compare external pin input to external pin input or to internal programmable voltage reference
1.10.I2C
– Master and slave receive and transmit operation with transmission speed up to 100 Kbps in Standard mode and 400 Kbps in Fast mode
– Interrupt generation
– Master with arbitration and clock synchronization, multimaster support, and 7-bit
addressing
mode
1.11 PWM
Trang 55
– Three PWM generator blocks, each with one 16-bit counter, two comparators, a PWM generator, and a dead-band generator
– One 16-bit counter
• Runs in Down or Up/Down mode
• Output frequency controlled by a 16-bit load value
• Load value updates can be synchronized
• Produces output signals at zero and load value
– Two PWM comparators
• Comparator value updates can be synchronized
• Produces output signals on match
– PWM generator
• Output PWM signal is constructed based on actions taken as a result of the counter and PWM comparator output signals
• Produces two independent PWM signals
– Dead-band generator
• Produces two PWM signals with programmable dead-band delays suitable for driving a half-H bridge
• Can be bypassed, leaving input PWM signals unmodified
– Flexible output control block with PWM output enable of each PWM signal
• PWM output enable of each PWM signal
• Optional output inversion of each PWM signal (polarity control)
• Optional fault handling for each PWM signal
• Synchronization of timers in the PWM generator blocks
• Synchronization of timer/comparator updates across the PWM generator blocks
• Interrupt status summary of the PWM generator blocks
– Can initiate an ADC sample sequence
1.12 QEI
– Two QEI modules
– Hardware position integrator tracks the encoder position
– Velocity capture using built-in timer
– The input frequency of the QEI inputs may be as high as 1/4 of the processor frequency (for
example, 12.5 MHz PhA/PhB/IDX for a 50-MHz system)
– Interrupt generation on index pulse, velocity-timer expiration, direction change, and quadrature
error detection
1.13.GPIOs
– 5-42 GPIOs, depending on configuration
– 5-V-tolerant input/outputs
– Programmable interrupt generation as either edge-triggered or level-sensitive
– Low interrupt latency; as low as 6 cycles and never more than 12 cycles
– Bit masking in both read and write operations through address lines
Trang 66
– Can initiate an ADC sample sequence
– Pins configured as digital inputs are Schmitt-triggered
– Programmable control for GPIO pad configuration:
• Weak pull-up or pull-down resistors
• 2-mA, 4-mA, and 8-mA pad drive for digital communication; up to four pads can be
configured with an 18-mA pad drive for high-current applications
• Slew rate control for the 8-mA drive
• Open drain enables
• Digital input enables
1.14 Power
– On-chip Low Drop-Out (LDO) voltage regulator, with programmable output
user-adjustable
from 2.25 V to 2.75 V
– Hibernation module handles the power-up/down 3.3 V sequencing and control for the core digital logic and analog circuits
– Low-power options on controller: Sleep and Deep-sleep modes
– Low-power options for peripherals: software controls shutdown of individual peripherals – User-enabled LDO unregulated voltage detection and automatic reset
– 3.3-V supply brown-out detection and reporting via interrupt or reset
■ Flexible Reset Sources
– Power-on reset (POR)
– Reset pin assertion
– Brown-out (BOR) detector alerts to system power drops
– Software reset
– Watchdog timer reset
– Internal low drop-out (LDO) regulator output goes unregulated
■ Additional Features
– Six reset sources
– Programmable clock source control
– Clock gating to individual peripherals for power savings
– IEEE 1149.1-1990 compliant Test Access Port (TAP) controller
– Debug access via JTAG and Serial Wire interfaces
– Full JTAG boundary scan
■ Industrial and extended temperature 100-pin RoHS-compliant LQFP package
■ Industrial-range 108-ball RoHS-compliant BGA package
Trang 77
Trang 88
2 Thư viện điều khiển ngoại vi Stellaris®
(Stellaris® Peripheral Driver Library)
2.1 Điều khiển hệ thống (19 System Control)
1.1 Giới thiệu
1.2 Mô tả chi tiết
- Các sysctl API được chia thành tám nhóm chức năng: Nhóm cung cấp thông tin thiết bị, nhóm nguồn xung clock của các thiết bị, những người cung cấp điều khiển thiết bị ngoại vi
1.2.1 Thông tin về các thiết bị được cung cấp bởi
SysCtlSRAMSizeGet (),
SysCtlFlashSizeGet (),
SysCtlPeripheralPresent (),
SysCtlPinPresent ()
1.2.2 Clocking của thiết bị
Cấu hình với:
SysCtlClockSet () và SysCtlPWMClockSet ()
Thông tin về bộ phát xung của thiết bị được cung cấp bởi:
SysCtlClockGet () và SysCtlPWMClockGet ().
1.2.3 Thiết bị ngoại được cho phép hay thiết lập lại bằng các thanh ghi:
SysCtlPeripheralReset() , SysCtlPeripheralEnable() ,
SysCtlPeripheralDisable() , SysCtlPeripheralSleepEnable() ,
SysCtlPeripheralSleepDisable() ,
SysCtlPeripheralDeepSleepEnable() , SysCtlPeripheralDeepSleepDisable() , and SysCtlPeripheral-
ClockGating()
1.2.4 Điều khiển hệ thống với ngắt: SysCtlIntRegister(), SysCtlIntUnregister(),
SysCtlIntEnable(), SysCtlIntDisable(), SysCtlIntClear(), SysCtlIntStatus().
1.2.5 LDO được điều khiển với SysCtlLDOSet() và SysCtlLDOConfigSet() Trạng
thái LDO được cung cấp bởi SysCtlLDOGet()
1.2.6 Thiết bị được chuyển sang chế độ ngủ với SysCtlSleep() and
SysCtlDeepSleep().
Trang 99
1.2.7 Các nguyên nhân Reset được quản lý bởi SysCtlResetCauseGet() and
SysCtlResetCauseClear() Reset bằng phần mềm được thực hiện bởi
SysCtlReset() Reset dobrown-out được cấu hình với
SysCtlBrownOutConfigSet()
1.2.8 Xác minh nguồn xung nhịp của các bộ đếm được quản lý
bởi SysCtlIOSCVerificationSet(), SysCtlMOSCVerificationSet(),
SysCtlPLLVerificationSet(), and SysCtlClkVerificationClear()
2.2 Điều khiển vào/ra 9 GPIO
2.1 Giới thiệu:
- Có thể được cấu hình như một đầu vào hoặc đầu ra Khi Reset, GPIO mặc định là một đầu vào Trong chế độ đầu vào, có thể tạo ra ngắt ở mức cao, mức thấp, sườn lên , sườn xuống hoặc cả hai cạnh
- Trong chế độ đầu ra, có thể được cấu hình cho 2 mA, 4 mA, hoặc 8mA
- Reset, GPIO mặc đầu ra có dòng là 2 mA Tùy chọn trở kéo lên hoặc kéo xuống
- Hoạt động mở cống tùy chọn Ngày thiết lập lại, họ mặc định để hoạt động push / pull chuẩn Có thể được cấu hình là một GPIO hoặc một pin thiết bị ngoại vi Ngày thiết lập lại, họ mặc định là GPIOs
- Lưu ý rằng không phải tất cả các chân trên tất cả các bộ phận có chức năng ngoại
vi, trong trường hợp này là pin chỉ hữu ích như là một GPIO (có nghĩa là, khi cấu hình cho chức năng ngoại vi pin sẽ không làm bất cứ điều gì hữu ích)
2.2 Mô tả chi tiết
Các GPIO API được chia thành ba nhóm chức năng: cấu hình các GPIO chân, liên quan đến hoạt động ngắt, và những chức năng truy cập vào các giá trị các chân
2.2.1 Các chân GPIO được cấu hình bới GPIODirModeSet() and
GPIOPadConfigSet() Các cấu hình có thể được đọc về bởi GPIODirModeGet() and GPIOPadConfigGet() Ngoài ra còn có các chức năng thuận tiện cho việc cấu hình pin cho việc cấu hình theo yêu cầu hoặc đề nghị của ngoại vi đặc biệt:
GPIOPinTypeCAN(), GPIOPinTypeComparator(), GPIOPinTypeGPIOInput(),
GPIOPinTypeGPIOOutput(), GPIOPinTypeGPIOOutputOD(), GPIOPinTypeI2C(), GPIOPinTypePWM(),
GPIOPinTypeQEI(), GPIOPinTypeSSI(), GPIOPinTypeTimer(), and GPIOPin-
TypeUART()
Trang 1010
2.2.2 Các ngắt GPIO được xử lý với GPIOIntTypeSet(), GPIOIntTypeGet(), GPIOPinIntEnable(),
GPIOPinIntDisable(), GPIOPinIntStatus(), GPIOPinIntClear(),
GPIOPortIntRegister(), and GPIOPortIntUnregister()
2.2.3 Trạng thái chân GPIO được truy cập bởi GPIOPinRead() and
GPIOPinWrite().
2.3 Điều khiển ngắt
3.1 Giới thiệu:
3.2 Mô tả chi tiết
3.2.1 Xử lý ngắt được quản lý với IntRegister () và IntUnregister ()
3.2.2 Mỗi nguồn ngắt có thể được kích hoạt và vô hiệu hóa thông qua
IntEnable() and IntDisable(); Các bộ xử lý ngắt có thể được kích hoạt và vô hiệu hóa thông qua IntMasterEnable() and IntMasterDisable();
3.2.3.Các ưu tiên của từng nguồn ngắt có thể được thiết lập và xem xét thông qua IntPrioritySet() and IntPriorityGet().
2.4 Điều khiển LCD OLED
2.5 Chuyển đổi tương tự - số ADC
5.1 Giới thiệu:
5.2 Mô tả chi tiết
Thư viên API của ADC được chia thành 3 nhóm chức năng:
5.2.1 Chức năng với các mẫu
- Cấu hình các chuỗi mẫu: ADCSequenceConfigure() and
ADCSequenceStepConfigure()
- Cấm hoạc cho phép : ADCSequenceEnable() and ADCSequenceDisable()
Trang 1111
- Thu dữ liệu từ bộ chuyển đổi: ADCSequenceDataGet().
5.2.2 Chức năng kích hoạt bộ xử lý
- Tín hiệu kích hoạt từ vi xử lý được tạo ra bởi : ADCProcessorTrigger().
5.2.3 Chức năng với ngắt
- Quản lý nguồn ngắt ADCIntDisable(),ADCIntEnable(), ADCIntStatus(), and ADCIntClear()
Trang 1212
3 Các bước thiết kế ứng dụng
3.1 Thiết kế ứng dụng với GPIO
Bước 1 Thiết lập hệ thống
- Thiết lập bộ dao động bằng lệnh SysCtlClockSet();
SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_OSC|SYSCTL_XTAL_8 MHZ|SYSCTL_OSC_MAIN);
- Cho phép PORT GPIO tương ứng hoạt động bằng lệnh
SysCtlPeripheralEnable();
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
Bước 2 Thiết lập cho các GPIO
- Lựa chọn hướng dữ liệu cho các PIN bằng 1 trong 2 lệnh
GPIOPinTypeGPIOInput();GPIOPinTypeGPIOOutput();
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_0);
GPIOPinTypeGPIOInput(GPIO_PORTF_BASE,GPIO_PIN_1);
- Cấu hình các đặc tính điện cho các PIN bằng hàm: GPIOPadConfigSet()
GPIOPadConfigSet(GPIO_PORTF_BASE,GPIO_PIN_1,GPIO_STRENGTH_2
MA, GPIO_PIN_TYPE_STD_WPU);
Bước 3 Ghi đọc dữ liệu
- Đọc dữ liệu: GPIOPinRead();
- Ghi dữ liệu: GPIOPinWrite();