LAB: USART - LED, Bluetooth
Date: 2023-09-26
Author/Partner:
Github: repository link
Demo Video: Youtube link
PDF version:
Introduction
In this lab, we will learn how to configure and use ‘USART(Universal synchronous asynchronous receiver transmitter)’ of MCU. Then, we will learn how to communicate between your PC and MCU and MCU to another MCU with wired serial communication.
Mission 1: Control LED(LD2) of each other MCU.
Mission 2: Run DC motors with Bluetooth
You must submit
LAB Report (*.md & *.pdf)
Zip source files(main*.c, ecRCC.h, ecGPIO.h, ecSysTick.c etc...).
Only the source files. Do not submit project files
Requirement
Hardware
MCU
NUCLEO-F411RE
Actuator/Sensor/Others:
DC motor, DC motor driver(L9110s),
Bluetooth Module(HC-06),
Software
Keil uVision, CMSIS, EC_HAL library
Problem 0: STM-Arduino
Procedure
Create a new project under the directory
\EC\LAB\LAB_USART_LED
Follow the tutorial: U(S)ART (Universal Asynchronous/synchronous Receiver and Transmitter)
Problem 1: EC HAL library
Using HAL library
Download ecUART2_student.c ecUART2_student.h
Change the file names as
ecUART2.c
ecUART2.h
Fill in empty spaces in the code.
You must update your header files located in the directory EC\include\
.
ecUSART2.h
Example Code
Example 1
Example 2
General USART Setup
Problem 2: Communicate MCU1-MCU2 using RS-232
Procedure
1. Create a new project under the directory \repos\EC\LAB\LAB_USART_LED
The project name is “LAB_USART_LED”.
Create a new source files named as “LAB_USART_LED.c”
You MUST write your name on the source file inside the comment section.
2. Include your updated library in \repos\EC\include\
or \repos\EC\lib\
to your project.
ecUART2.h, ecUART2.c
Update ecSTM32F4v2.h
3. Connect each MCUs to each PC with USART 2 via USB cable (ST-Link)
MCU1 to PC1
MCU2 to PC2
4. Connect MCU1 to MCU2 with USART 1
connect RX/TX pins externally with jumper wires as
MCU1_TX to MCU2_RXD
MCU1_RX to MCU2_TX
Connect the same GND for MCU1-MCU2
MUST connect the same GND pin for MCU1 and MCU2
Send a message from PC_1 by typing keys on Teraterm. It should send that message from MCU_1 to MCU_2.
Note that you have to press "Enter" to end the message.
The received message by MCU_2 should be displayed on PC_2.
7. Turn other MCU's LED(LD2) On/OFF by sending text:
"L" for Turn OFF
"H" for Turn ON
Configuration
Type | Port - Pin | Configuration |
---|---|---|
System Clock | PLL 84MHz | |
USART2 : USB cable (ST-Link) | No Parity, 8-bit Data, 1-bit Stop bit, 38400 baud-rate | |
USART1 : MCU1 - MCU2 | TXD: PA9 RXD: PA10 | No Parity, 8-bit Data, 1-bit Stop bit, 38400 baud-rate |
Digital Out: LD2 | PA5 |
Code
Your code goes here: ADD Code LINK such as github
Explain your source code with necessary comments.
Result
Experiment images and results
Show experiment images /results
Add demo video link
Problem 3: Control DC Motor via Bluetooth
Bluetooth
Search for the bluetooth module specification sheet (HC-06) and study the pin configurations. The default PIN number is 1234.
Example of connecting to USART1
DC Motor Driver
Connect DC motor driver(L9110s) module pins to MCU as shown below.
DO NOT use MCU’s VCC to motor driver. You should use external voltage source.
A- IA: PWM pin (0~100% duty) for Motor A
A- IB: Direction Pin (Digital Out H or L) for Motor B
Procedure
1. Create a new project under the directory `\repos\EC\LAB\LAB_USART_Bluetooth
The project name is “LAB_USART_Bluetooth”.
Create a new source files named as “LAB_USART_Bluetooth.c”
You MUST write your name on the source file inside the comment section.
2. Include your updated library in \repos\EC\lib\
to your project.
ecGPIO.h, ecGPIO.c
ecRCC.h, ecRCC.c
ecUART.h, ecUART.c
ecTIM.h, ecTIM.c
3. Connect the MCU to PC via Bluetooth. Use USART 1
connect RX/TX pins as
MCU TXD - BLUE RXD
MCU RXD - BLUE TXD
Check the Bluetooth connection by turning MCU's LED(LD2) On/OFF by sending text of "L0" or "L1" from PC.
Run 2 DC motors(Left-wheel, Right-wheel) to steer.
Turn Left: MotorA / MotorB = (50 / 80%) duty
Turn Right: MotorA / MotorB = (80 / 50%) duty
Go straight: MotorA / MotorB = (80 / 80 %) duty
STOP: MotorA / MotorB = (0 / 0 %) duty
You may use the key inputs as your preference for Left, Right, Straight.
- Ex) ‘L’, ‘R’, 'U' 'S'
Configuration
Type | Port - Pin | Configuration |
---|---|---|
System Clock | PLL 84MHz | |
USART1 : MCU -Bluetooth | TXD: PA9 RXD: PA10 | No Parity, 8-bit Data, 1-bit Stop bit, 9600 baud-rate |
Digital Out: LD2 | PA5 | |
PWM (Motor A) | TIM2-Ch1 | PWM period (2kHz~10kHz) |
PWM (Motor B) | TIM2-Ch2 |
Code
Your code goes here: ADD Code LINK such as github
Explain your source code with necessary comments.
Result
Experiment images and results
Show experiment images /results
Add demo video link
Reference
Complete list of all references used (github, blog, paper, etc)
Troubleshooting
1. Cannot find my bluetooth module in my PC
Change your BT searching setting in your Window
Last updated