Introduction USART & AVR EVK1100

Similar documents
First Step From Download to the Programming

19.1. Unit 19. Serial Communications

Serial Communications

Writing your own program in AVR32 Studio

Interfacing a Hyper Terminal to the Flight 86 Kit

AVR32 UC3B Hands-on 01: Using Low-Level Drivers of the UC3B Software Framework

ECE 353 Lab 4. General MIDI Explorer. Professor Daniel Holcomb Fall 2015

Unit 19 - Serial Communications 19.1

Hands on Experience with AVR32

Serial Communications

Hello, and welcome to this presentation of the STM32 Low Power Universal Asynchronous Receiver/Transmitter interface. It covers the main features of

Tutorial Creating your own program in Atmel Studio 6

ECE251: Thursday November 8

Note that FLIP is an Atmel program supplied by Crossware with Atmel s permission.

To be familiar with the USART (RS-232) protocol. To be familiar with one type of internal storage system in PIC (EEPROM).

In the HEW, open a new project by selecting New workspace from the main menu.

Debugging in AVR32 Studio

Firmware Reprogramming Guide

Embedded Systems and Software

Hello, and welcome to this presentation of the STM32 Universal Synchronous/Asynchronous Receiver/Transmitter Interface. It covers the main features


Keyboards. The PS/2 Protocol

Learn how to communicate

USART. USART stands for Universal Synchronous Asynchronous Receiver Transmitter. Full-duplex NRZ asynchronous serial data transmission

Embedded Systems and Software. Serial Communication

Laboratory Finite State Machines and Serial Communication

UM2092 User manual. Basic metrology firmware for the STM32F103RD and the STPM32 devices. Introduction

Concepts of Serial Communication

SQI FLASH click. PID: MIKROE-2828 Weight: 22 g

8051 Timers and Serial Port

Innovati s Bluetooth 100M Universal Wireless Bluetooth Module

SKP16C26 Tutorial 1 Software Development Process using HEW. Renesas Technology America Inc.

UNIVERSITY OF CONNECTICUT. ECE 3411 Microprocessor Application Lab: Fall Quiz II

Lab Course Microcontroller Programming

EE 354 November 13, 2017 ARM UART Notes

Serial Communication Prof. James L. Frankel Harvard University. Version of 2:30 PM 6-Oct-2015 Copyright 2015 James L. Frankel. All rights reserved.

UART Devices. ECE 480: Design Team 3. Application Note. By: Hoyoung Jung. Date: 4/3/15

Microcontroller basics

EET203 MICROCONTROLLER SYSTEMS DESIGN Serial Port Interfacing

CN310 Microprocessor Systems Design

ISPV3 Programmer s Guide. This guide addresses the features, setup and operation of the CRD89C51xxx microcontrollers with ISPV3 firmware.

Serial Communication. Simplex Half-Duplex Duplex

ELCT706 MicroLab Session #4 UART Usage for Bluetooth connection PC - PIC

Laboratory 5 Communication Interfaces

Network Embedded Systems Sensor Networks Fall Hardware. Marcus Chang,

Universität Dortmund. IO and Peripheral Interfaces

CMS-8GP32. A Motorola MC68HC908GP32 Microcontroller Board. xiom anufacturing

MCS-51 Serial Port A T 8 9 C 5 2 1


Universal Asynchronous Receiver Transmitter Communication

UART: Universal Asynchronous Receiver & Transmitter

Embedded Systems. 3. Hardware Software Interface. Lothar Thiele. Computer Engineering and Networks Laboratory

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

Asynchronous Transmission. Asynchronous Serial Communications & UARTS

MICROPROCESSOR BASED SYSTEM DESIGN

Device: MOD This document Version: 1.0. Matches module version: v3 [29 June 2016] Date: 23 October 2017

Getting Started with STK200 Dragon

CprE 288 Introduction to Embedded Systems (UART Interface Overview)

Amarjeet Singh. January 30, 2012

Interrupts and Serial Communication on the PIC18F8520

Hierarchy of I/O Control Devices

Engineer-to-Engineer Note

XC2287 HOT. Exercise CAN_1 Communication using the CAN Module

Embedded Systems - FS 2018

Hello, and welcome to this presentation of the STM32L4 power controller. The STM32L4 s power management functions and all power modes will also be

DELPHI CORPORATION. LIN to RS-232 Gateway Systems Analysis INterface Tool (SAINT) Users Guide

Communication. Chirag Sangani

PSIM Tutorial. How to Use SCI for Real-Time Monitoring in F2833x Target. February Powersim Inc.

