Peripherals and CMSIS STM32F4, Cortex M4 2016.

Slides:



Advertisements
Similar presentations
3-1 Peripherals & I/O lines All the on-chip peripherals are configured and controlled through Special Function Registers (SFR) Many of the SFR’s are bit.
Advertisements

Mark Neil - Microprocessor Course 1 Device Drivers – Digital Voltmeter.
Chung-Ta King National Tsing Hua University
STM32F10x Changes v1.5 to 1.4 HD added Changes v1.4 to 1.3
Lizard Labs Peripheral Reflex System
C Examples 1.
What is Arduino?  Arduino is a ATMEL 168 micro-controller kit designed specially for small projects  User friendly IDE(Integrated Development Environment)
PWM What is PWM signal? A square wave form with two parameters: 1. PWM period (T PWM ) and 2. Duty cycle (d)
10-1 Bard, Tiwari, Telang, Janapa Reddi, Gerstlauer, Valvano, Yerraballi EE 319K Introduction to Embedded Systems Lecture 10: Sampling, Analog-to-Digital.
Oscilloscope Watch Teardown. Agenda History and General overview Hardware design: – Block diagram and general overview – Choice of the microcontroller.
1 Lab2: A/D Converter. 2 This circuit connects a variable voltage to an A/D port on the AVR mcu. Your software running on the AVR mcu will read the digital.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
Decoding Barcodes Various approaches. Decoding barcodes There are a number of ways of decoding the barcodes –The data can be polled –The data can be read.
ASPPRATECH.
Block Diagram of 4518 Dual BCD Counter The 4518 Dual BCD Counter has two BCD counters. Each counter is similar to the other. Each counter has a master.
Lecture 9 Timer Operations and Programming. 2  Introduction  Summary of timers  Timer programming sequence  Summary of timer SFRs  Timer 0: 8-bit.
GPIO 碩一 李柏毅 陳政澤. overview Introduction example Structure of GPIO.
1 ARM University Program Copyright © ARM Ltd 2013 General Purpose I/O.
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
1 ARM University Program Copyright © ARM Ltd 2013 General Purpose I/O.
Microcontroller based system design Asst. Prof. Dr. Alper ŞİŞMAN.
1 LHO 13 The 8051CF020 and the University Daughter Card.
FREQUENCY COUNTER USING Silicon Labs C8051F020 microcontroller
ATMEL AVR 8 bit RISC MICROCONTROLLERS a general comparison.
ECE 371 – Unit 9 Interrupts (continued). Example Set up Two Interrupt Request Inputs: –Port H[0] Set Interrupt Flag on “0” to “1” transition (rising edge)
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Example 12 Pulse-Width Modulation (PWM): Motors and Servos Lecture L8.1.
Light Sensors ECE 4437 Dr. J. Glover Team 9: Jitin George Zachary Freeman.
Saxion University of Applied Sciences Advanced Microcontrollers A practical approach.
By James Cockrell and Justin Loveless
Chapter 5 - Interrupts.
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.
Lecture 11: Liquid Level Control System: A Case Study 1.
Chapter 12 Some PIC Microcontroller Advances The aims of this chapter are to introduce: To introduce in overview two microcontrollers which show some enhanced.
 CSC111 Quick Revision. Problem Write a java code that read a string, then show a list of options to the user to select from them, where:  L to print.
Basic Counters: Part I Section 7-6 (pp ).
Analog to Digital Conversion - ADC Mark Neil - Microprocessor Course 1 Device Drivers – Measuring Voltages.
Closed Loop Temperature Control Circuit with LCD Display Mike Wooldridge ECE 4330 Embedded Systems.
ARM Embedded Programming Lecture 4 Accessing Memory Mapped Registers.
Arduino DC Motor Motion Control Instructor: Dr Matthew Khin Yi Kyaw.
Vishwakarma government engineering college Prepare by. Hardik Jolapara( ) LCD Interfacing with ATmega16.
NAM S.B MDLAB. Electronic Engineering, Kangwon National University 1.
Praxis I.  Introduction  Hardware  Software Tools  Microcontroller board  Blinky (simple program to flash a led)  References.
Memory Mapped IO (and the CerfBoard). The problem How many IO pins are available on the 8051? What if you are using interrupts, serial, etc…? We want.
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),
EE 319K Introduction to Embedded Systems
Microprocessors A practical approach..
PRJ2: ESP2-UC workshop 1 Introductie 1.
Lizard Labs Peripheral Reflex System
Chip Config & Drivers – Required Drivers:
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
LCD Interfacing using Atmega 32
80C51 Block Diagram ECE Overview.
Workshop 3. Digital-to-analog and analog-to digital conversion
Microcontroller basics
CS4101 Introduction to Embedded Systems Lab 1: General Purpose IO
PRJ2UC: Microcontrollers
Programming Microcontroller ADC – Analog Digital Converter
Programmable Interval Timer
Embedded Systems Software Training Center
Blinking an LED Using MSP430ware to Control GPIO
ECET 340 Education for Service/tutorialrank.com
STM Arm I/O Programming
Example 13 The Serial Peripheral Interface (SPI)
Digital Control Systems Waseem Gulsher
Pondicherry Engineering College
8051 Micro Controller.
Device Drivers – Digital Voltmeter
Prof. Chung-Ta King Department of Computer Science
A modular robot for use in the RoboSumo lab
Presentation transcript:

