PRJ2UC: Microcontrollers

Slides:



Advertisements
Similar presentations
Asst. Prof. Dr. Alper ŞİŞMAN
Advertisements

Digital Thermostat and Data Logger Brandon Wagner and David Southwick.
PWM What is PWM signal? A square wave form with two parameters: 1. PWM period (T PWM ) and 2. Duty cycle (d)
7-1 Digital Serial Input/Output Two basic approaches  Synchronous shared common clock signal all devices synchronised with the shared clock signal data.
Asst. Prof. Dr. Alper ŞİŞMAN
External & internal Interrupts. Interrupt Sources There are 21 different interrupts and each one has its own vector located in a predefined location at.
2.0 EMBEDDED CONTROLLER Engr. Hj. Mohamad Fauzi bin Zakaria Department of Mechatronics and Robotics Engineering Faculty of Electrical and Electronic Engineering.
4.0 rtos implementation part II
Digilent System Board Capabilities Serial Port (RS-232) Parallel Port 1 Pushbutton Hint: Good for a reset button Connected to a clock input. See Digilent.
1 4-Integrating Peripherals in Embedded Systems. 2 Introduction Single-purpose processors  Performs specific computation task  Custom single-purpose.
Volume. 1-the idea of the program is to increase, decrease the volume. 2-the program does the following: A-PF8:decrease the volume B-Pf9:increase the.
1 ARM University Program Copyright © ARM Ltd 2013 General Purpose I/O.
1 ARM University Program Copyright © ARM Ltd 2013 General Purpose I/O.
Universal Asynchronous Receiver/Transmitter (UART)
Microcontroller based system design Asst. Prof. Dr. Alper ŞİŞMAN.
1 LHO 13 The 8051CF020 and the University Daughter Card.
NS Training Hardware. Serial Controller - UART.
1 General Purpose and Alternate Function I/O (GPIO and AFIO)
ATtiny23131 A SEMINAR ON AVR MICROCONTROLLER ATtiny2313.
Embedded Network Interface (ENI). What is ENI? Embedded Network Interface Originally called DPO (Digital Product Option) card Printer without network.
Team 2 Yimin Xiao Jintao Zhang Bo Yuan Yang.  The project we propose is a digital oscilloscope with playback function that provides almost any function.
7 - 1 Texas Instruments Incorporated Module 7 : Serial Peripheral Interface C28x 32-Bit-Digital Signal Controller TMS320F2812.
© 2009, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction  Purpose:  This course provides an overview of the serial communication.
ECE Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560.
1-3 GPIO_Output(LuminaryLibrary) 1.Alter the output current to 4mA 2.Let LED0 turn on but LED 1 turn off. Modify your program in E:\yourname\arm.
Presented by: © 2015 Jacob Beningo All Rights Reserved Writing Portable and Robust Firmware in C September 2, 2015 Jacob Beningo, CSDP Class 3: Uart Driver.
Communicating. The ATmega16 communicates through one of the following ways: Serial Peripheral Interface (SPI) Universal Synchronous and Asynchronous serial.
Praxis I.  Introduction  Hardware  Software Tools  Microcontroller board  Blinky (simple program to flash a led)  References.
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
Tiva C TM4C123GH6PM UART Embedded Systems ECE 4437 Fall 2015 Team 2:
1 Lab 4: D/A Converter Lab 4: D/A Converter This is a simple resistive network for a D/A converter Port 1, Port 0 are digital inputs ==> 00 (minimum),
1 The LPC1768 Architecture (with focus on Cortex-M3)
PRJ2: ESP2-UC workshop 1 Introductie 1.
Application Case Study Christmas Lights Controller
Arduino.
Lizard Labs Peripheral Reflex System
Chip Config & Drivers – Required Drivers:
Outline Introduction to NuMaker TRIO Programming environment setup
Lab 7 Basic 1: Game of Memory
Assist. Prof. Rassim Suliyev - SDU 2017
CS4101 嵌入式系統概論 General Purpose IO
Peripherals and CMSIS STM32F4, Cortex M
Workshop 3. Digital-to-analog and analog-to digital conversion
Microcontrollers & GPIO
Slides developed in part by Mark Brehob & Prabal Dutta
Chapter 6 General Purpose Input/Output
Refer to Chapter 10 in the reference book
4-Integrating Peripherals in Embedded Systems
NS Training Hardware.
4-Integrating Peripherals in Embedded Systems
Programming Microcontroller ADC – Analog Digital Converter
CS4101 嵌入式系統概論 General Purpose IO
COMP2121: Microprocessors and Interfacing
ARM Cortex-M4 Combines DSP and microcontroller features
Embedded Systems Software Training Center
E3165 DIGITAL ELECTRONIC SYSTEM
Blinking an LED Using MSP430ware to Control GPIO
Programming Microcontroller
The Arduino Microcontroller: Atmel AVR Atmega 328
STM Arm I/O Programming
SPI Protocol and DAC Interfacing
UART Serial Port Programming
CS-4540 Robotics - Lab 05 Switch inputs to the Arduino Uno
Designing with ARM Cortex-M4 (and a Real Dev Board)
NS Training Hardware.
CSCI1600: Embedded and Real Time Software
8051 Micro Controller.
CSCI1600: Embedded and Real Time Software
Wireless Embedded Systems
Embedded System Design Techniques™:
Presentation transcript:

