1. Configure the general purpose input-output of the ARM microcontroller to match the circuitry available on the Keil ARM EVB.
2. To write a small program that monitors the input switches and controls the LEDs on the EVB. 16.3.2. Introduction
Microcontrollers are used to monitor and control physical systems. Systems may be very simple such as using a transducer to detect when the temperature reaches some critical value and at that point drive some circuitry to turn on cooling. While the system being monitored/controlled may be very complex the process can be simulated by having the firmware monitor an on-off switch and depending upon the result control an LED. In a real system the challenge for the hardware engineer is the circuitry to interface the microcontroller to the external world while for the software engineer the challenge is usually the magnitude of the number of inputs and outputs required by a real system.
The ARM EVB has a set of LEDs wired to bits 8 to 15 of PortE plus 3 push button switches labelled User (PB7), Tamper (PC13) and WakeUp (PA0) that may be used to simulate user on-off inputs 156 . See figure 16.10
156 To implement the Tamper and WakeUp functions the microcontroller alternative functions must be implemented. Until this is done these two switches may be treated as general purpose input. The joystick also provides a push function (pin PD11) so it could also be used. Probe Pin 10K 100nF USER PB7 TAMPER PC13 RESET 1K 220K WAKE UP PA0 Page 250 of 526 13/12/2011 1. STMicroelectronics: RM0008 Reference manual for the STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xx and STM32F107xx advanced ARM-based 32-bit MCUs Available on the Keil site as stm32f10_ref.pdf
2. STMicroelectronics: Data sheet for the STM32F105xx, STM32F107xx. Connectivity line, ARM-based 32-bit MCU with 64/256 KB Flash, USB OTG, Ethernet, 10 timers, 2 CANs, 2 ADCs, 14 communication interfaces Available on the Keil site as stm32f105(7)_data.pdf
4. Joseph Yiu. The Definitive Guide to the ARM-Cortex M3 Second Edition. Newnes
5. Chapter on ARM-IO in Embedded Microprocessor Systems by J.Kneen 16.3.4. Preliminary.
Section 16.3.9 gives the starting code for this laboratory. It includes turning the LEDs on and off. The code is a smaller version of that used in the previous laboratories. In the previous laboratories the LEDs flashed so quickly they could not be detected.
1. Part of this laboratory will require turning the LEDs on and off at a visible rate. From your results to section 16.1.6 estimate the initial value of R0 in the following code fragment to give a visible delay.
Delay ADDS R0,#-1 ;note minus 1 BNE Delay
To initialise R0 the code might be of the form mov #constant. To keep the instruction within a 32 bit word 157 the ARM limits the value of constant.
2. From reference 3 STM32F10xxx Cortex-M3 programming manual read section 3.3.3 and document the restrictions on the value of constant. 158
The USER switch in this laboratory is wired to GPIOB. This will require GPIOB to be configured. (See preliminary 4)
3. Complete tables 16.11 and 16.12 159 .
157 The ARM is a RISC reduced instruction set computer. It limits the number of instructions in order to achieve higher speed. If 32 bit operands were allowed this would require two visits to memory which would degrade the performance. 158 To overcome this restriction the instruction to initialise r0 will be ldr r0,=constant. 159 While students are only required to add code for GPIOB in this laboratory the additional information is given for completeness and later reference. Page 251 of 526 13/12/2011
Port Base Address Clock Enable Bit in RCC_APB2ENR (address 0x40021018) GPIOA GPIOB GPIOC GPIOD GPIOE
Figure 16.11. GPIO Base Address and Clock enables.
Register Mnemonic Address Offset Configuration Register Low GPIOx_CRL Configuration Register High GPIOx_CRH Input Data Register GPIOx_IDR Output Data Register GPIOx_ODR
Figure 16.12. Input output registers
Figure 16.13. Code to test switch.
4. Using the code provided in section 16.3.9 as a guide read through the chapter on the ARM_IO and then develop the code to configure 160 the pin/port containing the user switch.
160 Note that the ARM internal clock is being used so the first step will be enabling the peripheral bus clock to the port to be used. Read the port with the switch. Mask/isolate the switch bit. Turn off LEDs code given Label Loop Switch Pressed Page 252 of 526 13/12/2011 5. Develop the code to implement the flow chart of figure 16.13. Note in the procedure this code will inserted after the LEDs have been turned on. The LEDs will remain on when the switch is pressed. 16.3.5. Procedure
1. Start a new project in the Keil development environment. The Keil start up code is not required. Save the project as Lab03.
Create the sample program Lab03.s given in section 16.3.9.
2. Insert the code from the preliminary for a visible delay and test. Use the MSO to accurately measure your delay.
3. Modify your code to read the switch. Using the code as given the switch is only read once. To test it will be necessary to either single step or hold the switch down while re-running the code.
4. Modify your code to wait until the switch is pressed before turning the LEDs off.
The existing program includes 4 fragments:
(i) Code to turn the LEDs on and off (ii) Code to read an input switch (iii) Code to make a decision on the state of the switch, and (iv) A delay routine.
These fragments could be combined to form a simple state machine such as a pedestrian road crossing. The actual traffic lights (red-green-yellow) would replace the LEDs, the switch would be the request button and the delay would generate times that match those required by a real pedestrian crossing.
5. Re-program your code to implement the design of figure 16.14.
6. Your report will be enhanced with a MSO trace of your program. Take a trace with at least 3 channels:
(a) One channel probing the input switch (b) A second probe on one of the first group of LEDs (c) The third probe on one of the lower group of LEDs.
Page 253 of 526 13/12/2011
Figure 16.14. Flashing LEDs
16.3.6. Questions
1. Often several outputs need to be wired together in an open drain/collector configuration. What is open drain and how does it work? How may open drain be configured on one of the ARM output pins?
2. In this laboratory the switch is sampled at one instant of time. If this happened in, for example a pedestrian traffic light controller, the request could be missed. What is needed is a circuit that remembers that a switch has been pressed. It is suggested that the RS flip flop might be an appropriate component. Explain how the RS flip flop could be implemented in the design of a traffic light controller. 16.3.7. Report As well as summarising what you did and answering the questions your report should highlight any challenges the laboratory presented and how you overcame these. Consider you are writing a laboratory guide for other students. Attempt to document something to assist them with any problems you perceive they might have. Looking at the footnotes might provide some ideas for the type of extra material you can include. 16.3.8. Looking ahead For these laboratories assembly language has been used. In laboratory 16.4 using the C language with the ARM microcontroller will be introduced. The laboratory will also reinforce the work on the parallel ports by using a joystick to generate a range of inputs which will allow programming of many output options. 16.3.9. Appendix
Flash 4 LEDs in turn. Flash other 4 LEDs. Switch Pressed Page 254 of 526 13/12/2011 AREA RESET, DATA, READONLY EXPORT __Vectors __Vectors DCD 0x20000200 DCD Reset_Handler
AREA |.text|, CODE, READONLY EXPORT Reset_Handler ; Reset_Handler PROC mov r6,#0x40 ;enable clock to port E ldr r7,=RCC_APB2ENR str r6,[r7] mov r6,#0x33333333 ;configure port E - o/p to LEDs ldr r7,=GPIOE_CRH str r6,[r7] ; mov r6,#0xff00; ;turn LEDs on ldr r7,=GPIOE_ODR str r6,[r7] ;Insert your code here mov r6,#0x00; ;turn LEDs off ldr r7,=GPIOE_ODR str r6,[r7] Loop b Loop ENDP END