USER GUIDE EDBG. Description

INTRODUCTION TO FLEXIO

8051 Serial Port. EE4380 Fall02 Class 10. Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

ELCT706 MicroLab Session #4 UART Usage for Bluetooth connection PC - PIC

Basic SigmaDSP Microcontroller Integration

Universal Asynchronous Receiver / Transmitter (UART)

Serial Communication. Simplex Half-Duplex Duplex

AP16050 SAB C161V/K/O. Emulating an asynchronous serial interface (ASC) via software routines. Microcontrollers. Application Note, V 1.0, Feb.

EDBG. Description. Programmers and Debuggers USER GUIDE

18-349: Introduction to Embedded Real-Time Systems

Application Note. Title: Incorporating HMT050CC-C as a Digital Scale Display by: A.S. Date:

Lab 6 RS-232 Communication The following routines are provided for devices with a single USART peripheral:

Contents. List of Figures. TermDriver Datasheet 1. 1 Overview 2. 2 Features 2. 3 Installation with Arduino 3

XC2287M HOT. Solution ASC. Uses a timer triggered LED to toggle with ASC Interrupt

Embedded Systems - FS 2018

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso

Lecture 10. Serial Communication

Embedded systems. Exercise session 3. Microcontroller Programming Lab Preparation

FW UPGRADE SPECIFICATION

COMP2121: Microprocessors and Interfacing

LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI

Programming in the MAXQ environment

AVR XMEGA TM. A New Reference for 8/16-bit Microcontrollers. Ingar Fredriksen AVR Product Marketing Director

PS Telematik-Projekt: Wireless Embedded Systems

Emulating an asynchronous serial interface (ASC0) via software routines

Introduction to Microcontroller Apps for Amateur Radio Projects Using the HamStack Platform.

Cookery-Book, V1.0, February XMC1400 BootKit HelloWorld

RS 232 Interface. RS 232 is the Serial interface on the PC. Three major wires for the Serial interface: Transmit Pin 2 Receive Pin 3

UART. Introduction. Agenda

Sender Receiver Sender

AN HI-3200 Avionics Data Management Engine Evaluation Board Software Guide

AN-1435 APPLICATION NOTE

Transcription:

Introduction USART & AVR EVK1100

Time scope: 2-4h USART (Theory) Flash Development board EVK 1100 Basics for programming USART (Driver, Code) Exercises Emqopter GmbH 2

Terminology: UART, Universal Asynchronous Receiver Transmitter USART, Universal Synchronous Asynchronous Receiver Transmitter UART Є USART Indicates electronical part or interface Theory: Serial Communication (One bit after the other) Synchronous: With clock or handshake vs. Asynchronous: No clock Asynchronous Interfaces are cheap, simple and popular Supports Full-Duplex: Send (Tx) and Receive (Rx) simultaneous Connections: Tx (for sending), Rx (for receiving), CLK (synchronization), RTS (Request to Send), CTS (Clear to Send), Start Bit LSB 0 Bit 1. Bit 6 MSB 7 Parity Stop Bit = 0 Byte = 1 Emqopter GmbH 3

Asynchronous: Start bit (low) + Stop bit (high) -> Define frame The maximum Frame length is limited since synchronization gets lost otherwise. Important: Baud rate must be defined (equal to bit rate in this case) Synchronous: Measure (Clock, clk) (Hardware-)handshake (CTS, RTS) Start Bit LSB 0 Bit 1. Bit 6 MSB 7 Parity Stop Bit = 0 Byte = 1 Notice: Baud rate = Symbols / s or Characters / s Bit rate = bit / s symbol rate data transmission rate Emqopter GmbH 4

Flash-Memory: Digital memory (e.g. USB-Stick) Non-volatile UC3A0512: 512k Flash (EVK 1100) Flashing means writing the program into the flash memory Functionality (simplified): Data = charge on floating gate of MISFET (metal insulator (electrical) semiconductor field-effect transistor) Floating gate isolated by dielectric -> no flow off -> Isolated transistor Today: Multi-Level-Cell Memories Emqopter GmbH 5

Development board EVK 1100: Extensive periphery: USART, GPIOs, TWI, SPI, 3 Buttons, 1 Joystick button, Display, Micro processor: 32UC3A0512-U Emqopter GmbH 6

PIN Mapping: Pin assignment functions (A,B,C) Datasheet from p.45 Emqopter GmbH 7