PRJ2UC: Microcontrollers workshop 3 Std. Periph. Driver Lib.

Today Standard Peripheral Driver Library Blinky with STM32F0-Discovery LED & PB functions USART with Std. Periph. Driver Lib.

Standard Peripheral Drivers Library Today Standard Peripheral Drivers Library Blinky with STM32F0-Discovery LED & PB functions USART with Std. Periph. Driver Lib.

Cortex Microcontroller Software Interface Standard (CMSIS) SRAM main application USART GPIO ??? drivers CMSIS STM32F05x Processor & Peripherals

Standard Peripheral Drivers Library SRAM main application STM32F0-Discovery LED & PB functions STM Std Periph Lib GPIO STM Std Periph Lib MISC STM Std Periph Lib RCC STM Std Periph Lib SYSCFG STM Std Periph Lib EXTI CMSIS STM32F05x Processor & Peripherals

Today Standard Peripheral Drivers Library Blinky with STM32F0-Discovery LED & PB functions USART with Std. Periph. Driver Lib.

Two files: STM32F0 LED & PB functions stm32f0-discovery.c stm32f0-discovery.h

STM32F0 LED & PB functions typedef enum { LED3 = 0, LED4 = 1 /** @defgroup STM32F0_DISCOVERY_LOW_LEVEL_Exported_Types */ typedef enum { LED3 = 0, LED4 = 1 } Led_TypeDef; /** @defgroup STM32F0_DISCOVERY_LOW_LEVEL_Exported_Functions void STM_EVAL_LEDInit(Led_TypeDef Led); void STM_EVAL_LEDOn(Led_TypeDef Led); void STM_EVAL_LEDOff(Led_TypeDef Led); void STM_EVAL_LEDToggle(Led_TypeDef Led); void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode); uint32_t STM_EVAL_PBGetState(Button_TypeDef Button);

STM32F0 LED & PB functions - example #include "stm32f0xx.h" #include "stm32f0_discovery.h" int main(void) { // Configure LED3 on STM32F0-Discovery STM_EVAL_LEDInit(LED3); while(1) STM_EVAL_LEDToggle(LED3); delay(SystemCoreClock/8); // Delay 1 sec. }

Standard Peripheral Drivers Library SRAM main application STM32F0 LED & PB functions STM Std Periph Lib GPIO STM Std Periph Lib MISC STM Std Periph Lib RCC STM Std Periph Lib SYSCFG STM Std Periph Lib EXTI CMSIS STM32F05x Processor & Peripherals

StdLib. is used in stm32f0_discovery.c /* Configures LED GPIO */ void STM_EVAL_LEDInit( Led_TypeDef Led ) { GPIO_InitTypeDef GPIO_InitStructure; /* Enable the GPIO_LED Clock */ RCC_AHBPeriphClockCmd( GPIO_CLK[Led], ENABLE ); /* Configure the GPIO_LED pin */ GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led]; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure); } General use of StdLib.: 1. Declare peripheral specific struct(s) 2. Fill the struct(s) with parameters 3. Call function(s) with struct(s) as a parameter

