Starting from:
$30

$24

Laboratory Exercise #03 Button Input and Serial Communication Solution

1 Introduction




In this laboratory exercise you will write, compile, execute, and demonstrate a program to sense the push buttons on the LM3S1968 board, generate a tone, and communicate over the serial port.




This laboratory builds on Lab #01 (Blinky) and Lab #02 (SpeakerBuzz). You should make a copy of your Task_Blinky/SpeakerBuzz project and work with the copy in this lab.




The program will: (1) monitor the five push buttons on the LM3S1968, (2) generate a (distinct) tone when a button is pushed and released, and (3) report the button press via the serial port. Your program should continue to blink the LED and write the current value of SysTickCount to the OLED display. You will write a report describing your measurements, analyses, and conclusions.




1.1 LM3S1968 Evaluation Board Switches Background




The LM3S1968 evaluation board has five switches that can be used for user input, these are named Select (SW2), Up (SW3), Down (SW4), Left (SW5), and Right (SW6). When a switch is pressed, the corresponding GPIO input signal is pulled to Ground, i.e. a 0 input to your program.




1.1.1 Switch Bounce




When a switch is pressed, it does not generate a clean signal. That is, the signal may change from 1 - 0 - 1 - 0 - 1 - 0 before it settles at a 0 state. This is called switch bounce and is a characteristic of the switch mechanics. When the switch is released, it returns to a 1 state. Generally, there is no switch bounce when the switch is released. A typical GPIO signal might look like:











































Your program must compensate for switch bounce.




EECS 388 Laboratory #3
1
 
Version E







The five switches on LM3S1968 evaluation board are shown in the following figure:







































































































The figure is from: TI_Stellaris_LM3S1968_EvalBoard.pdf. The schematic shows the signals, e.g. RIGHT_SWn, are connected to ground when the switch is pressed. The GPIO port must provide a weak pull-up to bring the signal high when the switch is not pressed. The schematic shows that signals UP_SWn…SELECT_SWn are connected to PortG<3..7, respectively. Therefore, you will have to program GPIO PortG appropriately to read the buttons.




2 Laboratory Exercises




2.1 Before Laboratory Period(s)




Before you come to lab you should do the following:




Design your task and write pseudo-code describing your task. Submit your pseudo-code prior to your laboratory period according to your GTA’s instructions.



Write your task using a text editor. Make sure your task is well organized, well formatted, and documented.









EECS 388 Laboratory #3
2
 
Version E







Use the computers in the lab or computing commons to compile and debug your task.



Bring a printed version of your task to your lab.



You may use parts of the task you have run in lab or other programs. However, if you use code from any other program, you must cite the source of that code in your report.




You may ask questions about the lab in lecture.




2.2 In Lab




Show your lab instructor your printed listing of your task.



Demonstrate your task to the lab instructor.



Be prepared to answer questions about your task asked by your lab instructor.



2.3 Complete the Laboratory




Collect your measurements, logs, copies of your task in your directory, and clean up your lab bench. If you checked out a probe kit, make sure you return it to the EECS Shop immediately after you are finished in the lab.




Instructions for writing your report will be provided by your lab instructor.




3 Program Description




Your task will implement the following general activities (along with LED Blink and




SysTickCount reporting to the OLED):




Your task will monitor the five buttons on the evaluation board.



Your task will generate a tone when the switch press is detected and when the switch is released.



Your task will report the identity of the switch released via the serial communication port.



You do not have to account for more than one switch pressed at the same time nor for rapid, less than 2 Seconds interval, pressing of the switches.



3.1 Button Monitoring and Tone Generation




Your task will monitor the five buttons on the evaluation board. You shall check the button state once each 1 mS.



When a button transition is detected, your task shall wait 10 mS to insure the button is actually pressed. This is the de-bounce period.






EECS 388 Laboratory #3
3
 
Version E







When a button is pressed and switch bounce is compensated for, your program will emit a 440 Hz tone on the speaker for 0.2 Seconds.



When a button is released, your program will emit a 440 Hz tone for 0.5 Seconds and report the event via the UART. The message shall state: “Button <x released.\n.” Where <x is the identity of the button, e.g. “UP,” “DOWN,” … or “SELECT.”



4 Program Structure




4.1 Button Monitor Setup




You program must configure GPIO PortG to read the five buttons. The buttons are connected to PortG<7..3. The actions are:




Enable PortG with SysCtlPeripheralEnable.



Set PortG<7..3 pins to input with GPIOPinTypeGPIOInput() subroutine



from DriverLib.




Set PortG<7..3 pins to weak pull-up with GPIOPadConfigSet. You do not have to set the drive current on these pins.



4.2 Button Monitor




Your program must:




Read the state of the five buttons every 1 mS.



If a button is released, go to step 6.



If no button is pressed, exit.



If a button is pressed, wait 10 mS.



If the same button is pressed after 10mS, declare a button press and emit a 0.2 S tone at 440 Hz and exit.



On release of a button, emit a 0.5 S tone at 440 Hz and send a message using the UART.



4.3 UART Setup




UART0 is connected through GPIO PortA. You will use an API known as UARTStdio. This API and associated *.h is in your program “Drivers” directory. A subroutine will be provided to you to carry out this initialization.







The actions to set up UART0 and send a short message are:




//




Enable UART0, to be used as a serial console.



 



SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOA );




EECS 388 Laboratory #3
4
 
Version E




SysCtlPeripheralEnable( SYSCTL_PERIPH_UART0 );




GPIOPinConfigure( GPIO_PA0_U0RX );




GPIOPinConfigure( GPIO_PA1_U0TX );




GPIOPinTypeUART( GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1 );




UARTClockSourceSet( UART0_BASE, UART_CLOCK_SYSTEM );




//




Initialize UARTStdio



 



UARTStdioConfig( 0, 115200, SysCtlClockGet() );




4.4 UART Use




To output strings to the PC using UARTStdio, you use the UARTprintf function. It is similar, but simpler, than the common printf function. An example is:




UARTprintf( “Button: %d\n”, ButtonIndex );




UARTprintf is documented in the UARTStdio.c file.




4.5 COM setup on the Windows PC




See Appendix A for setting up serial communications on Windows PC machines.







































More products