Analogdaten mit dem mySTM32 Board Light
//--------------------------------------------------------------------------- // Title : simple ADC Solution, ARM C application in SiSy //--------------------------------------------------------------------------- // Function : ... // Wiring : ... //--------------------------------------------------------------------------- // Hardware : ... // Clock : ... MHz // Language : ARM C // Date : ... // Version : ... // Author : ... //--------------------------------------------------------------------------- #include <stddef.h> #include <stdlib.h> #include "hardware.h" void initApplication() { SysTick_Config(SystemCoreClock/100); // LED an B0 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB,ENABLE); GPIO_InitTypeDef led; led.GPIO_Mode = GPIO_Mode_OUT; led.GPIO_OType = GPIO_OType_PP; led.GPIO_Pin = GPIO_Pin_0; led.GPIO_PuPd = GPIO_PuPd_NOPULL; led.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIOB,&led); // ADC1 Chanel11 an PC1 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE); GPIO_StructInit (&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOC, &GPIO_InitStructure); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); ADC_CommonInitTypeDef ADC_CommonInitStructure; ADC_CommonStructInit(&ADC_CommonInitStructure); ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div6; ADC_CommonInit(&ADC_CommonInitStructure); ADC_InitTypeDef ADC_InitStructure; ADC_StructInit(&ADC_InitStructure); ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_Resolution = ADC_Resolution_8b; ADC_Init(ADC1, &ADC_InitStructure); ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 1, ADC_SampleTime_28Cycles); ADC_Cmd(ADC1, ENABLE); ADC_SoftwareStartConv(ADC1); } int main(void) { SystemInit(); initApplication(); uint8_t data=0; do{ waitMs(10); data=ADC_GetConversionValue(ADC1); //USART_SendData(USART3,data); if (data>100) GPIO_SetBits(GPIOB,GPIO_Pin_0); else GPIO_ResetBits(GPIOB,GPIO_Pin_0); } while (true); return 0; } extern "C" void SysTick_Handler(void) { // Application SysTick } //------------------------------------------------------------------------------
Test
Nutzen sie die Schaltflächen Kompilieren, Linken und Brennen. Stellen Sie die nötigen Verbindungen auf dem Board mit den dafür vorgesehenen Patchkabeln her. Testen Sie die Anwendung.
Version mit der STM32 HAL Library
…
Version mit der STM32 LL Library
…