GPIO stm32f0xx_gpio.c /* @file stm32f0xx_gpio.c ================================================================= ##### How to use this driver ##### ================================================================= [..] (#) Enable the GPIO AHB clock using RCC_AHBPeriphClockCmd() (#) Configure the GPIO pin(s) using GPIO_Init() Four possible configuration are available for each pin: (++) Input: Floating, Pull-up, Pull-down. (++) Output: Push-Pull (Pull-up, Pull-down or no Pull) Open Drain (Pull-up, Pull-down or no Pull). In output mode, the speed is configurable: Low, Medium, Fast orHigh. (++) Alternate Function: Push-Pull (Pull-up, Pull-down or no Pull) (++) Analog: required mode when a pin is to be used as ADC channel, DAC output or comparator input. (#) Peripherals alternate function: …

Assignment Use STM_EVAL_PBGetState() to toggle the blue LED each time the blue Push Button is pressed. Remember to first initialize the pushbutton. Change the 'STM32F0Discovery LED & PB functions' so that besides using LED3 and LED4 (see Led_TypeDef in stm32f0_discovery.h) to select a LED, you can also use LED_GREEN and LED_BLUE. E.g.: STM_EVAL_LEDToggle(LED_GREEN);

Assignment – extra Add a new red LED to the 'STM32F0Discovery LED & PB functions' (see files stm32f0_discovery.h and stm32f0_discovery.c): The LED is connected to PB0. The LED is defined as LED5 (and/or as LED_RED). The LED is on with a logic 1. Test your implementation (remember to use a resistor in series) using the following function calls: STM_EVAL_LEDInit(LED5); STM_EVAL_LEDOn(LED5); STM_EVAL_LEDOff(LED5); STM_EVAL_LEDToggle(LED5);

Today Standard Peripheral Drivers Library Blinky with STM32F0-Discovery LED & PB functions USART with Std. Periph. Driver Lib.

USART stm32f0xx_usart.c /* @file stm32f0xx_usart.c ================================================================= ##### How to use this driver ##### ================================================================= [..] (#) Enable peripheral clock using RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE) function for USART1 or using RCC_APB1PeriphClockCmd(RCC_APB1Periph_USARTx, ENABLE) function for USART2 and USART3. (#) According to the USART mode, enable the GPIO clocks using RCC_AHBPeriphClockCmd() function. (The I/O can be TX, RX, CTS, or and SCLK). (#) Peripheral's alternate function: (++) Connect the pin to the desired peripherals' Alternate Function (AF) using GPIO_PinAFConfig() function. (++) Configure the desired pin in alternate function by: GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF. (++) Select the type, pull-up/pull-down and output speed via GPIO_PuPd, GPIO_OType and GPIO_Speed members. (++) Call GPIO_Init() function. (#) Program the Baud Rate, Word Length , Stop Bit, Parity, Hardware flow control and Mode(Receiver/Transmitter) using the SPI_Init() function. (#) For synchronous mode, enable the clock and program the polarity, phase and last bit using the USART_ClockInit() function. (#) Enable the NVIC and the corresponding interrupt using the function USART_ITConfig() if you need to use interrupt mode. (#) When using the DMA mode: (++) Configure the DMA using DMA_Init() function. (++) Active the needed channel Request using USART_DMACmd() function. (#) Enable the USART using the USART_Cmd() function. (#) Enable the DMA using the DMA_Cmd() function, when using DMA mode.

USART (I) int main(void) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; uint16_t c; // Initialize USART1 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); // Setup Tx- and Rx pin GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1); GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1); 1. 2. 3.

USART (II) //fill with default values USART_StructInit(&USART_InitStructure); USART_InitStructure.USART_BaudRate = 115200; USART_Init(USART1, &USART_InitStructure); USART_Cmd(USART1, ENABLE); while(1) { // Transmit information: "Press a key: " while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET){} USART_SendData(USART1, 'P'); // Etc. ... // Receive data while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET){} c = USART_ReceiveData(USART1); 2. 3.

Use the example project to: Implement the following functions: Assignment Use the example project to: Implement the following functions: void USART_SendString(USART_TypeDef* USARTx, char *p); void USART_ReceiveString(USART_TypeDef* USARTx, char *p); Extra Implement auto baud rate detection. Check the peripheral driver library for functions that can be used with respect to this feature.

Assignment: Use Std. Periph. Driver Library Demonstrate next week per team: TIP: Use interrupts for pushbutton (and USART?) STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI); Putty STM32F0-Discovery “blue on” Blue LED on “blue off” Blue LED off “blue toggle” Blue LED toggle “green n” with n=1..9 Green LED blink with n Hz STM32F0-Discovery Putty Blue pushbutton pressed “Blue pushbutton pressed”