cancel
Showing results for 
Search instead for 
Did you mean: 

TNX Clive1, this works A time out from HAL_ADC_PollForConversion

LMI2
Lead
Posted on October 03, 2017 at 22:14

I combined the code from STM32F746 discovery Template and ADC code from Cube for 746 Discovery. Something is missing allthough I checked the code several times. I use ADC3 input 6 because it is connected to a pin of Discovery board.

#include 'main.h'
#include <stdio.h>
#include 'stm32f7xx_hal.h'
#include 'stm32746g_discovery.h'
#include 'stm32746g_discovery_lcd.h'
 #include <stdio.h>
 #include <string.h>
 #include <limits.h>
//#include 'stm32f7xx_hal.h'
#include <stdlib.h>
#include 'stm32746g_discovery_ts.h'
/** @addtogroup STM32F7xx_HAL_Examples
 * @{
 */
/** @addtogroup Templates
 * @{
 */ 
#include 'stm32746g_discovery_lcd.h'
#define LCD_FRAME_BUFFER SDRAM_DEVICE_ADDR
#define RGB565_BYTE_PER_PIXEL 2
#define ARBG8888_BYTE_PER_PIXEL 4
double ccc,kkk;
TS_StateTypeDef TS_State;
DMA2D_HandleTypeDef hdma2d;
 
I2C_HandleTypeDef hi2c3;
 
LTDC_HandleTypeDef hltdc;
 
UART_HandleTypeDef huart1;
 
DMA_HandleTypeDef hdma_memtomem_dma2_stream0;
SDRAM_HandleTypeDef hsdram1;
ADC_HandleTypeDef hadc1;
UART_HandleTypeDef huart2;
 char klaa[40];
 unsigned char plaa[40];
 volatile int pufkuri[1];
 volatile char isopuf[10];
 int c,kokon;
 volatile int maara;
 double ccc,kkk;
static void SystemClock_Config(void);
static void Error_Handler(void);
static void MPU_Config(void);
static void CPU_CACHE_Enable(void);
/* Private functions ---------------------------------------------------------*/
 static void MX_ADC1_Init(void);
int main(void)
{
 uint8_t ggg;
 uint8_t buf=0;
 char texk[33];
 uint16_t x=0, y=0;
 uint8_t str[4]={0,};
 
 MPU_Config();
 /* Enable the CPU Cache */
 CPU_CACHE_Enable();
 
 HAL_Init();
 
 /* Configure the System clock to have a frequency of 216 MHz */
 SystemClock_Config();
 MX_ADC1_Init();
BSP_LCD_Init();
BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FRAME_BUFFER);
BSP_LCD_SetLayerVisible(LTDC_ACTIVE_LAYER, ENABLE);
BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER);
BSP_LCD_Clear(LCD_COLOR_BLACK);
BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
BSP_LCD_DisplayOn();
char buffer[30] ;
sprintf(buffer,'hghhhh') ;
BSP_LCD_DisplayStringAtLine(0, (uint8_t *) buffer) ;
 while (1)
 {
 
 HAL_ADC_Start(&hadc1);
 
 if (HAL_ADC_PollForConversion(&hadc1, 1000) == HAL_OK)
 {
 kokon = HAL_ADC_GetValue(&hadc1);
 
 }
 HAL_ADC_Stop(&hadc1);
 sprintf (klaa,'Readout %d', kokon);
 BSP_LCD_DisplayStringAtLine(5, (uint8_t *) klaa) ; 
 }
}
 static void MX_ADC1_Init(void)
 {
 ADC_ChannelConfTypeDef sConfig;
 /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
 */
 hadc1.Instance = ADC3;
 //hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
 hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
 hadc1.Init.Resolution = ADC_RESOLUTION_12B;
 hadc1.Init.ScanConvMode = DISABLE;
 hadc1.Init.ContinuousConvMode = DISABLE;
 hadc1.Init.DiscontinuousConvMode = DISABLE;
 hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
 hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
 hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
 hadc1.Init.NbrOfConversion = 1;
 hadc1.Init.DMAContinuousRequests = DISABLE;
 hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
 if (HAL_ADC_Init(&hadc1) != HAL_OK)
 {
 Error_Handler();
 }
 sConfig.Channel = ADC_CHANNEL_6;
 sConfig.Rank = 1;
 //sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
 sConfig.SamplingTime = ADC_SAMPLETIME_15CYCLES;
 if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
 {
 Error_Handler();
 }
 }
