Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

GPIO polling in freeRTOS

Posted by ajinkya on January 31, 2013
I have very simple program written for polling a GPIO pin.

void main( void )
{
#ifdef DEBUG
debug();
#endif
prvSetupHardware();
xTaskCreate( vOnOffPoll, "AC_ON_OFF_Poll", configMINIMAL_STACK_SIZE * 3, NULL, mainCHECK_TASK_PRIORITY - 1, NULL);

vTaskStartScheduler();
for( ;; );
}

First I tried simple if else loop inside while(1)

void vOnOffPoll(void *pvParameters)
{
while(1)
{
if( GPIO_ReadBit(GPIO4,GPIO_Pin_7) == Bit_RESET)
GPIO_WriteBit(GPIO4, GPIO_Pin_0, Bit_SET);
else
GPIO_WriteBit(GPIO4, GPIO_Pin_0, Bit_RESET);
}

then I tried switch case statement to do the same task in while(1)

void vOnOffPoll(void *pvParameters)
{
while(1)
{
int state=0;
state = GPIO_ReadBit(GPIO4,GPIO_Pin_7);
switch(state)
{
case 1:
GPIO_WriteBit(GPIO4, GPIO_Pin_0, Bit_SET);
break;
case 0:
GPIO_WriteBit(GPIO4, GPIO_Pin_0, Bit_RESET);
break;
}
}
}

I have no other task but still it gets executed once it dose not poll continuously.

Initially pin (GPIO4,GPIO_Pin_7) is connected to on board GND then (GPIO4,GPIO_Pin_0) is set
but when I connect (GPIO4,GPIO_Pin_7) to on board VCC it is not changing state ((GPIO4,GPIO_Pin_0) is not reset) untill I reset kit keeping (GPIO4,GPIO_Pin_7) to on board VCC.

What is the problem? A task cannot be more simpler than this and still it is not working.

RE: GPIO polling in freeRTOS

Posted by Dave on January 31, 2013
There is nothing wrong with the code you have written and because there is only one task that never blocks and the task runs with a priority that is higher than the idle priority the task should just run continuously.

If you put a break point on the first line of the task then step through the code you should see what it is doing.

You can also replace the while loop with a simple increment variable like


volatile int i = 0;

while( 1 ) {
i++;
i++;
}


run your code and check that the value of i is counted up. If it is then the task is being executed as expected. If the task does not execute as expected with the original GPIO code then it must be something in the GPIO functions that stops it.

RE: GPIO polling in freeRTOS

Posted by ajinkya on January 31, 2013
Thanks davedoors for reply,
Actually I was doing small mistake in pin configuration.
Whole project we divided in modules and couldn't notice hardware config than should have changed at first place.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner