Skip to main content
Associate
Jun 17, 2024 3:12 PM UTC
Question

conflicting types error

I'm trying to make a smart irrigation using stm32f407 so, i used a Soil Moisture Sensors 

i write my code but when i trying to run the problem is :Description Resource Path Location Type conflicting types for 'Read_Soil_Moisture'; have 'uint16_t(void)' {aka 'short unsigned int(void)'} main.c /Projectrrr/Core/Src line 89 C/C++ Problem

and this is my code:

Screenshot 2024-06-17 181149.png

 

so how i can solve this problem

This topic has been closed for replies.

6 replies

Andrew Neil
Super User
Jun 17, 2024 3:18 PM UTC

Please use this button to properly post source code:

AndrewNeil_0-1718637315969.png

 

Please post the full text of the message - copy from the 'Console' window, and paste here.

The full message should tell you both what type it was expecting, and what type it actually got - you've only posted the bit saying what it's got.

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate
Jun 17, 2024 3:25 PM UTC
#include "main.h"

// Function prototypes
void SystemClock_Config(void);
void Error_Handler(void);
static void MX_GPIO_Init(void);
static void MX_ADC1_Init(void);
static void MX_TIM2_Init(void);

ADC_HandleTypeDef hadc1;
TIM_HandleTypeDef htim2;

int main(void) {
 HAL_Init();
 SystemClock_Config();
 MX_GPIO_Init();
 MX_ADC1_Init();
 MX_TIM2_Init();

 while (1) {
 uint16_t moisture_level = Read_Soil_Moisture();

 if (moisture_level < 2000) { // Example threshold
 Control_Servo(90); // Open valve
 } else {
 Control_Servo(0); // Close valve
 }

 HAL_Delay(1000); // Delay for 1 second
 }
}

void SystemClock_Config(void) {
 // System clock configuration code (auto-generated by STM32CubeMX)
}

static void MX_GPIO_Init(void) {
 // GPIO initialization code (auto-generated by STM32CubeMX)
}

static void MX_ADC1_Init(void) {
 ADC_ChannelConfTypeDef sConfig = {0};

 hadc1.Instance = ADC1;
 hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
 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_0;
 sConfig.Rank = 1;
 sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
 if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) {
 Error_Handler();
 }
}

static void MX_TIM2_Init(void) {
 TIM_OC_InitTypeDef sConfigOC = {0};

 htim2.Instance = TIM2;
 htim2.Init.Prescaler = 83;
 htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
 htim2.Init.Period = 20000 - 1;
 htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
 htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
 if (HAL_TIM_PWM_Init(&htim2) != HAL_OK) {
 Error_Handler();
 }
 sConfigOC.OCMode = TIM_OCMODE_PWM1;
 sConfigOC.Pulse = 1500; // 1.5ms pulse width (90 degrees)
 sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
 sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
 if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_2) != HAL_OK) {
 Error_Handler();
 }
 HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2);
}

 uint16_t Read_Soil_Moisture(void) {
 HAL_ADC_Start(&hadc1);
 HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);
 uint16_t value = HAL_ADC_GetValue(&hadc1);
 HAL_ADC_Stop(&hadc1);
 return value;
}

void Control_Servo(uint8_t position) {
 // Convert position (0-180) to pulse width (1ms to 2ms)
 uint16_t pulse = (position * 1000 / 180) + 1000;
 __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_2, pulse);
}

void Error_Handler(void) {
 while (1) {
 // Stay here...
 }
}
Tesla DeLorean
Guru
Jun 17, 2024 3:28 PM UTC

Used it on line 21 and compiler guessed, you need a prototype or definition before first usage.

uint16_t Read_Soil_Moisture(void); // prototype first, and early

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Guru
Jun 17, 2024 3:26 PM UTC

Lacking in contextual detail.

You've probably defined or used it earlier and the compiler used that.

Check .H files and any instance where you might have created a prototype or used it previously.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Jun 17, 2024 6:22 PM UTC

In line 21  Read_Soil_Moisture() called without previous declaration. Either move this  function up before main(), or add the prototype declaration after line 8.