/**
 * @brief System Clock Configuration
 * @param None
 * @retval None
 */
static void SystemClock_Config(void)
{
 RCC_ClkInitTypeDef RCC_ClkInitStruct;
 RCC_OscInitTypeDef RCC_OscInitStruct;
 /* Enable HSE Oscillator and activate PLL with HSE as source */
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
 RCC_OscInitStruct.HSEState = RCC_HSE_ON;
 RCC_OscInitStruct.HSIState = RCC_HSI_OFF;
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
 RCC_OscInitStruct.PLL.PLLM = 25;
 RCC_OscInitStruct.PLL.PLLN = 432; 
 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
 RCC_OscInitStruct.PLL.PLLQ = 9;
 if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 {
 Error_Handler();
 }
 /* activate the OverDrive to reach the 216 Mhz Frequency */
 if(HAL_PWREx_EnableOverDrive() != HAL_OK)
 {
 Error_Handler();
 }
 
 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 
 clocks dividers */
 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; 
 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; 
 if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) != HAL_OK)
 {
 Error_Handler();
 }
}
/**
 * @brief This function is executed in case of error occurrence.
 * @param None
 * @retval None
 */
static void Error_Handler(void)
{
 /* User may add here some code to deal with this error */
 while(1)
 {
 // BSP_LCD_DisplayStringAtLine(6, (uint8_t *) buffer) ; 
 }
}

static void MPU_Config(void)
{
 MPU_Region_InitTypeDef MPU_InitStruct;
 
 /* Disable the MPU */
 HAL_MPU_Disable();
 /* Configure the MPU attributes as WT for SRAM */
 MPU_InitStruct.Enable = MPU_REGION_ENABLE;
 MPU_InitStruct.BaseAddress = 0x20010000;
 MPU_InitStruct.Size = MPU_REGION_SIZE_256KB;
 MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
 MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
 MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
 MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
 MPU_InitStruct.Number = MPU_REGION_NUMBER0;
 MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
 MPU_InitStruct.SubRegionDisable = 0x00;
 MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
 HAL_MPU_ConfigRegion(&MPU_InitStruct);
 /* Enable the MPU */
 HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
}
static void CPU_CACHE_Enable(void)
{
 /* Enable I-Cache */
 SCB_EnableICache();
 /* Enable D-Cache */
 SCB_EnableDCache();
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{ 
 while (1)
 {
 }
}
#endif
/**
 * @}
 */ 
/**
 * @}
 */ 
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

#hal_adc_pollforconversion
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on October 03, 2017 at 23:37

>>Something is missing although I checked the code several times

Like code to enable the ADC3 clock?

No code presented enables the pin, clocks, etc. try looking at that code.

__HAL_RCC_ADC3_CLK_ENABLE();

Polling using ADC3

STM32Cube_FW_F7_V1.8.0\Projects\STM32756G_EVAL\Examples\ADC\ADC_RegularConversion_Polling\Src\main.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

3 REPLIES 3
Posted on October 03, 2017 at 23:37

>>Something is missing although I checked the code several times

Like code to enable the ADC3 clock?

No code presented enables the pin, clocks, etc. try looking at that code.

__HAL_RCC_ADC3_CLK_ENABLE();

Polling using ADC3

STM32Cube_FW_F7_V1.8.0\Projects\STM32756G_EVAL\Examples\ADC\ADC_RegularConversion_Polling\Src\main.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 05, 2017 at 23:12

Thanks.

I checked '...\Projects\STM32756G_EVAL\Examples\ADC\ADC_RegularConversion_Polling\Src\main.c' and corrected all  differencies I could find but I still get time outs. It could be that I don't use my Keil IDE optimally but finding differencies is either tedious or hit and mostly miss. There are quite a lot of .c and .h files.

LMI2
Lead
Posted on October 06, 2017 at 17:05

I cant understand where are all the .c and .h files in a project. And what is changed for just current project and what not.

But I got ADC working , I think. At least there are no time outs. After a hint from Clive1 I compared files or 'mess'  from an other project to my mess of files and finally got rid of time outs.