Lets go! IDE: start AVR32 Studio Create example project: File -> New -> Other -> AVR Example Project Choose DIP 204 Example: -> AT32UC3A0512 -> EVK 1100 COMPONENTS DIP204 example Emqopter GmbH 8

Emqopter GmbH 9

Add Target Create a new target Properties (Right click on New Target ) In Details choose USB DFU and AT32UC3A0512 1 2 3 Emqopter GmbH 10

Flashing / Programming (4 steps: 1. + 2.) Power: Board gets power via USB from PC + Switch (green LED) Compile: compile project code via Build Project or Ctrl + B Check success of compiling 2 Right click on project 1 Emqopter GmbH 11

Flashing / Programming (4 Steps: 3.) Flash-Mode: prepare board for flashing: Press (C)ursor button + (R)eset button in the following order: Hold C pressed, then press R, release R, then release C. The Board is ready for flashing when MCU stops. This means the display and the LED1 to LED6 go out. Emqopter GmbH 12

Flashing / programming (4 Steps: 4.) Flashing: write program into the flash memory Right click on target -> program Select binary (*.elf file) from folder: AVR_Workspace / Project name / Debug Activate check boxes: Verify memory Start executing Erase flash Reset MCU Press OK Emqopter GmbH 13

Batchip Error: When flashing is not successful: Go to window -> preferences -> Tool Paths and add the following folder: C:\Program Files (x86)\atmel\flip 3.4.5\bin or C:\Program Files\Atmel\Flip 3.4.5\bin Emqopter GmbH 14

Hello World: Change display massage to Hello World Go to line 339 (Show line numbers via right click on left border) Write Hello World Repeat steps 1-4 for flashing Emqopter GmbH 15

Create new empty project: - File -> New -> AVR Project from Template - Start EVK 1100 application - Finish Emqopter GmbH 16

Add Drivers: - Framework -> Select Drivers / Components - Recommended driver configuration can be taken from next slide Emqopter GmbH 17

Add Drivers: - Recommended driver configuration: CPU, FLASHC, GPIO, INTC, PM, PWM, SPI, DIP204 (Page 2), Delay (Page 3) Emqopter GmbH 18

AVR32 Studio Bug with newly created projects: Some files of the framework are not included correctly after restart of AVR Studio. The problem will occur at the next start. So resolve it now before you forget the solution: Take the DIP example program as a template: File\New\Project -> AVR Example Project -> AT32UC3A0512 -> EVK1100 COMPONENTS DIP204 example Copy your code into the project: Select the whole code in main.c with ctrl + A and replace all the code in dip204_example.c or just copy/move the main.c file and delete dip204_example.c file After this, you can delete the newly created project and continue your work with the DIP example project. It is best to rename it right now. Recommendation: Copy and past the DIP example and work with it. So there are three ways to get it working: 1. Use a DIP 204 example project and change the code in dip204_example.c. 2. Use a DIP 204 example project, delete the code from dip204_example.c and add your code there. 3. Create a new project and copy the code from the main (.c) into a new DIP 204 example project. The newly created project and the dip204_example.c can be deleted afterwards. Emqopter GmbH 19

USART Introduction (Driver) Wanted function: USART_write(string); ne(avr32_usart_t *usart, char* string); // (see. usart.h / usart.c ) To do this you have to init avr32_usaframework offers: void usart_write_lirt_t & HW: Define and connect GPIO PINs & functions Initialize Oscillator / Clock for USART (USART is time-dependent) Initialize USART: Settings such as baud rate, stop bits, etc. Clock assignment: Which clock Assign USART & PINs: There are 4 USARTs and 102 GPIO PINs: Thereof about 40 PINs with USART functions Emqopter GmbH 20

Header/Include Files: IO Defines of processor (UC3A0512) #include <avr32/io.h> Compiler Defines such as type, etc. #include "compiler.h " Defines of the boards (EVK1100): LEDs, Buttons, etc. #include "board.h" Clock defines und functions: pcl_switch_to_osc() #include "power_clocks_lib.h " GPIO (PINS) Driver functions #include "gpio.h" USART Header with functions and so on #include "usart.h" Emqopter GmbH 21

