cancel
Showing results for 
Search instead for 
Did you mean: 

Doubt regarding why read pin is not working when it's set.

Killstreet30
Associate III

0693W00000Y9vz0QAB.pngHello.

Find the attached circuit diagram for my IR sensor. The trigger is built in such a way that when it's off the IR transmitter is off and we get the sunlight values and when it's on we get sunlight + IR value and when we subtract the two we get the resultant. But my code doesn't dsiplay any value when the IR transmitter is on. Here's my code. Please help. When I add a breakpoint it never gets triggered by the if loop where the trigger or pin 9 is set.

HAL_TIM_Base_Start_IT(&htim3);

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

 HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_9);

 HAL_Delay(1000);

 if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_9) == GPIO_PIN_SET){

    HAL_ADC_Start(&hadc1);

    HAL_ADC_PollForConversion(&hadc1, 100);

    ir = HAL_ADC_GetValue(&hadc1);}

 else if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_9) == GPIO_PIN_RESET){

        HAL_ADC_Start(&hadc1);

        HAL_ADC_PollForConversion(&hadc1, 100);

        sunlight = HAL_ADC_GetValue(&hadc1);}

 res = ir - sunlight;

2 REPLIES 2
Javier1
Principal

Are you trying to read and write from the same GPIO?

How did you configured gpio A-9, output or input?

I recommend this for you https://www.youtube.com/watch?v=vdY0VN21ZOI

we dont need to firmware by ourselves, lets talk
gbm
Lead III

I'll be surprised if it works. Normally the photodiode has much too small current to be sampled by ADC, unless you direct a laser light onto it. For light intensity sensing without an amplifier use phototransistor or LDR. For IR remote reception - use a dedicated circuit, like TSOP1836.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice