Microprocessor and interfacing Lab Report 01, Study Guides, Projects, Research of Microprocessors

This is the Lab 01 of Microprocessor of Comsats University Islamabad

Typology: Study Guides, Projects, Research

2022/2023

Uploaded on 05/09/2023

arslan-bin-shabeer
arslan-bin-shabeer 🇵🇰

2 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Microprocessor Systems & Interfacing (EEE-342)
Lab # 11 Serial Communication with UART and
Interfacing Bluetooth HC-05
Name Arslan Shabeer
Registration Number FA20-BEE-033
Class BEE-5A
Instructor’s Name Sir Sikandar Gull SB
pf3
pf4
pf5

Partial preview of the text

Download Microprocessor and interfacing Lab Report 01 and more Study Guides, Projects, Research Microprocessors in PDF only on Docsity!

Microprocessor Systems & Interfacing (EEE-342)

Lab # 11 Serial Communication with UART and

Interfacing Bluetooth HC-

Name Arslan Shabeer

Registration Number FA20-BEE-

Class BEE-5A

Instructor’s Name

Sir Sikandar Gull SB

Objectives:

 To implement serial communication using UART of Atmega328p

 To establish Bluetooth connectivity between Atmega328p and an Android mobile device.

Pre-Lab: Serial Communication:

Microcontrollers must often exchange data with other microcontrollers or devices. Data may be

exchanged by using parallel or serial communication links. With parallel techniques, an entire

byte of data is typically sent simultaneously from the transmitting device to the receiver device.

Although this is efficient from a time point of view, it requires eight separate lines for the data

transfer. In serial transmission, a byte of data is sent a single bit at a time. Once 8 bits have been

received at the receiver, the data byte is reconstructed. Although this is inefficient from a time

point of view, it only requires a line (or two) to transmit the data.

In Lab: Task 1:

You will configure (i.e. set baud rate, frame format, parity settings etc ) UART present in

Atmega328P for Asynchronous Serial Communication. The rest of the code implements the

transmit and receive functionality and uses them in an echo back mechanism. This means that

the program waits for any data received on the UART receiver and then transmits it back.

SOLUTION:

Code:

#include <avr/io.h> // Most basic include files #include <avr/interrupt.h> // Add the necessary ones #include <util/delay.h> #include <string.h> #define F_CPU 16000000UL // a System clock of 16 MHz // ************** Definistion for USART ********************** #define BAUD 9600.00 // Baud Rate Declared as a float #define UBRR_VAL ( F_CPU /(16*BAUD))-1 // Corresponding UBRR Value //


void USART_Init(unsigned int ubrr); // function to Initialize the USART void USART_Transmit(unsigned char data); // Transmit Data via USART unsigned char USART_Receive(void); // Receive Data via USART void USART_send_str(char * string1); // Transmit a string void USART_read_str(char * ); // Read the USART buffer // ***********************************************************

ch = USART_Receive(); unsigned char i; str[i] = ch; } while(ch != '\0'); } Proteus Simulation: Task 2: Interfacing HC-05 Bluetooth device and Communicating with an Android Device

HC-05 is a module that is used to provide Bluetooth wireless connectivity to your

microcontrollers. HC-05 has a close cousin, the HC-06 also available in the market. Both devices

are Bluetooth transceiver modules but HC-05 can operate both as a Master or a Slave device

whereas HC-06 can only operate in the Slave mode. A Bluetooth master device can look for other

BT devices and then make a connection with them (called Paring in BT terminology). It is

recommended that you get an HC-05 device since the price is the same for the two modules.

Following figure shows the two modules side by side. The HC-05 has 6 pins compared to 5 pins of

HC-06.

Figure 11.4 HC-05 and HC-

Once paired with a device, the HC-05 acts as a communication bridge between the

microcontroller and the connected device.

Interfacing HC-05 with Arduino Nano

The following figure shows the electrical interface between the HC-05 and Arduino Nano. HC-

05 is powered from the 5V and the GND pins of the Arduino, the TX and RX pins of the module

are connected to D8 and D9 of the Arduino board.

Figure 11.5 Interfacing HC-05 with Arduino Nano

HC-05 and HC-06 operate in two modes.

1. Command Mode or AT mode

2. Communication Mode

Command mode is used to set configuration of the Bluetooth module (HC-05/06). These

configurations include baud rate , password , role (master/slave), address (unique for different

modules) etc. To start the module in this mode press and hold down the button on the corner of

the module when powering it. You can tell that the module is in communication mode by the

blinking of its LED. In communication mode, the LED will blink with a period of about 4 seconds.

The commands that can be issued to module are listed in the following link.

Critical Analysis / Conclusion:

Overall, this lab appears to provide a good introduction to serial communication using the

USART of the Atmega328p microcontroller. It covers the basic concepts of serial

communication, such as baud rate and frame format, and demonstrates how to use the

USART for transmitting and receiving data. The code also includes functions for sending and

reading strings, which can be useful for sending multiple bytes of data at once.

In this concerned lab, I have learnt a lot about how to implement serial communication

using UART of Atmega328p. This has been done successfully in task 1 where the code was

given and I understood it and filled the missing part and then successfully implemented it.

I also got to learn about how to establish bluetooth connectivity between Atmega328p and

an Android mobile device. I installed the app of Serial Monitor on my mobile phone and

implemented the task 2 of this Lab using it.