USART Init Code: # define USART1 (&AVR32_USART1) static const gpio_map_t USART_GPIO_MAP = { {AVR32_USART1_RXD_0_0_PIN, AVR32_USART1_RXD_0_0_FUNCTION}, {AVR32_USART1_TXD_0_0_PIN, AVR32_USART1_TXD_0_0_FUNCTION} }; // USART PIN Mapping (Assignment<->Routing) static const usart_options_t USART_OPTIONS = {.baudrate = 57600,.charlength = 8,.paritytype = USART_NO_PARITY,.stopbits = USART_1_STOPBIT,.channelmode = USART_NORMAL_CHMODE }; // USART Options // configure Clock Osc0 with Startup Time pcl_switch_to_osc(pcl_osc0, FOSC0, OSC0_STARTUP); // PCL_OSC0 = Oczillator (Which), FOSC0 (Frequency, Hz) // OSC0_STARTUP = Start up time(time between init power // and stable clock // Assign GPIO to USART gpio_enable_module(usart_gpio_map, sizeof(usart_gpio_map) / sizeof(usart_gpio_map[0])); // Initialize USART in RS232 mode. usart_init_rs232(usart1, &USART_OPTIONS, FOSC0); Emqopter GmbH 22

USART functionality (code): Example program, for more information see usart.h usart_write_line(usart1, "Hello, this is EVKI! \n"); Send text via USART usart_write_char(usart1, 1); Send 1 usart_putchar(usart1, 2); Send 2 More code: int i; for (i = 0; i< 1000; i++); usart_write_char(usart1, 5); usart_write_char(usart1, 10); usart_write_char(usart1, 20); while(1); Emqopter GmbH 23

Hterm Terminal program Serial communication PC <-> MCU Connection establishment 1. Connect USART1 to PC 2. Lode and compile USART Example: EVK1100 EVK1100 DRIVERS USART example 3. Start Hterm 4. Set Baud rate to 57600 and press Connect 5. Flash MCU with USART example 6. Data should be received in Hterm 7. Send Enter. Enter is HEX: 0D Emqopter GmbH 24

What is part of the USART Driver / Code and what is its function? Include Files: Contains structures, functions, drivers, libraries, etc. &AVR32_USART1 = USART structure USART structure contains state variables of the USART USART structure can be used by define: easier, faster, saver, more maintainable Each USART has its fixed address in HW There are several USARTS (0-3). We use #0 and #1. Note label on EVK1100 and #number in the code! Mapping -> Which GPIO PINs contain which functions. Define TX and RX here. Create options-struct -> is being used by the init function Start oscillator -> Measure for USART (and other functionality) USART requires a measure. One oscillator can be used for everything. Do not start the oscillator twice USART Init (configure HW) Emqopter GmbH 25

Required hardware: EVK 1100 USART cable for communication: RS232 on PC (RS232 or USB) Micro USB cable for power supply and flashing Required software: AVR Studio 32 (with Tool Chain and FLIP Driver) Example code: main_usart.c Emqopter GmbH 26

Exercise 1a: Implement your own USART Example which is able to transmit a message via USART to the PC. Create your own project. You can use the example code from the framework, the code from the slides or the code from the example file main_usart.c. Try to understand the code first! Exercise 1b: Execute the example program (main_usart.c). Have a close look at the program code and the Hterm output. What do you notice? Explain! Exercise 2: Implement a counter. The counter value is to be transmitted continuously to the PC via USART. Emqopter GmbH 27

Important hints: How do I write a number? Create a String and send it to the PC! Fill a string using sprintf Required header: #include <stdio.h> A String is an array of chars char my_string[80]; Remember to reserve enough memory space for the string Be careful: sprintf does not check the memory for sufficiency! Create a number to write int number = 3; Create a String sprintf(my_string, My number is %d", number); Transmit a String usart_write_line(usart1, my_string); Emqopter GmbH 28

Exercise 3: Write a program that reads two numbers via USART, multiplies them and transmits the result via USART. Use a C function, which multiplies two input values and returns the result. Use a state machine for the main routine with the states WAIT_FOR_VALUE_1, WAIT_FOR_VALUE_2. Return the result and set the state machine on waiting for the first value after receiving the second value. Test your program extensively. Which numbers can not be multiplied? Think about a solution and implement it! Emqopter GmbH 29

Important hints: Send Character/Byte: usart_write_char(usart, int); Receive Character/Byte: usart_read_char(usart, int*); usart_read_char() does not wait usart_read_char() returns USART_SUCCESS if a Character (Byte) has been read successfully usart_read_char() returns other values when errors occur, or no data is available Code for state machine with Switch-Case: #define WAIT_FOR_VALUE_1 0 #define WAIT_FOR_VALUE_2 1 int state = WAIT_FOR_VALUE_1; switch(state){ case WAIT_FOR_VALUE_1 : // CODE break; } case WAIT_FOR_VALUE_2 : // CODE break; Emqopter GmbH 30