Peripherals and CMSIS STM32F4, Cortex M4 2016

GPIO configuration } void SUBinit (void) { GPIO_InitTypeDef GPIO_InitStructure; // declare data structure RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOE, ENABLE); // clock enable GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | // list pins to work with GPIO_Pin_5 | GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; // define direction GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; // define driver mode GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; // define speed GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; // define termination GPIO_Init (GPIOE, &GPIO_InitStructure); } // color code: function call, data structure name, data structure member, TypeDef, parameter, defined as „0xsomething“

GPIO use #include "stm32f4xx.h" #include "stm32f4xx_rcc.c " // these must be included #include "stm32f4xx_gpio.c " // #include "dd.h" void main (void) { // char switches = 0; SWITCHinit (); LEDinit (); while (1) { // switches = GPIOE->IDR; if (switches & S370) LED_GR_ON; else LED_GR_OFF; // S370 = 0x0008 if (switches & S371) LED_OR_ON; else LED_OR_OFF; // S370 = 0x0010 if (switches & S372) LED_RD_ON; else LED_RD_OFF; // S370 = 0x0020 if (switches & S373) LED_BL_ON; else LED_BL_OFF; // S370 = 0x0040 }; } // color code: function call, TypeDef, macro call, defined as „0xsomething“

LCD screen 2x16 characters, functions #include "LCD2x16.c„ // must be included if LCD is used LCD_init (); // init LCD, must run first LCD_string ("LCD test", 0x00); // display title string LCD_uInt16 (counter++, 0x0a, 0x01); // write to LCD, unsigned, 16 bits LCD_sInt16 (counter++, 0x40, 0x01); // write to LCD, signed, 16 bits LCD_uInt32 (counter++, 0x48, 0x01); // write to LCD, unsigned, 32 bits LCD_sInt32 (counter++, 0x40, 0x01); // write to LCD, signed, 32 bits LCD_sInt3DG (counter++, 0x42, 0x01); // write to LCD, unsigned, 3 digits // what to do, (what, where, how); // color code: function call, parameter

DAC block diagram X2 !

DAC configuration void DACinit (void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; // DAC outputs are available here GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; // pins must be in analog mode GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; // no need, done automatically GPIO_Init (GPIOA, &GPIO_InitStructure); DAC_InitTypeDef DAC_InitStructure; RCC_APB1PeriphClockCmd (RCC_APB1Periph_DAC, ENABLE); DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable; DAC_InitStructure.DAC_Trigger = DAC_Trigger_None; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_Init (DAC_Channel_1, &DAC_InitStructure); DAC_Init (DAC_Channel_2, &DAC_InitStructure); DAC_Cmd (DAC_Channel_1, ENABLE); DAC_Cmd (DAC_Channel_2, ENABLE); } // color code: function call, data structure name, TypeDef, data structure member, parameter, defined as „0xsomething“

DAC use #include "stm32f4xx.h" #include "stm32f4xx_rcc.c " // these must be included #include "stm32f4xx_dac.c " // #include "stm32f4xx_gpio.c " // int main () { unsigned int j; DACinit (); while (1) { DAC->DHR12R1 = j & 0xfff; // up ramp, direct write to DAC data register DAC->DHR12R2 = 0xfff - (j & 0xfff); // down ramp , direct write to DAC data register j = (j + 1) & 0x0fff; };

ADC block diagram x3 !

ADC configuration, part 1 // decision: use two ADCs, simultaneous sampling void ADCinit_SoftTrigger (void) { GPIO_InitTypeDef GPIO_InitStructure; ADC_InitTypeDef ADC_InitStructure; ADC_CommonInitTypeDef ADC_CommonInitStructure; RCC_APB2PeriphClockCmd (RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2, ENABLE); RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2; // we will use ADC inputs here GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; // put pins into analog mode GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; // not really needed GPIO_Init (GPIOA, &GPIO_InitStructure); // color code: function call, data structure name, TypeDef, data structure member, parameter, defined as „0xsomething“

ADC configuration, part 2 ADC_CommonInitStructure.ADC_Mode = ADC_DualMode_RegSimult; ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2; ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; ADC_CommonInit (&ADC_CommonInitStructure); ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfConversion = 1; ADC_Init (ADC1, &ADC_InitStructure); ADC_RegularChannelConfig (ADC1, ADC_Channel_1, 1, ADC_SampleTime_3Cycles); ADC_Init (ADC2, &ADC_InitStructure); ADC_RegularChannelConfig (ADC2, ADC_Channel_2, 1, ADC_SampleTime_3Cycles); ADC_Cmd (ADC1, ENABLE); ADC_Cmd (ADC2, ENABLE); }; // color code: function call, data structure name, data structure member, parameter, defined as „0xsomething“

ADC use in program #include "stm32f4xx.h" #include "stm32f4xx_rcc.c " // #include "stm32f4xx_adc.c " // these must be included #include "stm32f4xx_gpio.c " // #include "LCD2x16.c" // result goes to screen this time int main () { unsigned int j; ADCinit_SoftTrigger (); // call configuration software LCD_init(); LCD_string("ADC1=", 0); LCD_string("ADC2=", 0x40); // LCD configure and init while (1) { // endless loop ADC_SoftwareStartConv (ADC1); for (j = 0; j<10000000; j++){}; // waste some time LCD_uInt16 ( (int)ADC1->DR, 0x06, 1); // write result on LCD, 1st line LCD_uInt16 ( (int)ADC2->DR, 0x46, 1); // write result on LCD, 2nd line }; }

COUNTER TIMER block diagram What to count Count processing X14 ! x3 ! Input shaping Count processing Output shaping

TIMER as simple counter, configuration, part 1 // decision: use Timer 2, simple counting, port configuration void GPIOAinit_TIM2_ETR (void) { GPIO_InitTypeDef GPIO_InitStructure;   RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; // ETR is available at GPIO_Pin_15 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; // as an alternate function GPIO_Init (GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig (GPIOA, GPIO_PinSource15, GPIO_AF_TIM2); // pin PA15:TIM2_Ch1/ETR  } // color code: function call, data structure name, TypeDef, data structure member, parameter, defined as „0xsomething“

TIMER as simple counter, configuration, part 2 // decision: use Timer 2, simple counting at ETR input pin, timer2 configuration void TIM2init_counter (void) { // counting from ETR TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure; RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM2, ENABLE); // enable counter; apply clock   TIM_TimeBaseInitStructure.TIM_Prescaler = 0; TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInitStructure.TIM_Period = 100000; TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseInit (TIM2, &TIM_TimeBaseInitStructure); TIM_ETRClockMode2Config (TIM2, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted, 0x00); // ETR requires mode 2 TIM_Cmd (TIM2, ENABLE); } // color code: function call, data structure name, TypeDef, data structure member, parameter, defined as „0xsomething“

TIMER simple counter, use of // decision: use Timer 2, simple counting #include "stm32f4xx.h" #include "stm32f4xx_rcc.c„ // must be included #include "stm32f4xx_gpio.c„ // #include "stm32f4xx_tim.c" // #include "LCD2x16.c" // due to writing on the screen int main () { GPIOAinit_TIM2_ETR (); // sub: GPIO clock enable, digital pin definitions TIM2init_counter (); // sub: Timer 2 as counter: ETR input LCD_init (); // due to writing on the screen LCD_string ("TIM2 counter ETR", 0); // write title to LCD while (1) { LCD_uInt32 (TIM2->CNT, 0x40, 0x01); // write counts to LCD for (int i = 0; i < 1000000; i++) {}; // waste time }; } // color code: function call, TypeDef, parameter, defined as „0xsomething“