{"id":319,"date":"2022-07-17T08:34:14","date_gmt":"2022-07-17T07:34:14","guid":{"rendered":"https:\/\/www.spacelabcachan.universite-paris-saclay.fr\/?p=319"},"modified":"2022-07-17T20:30:54","modified_gmt":"2022-07-17T19:30:54","slug":"mise-en-oeuvre-de-ladc","status":"publish","type":"post","link":"https:\/\/www.spacelabcachan.universite-paris-saclay.fr\/?p=319","title":{"rendered":"Mise en \u0153uvre de l\u2019ADC"},"content":{"rendered":"<h1>Mise en oeuvre de l'ADC sans le DMA<\/h1>\n<h3>Mat\u00e9riel requis<\/h3>\n<ul>\n<li>un ordinateur avec un terminal (putty, termite,...)<\/li>\n<li>une carte nucleo-L073RZ ou STM32F446RE ou autre<\/li>\n<li>Un potentiom\u00e8tre de 10kOhm par exemple reli\u00e9 \u00e0 PA0 ou la carte IHM (mbed-application-shield)<\/li>\n<li><img decoding=\"async\" src=\"https:\/\/www.spacelabcachan.universite-paris-saclay.fr\/wp-content\/uploads\/2022\/07\/mbed_application_shield.jpeg\" alt=\"\" \/><br \/>\n<h2>Cr\u00e9ation du projet - C\u00f4t\u00e9 configuration<\/h2>\n<h4>Configuration USART<\/h4>\n<p>On configure l'USART2 en 115200 baud.<\/p>\n<\/li>\n<\/ul>\n<h4>Configuration ADC<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/www.spacelabcachan.universite-paris-saclay.fr\/wp-content\/uploads\/2022\/07\/ADC_config_1.png\" alt=\"\" \/><\/p>\n<p>Les choses importantes ici sont la r\u00e9solution (12 bits), on aurait pu prendre moins.<br \/>\nLes param\u00e8tre Continous conversion Mode et Discontinuous Conversion Mode peuvent \u00eatre indiff\u00e9remment Enable ou Disable.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.spacelabcachan.universite-paris-saclay.fr\/wp-content\/uploads\/2022\/07\/ADC_config_params.png\" alt=\"\" \/><\/p>\n<p>Si on met Enable \u00e0 Conversion Continuous Mode plus besoin de faire \u00e0 chaque fois un ADC_Start(), on le fait au d\u00e9but une fois pour toute.<br \/>\nEvidemment, si on fait un ADC_Stop(), va falloir remettre un ADC_Start() quand on veut un nouvel \u00e9chantillon.<\/p>\n<h3>Fonction main de main.c :<\/h3>\n<pre><code class=\"language-c\">    MX_GPIO_Init();\n    MX_DMA_Init();\n    MX_USART2_UART_Init();\n    MX_ADC_Init();\n    HAL_UART_Transmit(&amp;huart2, welcomeMessage , sizeof(welcomeMessage), HAL_MAX_DELAY);\n\n    uint8_t pdata = 0;\n    uint8_t message[5];\n    HAL_ADC_Start(&amp;hadc);\n  while (1)\n  {\n        HAL_ADC_Start(&amp;hadc);\n        HAL_ADC_PollForConversion(&amp;hadc, 1);\n        pdata = HAL_ADC_GetValue(&amp;hadc);\n        sprintf(message,&quot;%d\\r\\n&quot;,HAL_ADC_GetValue(&amp;hadc));\n        HAL_UART_Transmit(&amp;huart2, message , sizeof(message), HAL_MAX_DELAY);\n        HAL_ADC_Stop(&amp;hadc);\n        HAL_Delay(200);\n  }\n}<\/code><\/pre>\n<h3>Fonction MX_ADC_Init de main.c :<\/h3>\n<pre><code class=\"language-c\">static void MX_ADC_Init(void)\n{\n  ADC_ChannelConfTypeDef sConfig = {0};\n\n  hadc.Instance = ADC1;\n  hadc.Init.OversamplingMode = DISABLE;\n  hadc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV1;\n  hadc.Init.Resolution = ADC_RESOLUTION_8B;\n  hadc.Init.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;\n  hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;\n  hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;\n  hadc.Init.ContinuousConvMode = ENABLE;\n  hadc.Init.DiscontinuousConvMode = DISABLE;\n  hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;\n  hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;\n  hadc.Init.DMAContinuousRequests = DISABLE;\n  hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;\n  hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED;\n  hadc.Init.LowPowerAutoWait = DISABLE;\n  hadc.Init.LowPowerFrequencyMode = ENABLE;\n  hadc.Init.LowPowerAutoPowerOff = DISABLE;\n  if (HAL_ADC_Init(&amp;hadc) != HAL_OK)\n  {\n    Error_Handler();\n  }\n\n  \/** Configure for the selected ADC regular channel to be converted.\n  *\/\n  sConfig.Channel = ADC_CHANNEL_0;\n  sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;\n  if (HAL_ADC_ConfigChannel(&amp;hadc, &amp;sConfig) != HAL_OK)\n  {\n    Error_Handler();\n  }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Mise en oeuvre de l&rsquo;ADC sans le DMA Mat\u00e9riel requis un ordinateur avec un terminal (putty, termite,&#8230;) une carte nucleo-L073RZ ou STM32F446RE ou autre Un potentiom\u00e8tre de 10kOhm par exemple reli\u00e9 \u00e0 PA0 ou la carte IHM (mbed-application-shield) Cr\u00e9ation du projet &#8211; C\u00f4t\u00e9 configuration Configuration USART On configure l&rsquo;USART2 en 115200 baud. Configuration ADC Les &hellip; <a href=\"https:\/\/www.spacelabcachan.universite-paris-saclay.fr\/?p=319\" class=\"more-link\">Continuer la lecture de <span class=\"screen-reader-text\">Mise en \u0153uvre de l\u2019ADC<\/span>  <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[8,9,6,10],"class_list":["post-319","post","type-post","status-publish","format-standard","hentry","category-stm32","tag-adc","tag-microcontroleur","tag-stm32","tag-stm32cubeide"],"_links":{"self":[{"href":"https:\/\/www.spacelabcachan.universite-paris-saclay.fr\/index.php?rest_route=\/wp\/v2\/posts\/319","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.spacelabcachan.universite-paris-saclay.fr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.spacelabcachan.universite-paris-saclay.fr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.spacelabcachan.universite-paris-saclay.fr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.spacelabcachan.universite-paris-saclay.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=319"}],"version-history":[{"count":4,"href":"https:\/\/www.spacelabcachan.universite-paris-saclay.fr\/index.php?rest_route=\/wp\/v2\/posts\/319\/revisions"}],"predecessor-version":[{"id":323,"href":"https:\/\/www.spacelabcachan.universite-paris-saclay.fr\/index.php?rest_route=\/wp\/v2\/posts\/319\/revisions\/323"}],"wp:attachment":[{"href":"https:\/\/www.spacelabcachan.universite-paris-saclay.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.spacelabcachan.universite-paris-saclay.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.spacelabcachan.universite-paris-saclay.fr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}