C Switch Statement CMSIS FreeRTOS

-1

I'm trying to make a C program which uses various functions then via a DIP switch connected to a LPCXpresso 1769 it must select the function to execute (e.g. 00 binary counter 01 rotate leds and so on). Now, I've already made it but wanted to change the function which chooses the program to execute from nested if's to a switch statement but it doesn't work. It does compile, however, the debugger throws some warnings ('statement with no effect' at line 123 and 132 also 'unused parameter pvParameter' at line 100), also after flashing it to the LPCXpresso and choosing the combination for each task it doesn't do a thing. I'm using the LPCXpresso IDE from NXP.

Here's the code

#include <string.h>
#include "FreeRTOS.h"
#include "task.h"
#ifdef __USE_CMSIS
#include "LPC17xx.h"
#endif

#include <cr_section_macros.h>
#include <NXP/crp.h>
#include "lpc17xx_gpio.h"
#include "lpc17xx_timer.h"
#include "lpc17xx_adc.h"
#include "lpc17xx_pinsel.h"
/* Library includes. */
#include "LPC17xx.h"
#include "LPC17xx_gpio.h"
#include "system_LPC17xx.h"



/* Used as a loop counter to create a very crude delay. */
IRQn_Type TIMER0;
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;
/* Used in the run time stats calculations. */
/* Used in the run time stats calculations. */
static uint32_t ulClocksPer10thOfAMilliSecond = 0UL;
#define mainDELAY_LOOP_COUNT    (0xfffff)
void CONFIG_GPIO(void);

static void init_adc(void);
extern int Timer0_Wait();

#define RGB_RED 0x01000000
#define RGB_BLUE 0x02000000
#define RGB_GREEN 0x04000000
void init_rgb (void);
void counter_rgb (void);

void vTaskKit( void *pvParameters );

int main( void )
{
    init_adc();
    init_rgb();
    CONFIG_GPIO();

    xTaskCreate (vTaskKit, "Kit", 240, NULL, 1, NULL );
    /* Start the FreeRTOS scheduler. */
    vTaskStartScheduler();

    /* The following line should never execute.  If it does, it means there was
insufficient FreeRTOS heap memory available to create the Idle and/or timer
tasks.  See the memory management section on the http://www.FreeRTOS.org web
site for more information. */
for( ;; );
}


/*-----------------------------------------------------------*/


void CONFIG_GPIO(void)
            {
                GPIO_SetDir(0,0x000000FF, 1);
                GPIO_ClearValue(0, 0x000000FF);
                GPIO_SetDir(2,0x000000FF,0);
                GPIO_ClearValue(2, 0x000000FF);
            }
void init_rgb (void)
            {
                GPIO_SetDir (0,0x01000000, 1);
                GPIO_SetDir (0,0x02000000, 1);
                GPIO_SetDir (0,0x04000000, 1);
            }
static void init_adc(void)
{

/*
 * Init ADC pin connect
 * AD0.0 on P0.23
 */
PINSEL_CFG_Type PinCfg;
PinCfg.Funcnum = 1;
PinCfg.OpenDrain = 0;
PinCfg.Pinmode = 0;
PinCfg.Pinnum = 23;
PinCfg.Portnum = 0;
PINSEL_ConfigPin(&PinCfg);

/* Configuration for ADC :
 *  Frequency at 1Mhz
 *  ADC channel 0, no Interrupt
 */
ADC_Init(LPC_ADC, 100000);
ADC_IntConfig(LPC_ADC,ADC_ADINTEN0,ENABLE);
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_0,ENABLE);
ADC_EdgeStartConfig(LPC_ADC,ADC_START_ON_FALLING);
}

void vTaskKit( void *pvParameters )
{
volatile unsigned long ul;

uint32_t var1=0x00000001;
uint32_t del =0x000000FF;
uint32_t var2=0x00000001;
uint32_t analog = 0;
uint32_t sw=0x00000000;
unsigned int var=0;
while(1)
{
    sw=GPIO_ReadValue(2);
    switch(sw)
    {
        case 0x00000001://Contador Binario
            GPIO_SetValue(0,var);
            var++;
            vTaskDelay(100);
            GPIO_ClearValue(0,0x000000FF);
            break;

        case 0x00000002://Auto Increible
            for(var2;var2<=7;var2++)
            {
                GPIO_SetValue(0,var1);
                var1= var1<<1;
                for (ul =0; ul < mainDELAY_LOOP_COUNT; ul++ )
                {
                }
                GPIO_ClearValue(0,del);
            }
            for(var2;var2>=2;var2--)
            {
                GPIO_SetValue(0,var1);
                var1= var1>>1;
                for (ul =0; ul < mainDELAY_LOOP_COUNT; ul++ )
                {
                }
                GPIO_ClearValue(0,del);
            }
            break;

        case 0x00000003://Contador RGB
            GPIO_SetValue (0,RGB_RED);
            vTaskDelay( 200 / portTICK_RATE_MS );

            GPIO_ClearValue (0,RGB_RED);
            GPIO_SetValue (0,RGB_BLUE);
            vTaskDelay( 200 / portTICK_RATE_MS );

            GPIO_ClearValue (0,RGB_BLUE);
            GPIO_SetValue (0,(RGB_RED+RGB_BLUE));
            vTaskDelay( 200 / portTICK_RATE_MS );

            GPIO_ClearValue (0,(RGB_RED+RGB_BLUE));
            GPIO_SetValue (0,RGB_GREEN);
            vTaskDelay( 200 / portTICK_RATE_MS );

            GPIO_ClearValue (0,RGB_GREEN);
            GPIO_SetValue (0,RGB_GREEN+RGB_RED);
            vTaskDelay( 200 / portTICK_RATE_MS );

            GPIO_ClearValue (0,RGB_GREEN+RGB_RED);
            GPIO_SetValue (0,RGB_GREEN+RGB_BLUE);
            vTaskDelay( 200 / portTICK_RATE_MS );

            GPIO_ClearValue (0,RGB_GREEN+RGB_BLUE);
            GPIO_SetValue (0,RGB_GREEN+RGB_BLUE+RGB_RED);
            vTaskDelay( 200 / portTICK_RATE_MS );

            GPIO_ClearValue (0,RGB_GREEN+RGB_BLUE+RGB_RED);
            vTaskDelay( 200 / portTICK_RATE_MS );
            break;

        case 0x00000004://Contador ADC Binario
            ADC_StartCmd(LPC_ADC,ADC_START_NOW);
            analog=ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_0);
            analog=analog/16;
            GPIO_SetValue(0,analog);
            vTaskDelay( 100 / portTICK_RATE_MS );

            GPIO_ClearValue(0,0x000000FF);
            break;

        case 0x00000005://Contador ADC RGB
            ADC_StartCmd(LPC_ADC,ADC_START_NOW);
            analog=ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_0);
            if(analog<585)
            {
                GPIO_SetValue(0,RGB_RED);
                vTaskDelay( 50 / portTICK_RATE_MS );
                GPIO_ClearValue (0,RGB_RED);
            }
            if(585<analog && analog<1170)
            {
                GPIO_SetValue (0,RGB_BLUE);
                vTaskDelay( 50 / portTICK_RATE_MS );
                GPIO_ClearValue (0,RGB_BLUE);
            }
            if(1170<analog && analog<1755)
            {
                GPIO_SetValue (0,(RGB_RED+RGB_BLUE));
                vTaskDelay( 50 / portTICK_RATE_MS );
                GPIO_ClearValue (0,(RGB_RED+RGB_BLUE));
            }
            if(1755<analog && analog<2340)
            {
                GPIO_SetValue (0,RGB_GREEN);
                vTaskDelay( 50 / portTICK_RATE_MS );
                GPIO_ClearValue (0,RGB_GREEN);
            }
            if(2340<analog && analog<2925)
            {
                GPIO_SetValue (0,RGB_GREEN+RGB_RED);
                vTaskDelay( 50 / portTICK_RATE_MS );
                GPIO_ClearValue (0,RGB_GREEN+RGB_RED);
            }
            if(2925<analog && analog<3510)
            {
                GPIO_SetValue (0,RGB_GREEN+RGB_BLUE);
                vTaskDelay( 50 / portTICK_RATE_MS );
                GPIO_ClearValue (0,RGB_GREEN+RGB_BLUE);
            }
            if(3510<analog && analog<4095)
            {
                GPIO_SetValue (0,RGB_GREEN+RGB_BLUE+RGB_RED);
                vTaskDelay( 50 / portTICK_RATE_MS );
                GPIO_ClearValue (0,RGB_GREEN+RGB_BLUE+RGB_RED);
            }
            break;
    }
 }
}















void vMainConfigureTimerForRunTimeStats( void )
{
/* How many clocks are there per tenth of a millisecond? */
ulClocksPer10thOfAMilliSecond = configCPU_CLOCK_HZ / 10000UL;
}
/*-----------------------------------------------------------*/

uint32_t ulMainGetRunTimeCounterValue( void )
{
uint32_t ulSysTickCounts, ulTickCount, ulReturn;
const uint32_t ulSysTickReloadValue = ( configCPU_CLOCK_HZ /   configTICK_RATE_HZ ) - 1UL;
volatile uint32_t * const pulCurrentSysTickCount = ( ( volatile uint32_t  *) 0xe000e018 );
volatile uint32_t * const pulInterruptCTRLState = ( ( volatile uint32_t *) 0xe000ed04 );
const uint32_t ulSysTickPendingBit = 0x04000000UL;

/* NOTE: There are potentially race conditions here.  However, it is used
anyway to keep the examples simple, and to avoid reliance on a separate
timer peripheral. */


/* The SysTick is a down counter.  How many clocks have passed since it was
last reloaded? */
ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount;

/* How many times has it overflowed? */
ulTickCount = xTaskGetTickCountFromISR();

/* Is there a SysTick interrupt pending? */
if( ( *pulInterruptCTRLState & ulSysTickPendingBit ) != 0UL )
{
    /* There is a SysTick interrupt pending, so the SysTick has  overflowed
    but the tick count not yet incremented. */
    ulTickCount++;

    /* Read the SysTick again, as the overflow might have occurred since
    it was read last. */
    ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount;
}

/* Convert the tick count into tenths of a millisecond.  THIS ASSUMES
configTICK_RATE_HZ is 1000! */
ulReturn = ( ulTickCount * 10UL ) ;

/* Add on the number of tenths of a millisecond that have passed since the
tick count last got updated. */
ulReturn += ( ulSysTickCounts / ulClocksPer10thOfAMilliSecond );

return ulReturn;
}
/*-----------------------------------------------------------*/

void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char  *pcTaskName )
{
( void ) pcTaskName;
( void ) pxTask;

/* Run time stack overflow checking is performed if
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook
function is called if a stack overflow is detected. */
taskDISABLE_INTERRUPTS();
for( ;; );
}
/*-----------------------------------------------------------*/

void vApplicationMallocFailedHook( void )
{
/* vApplicationMallocFailedHook() will only be called if
configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook
function that will get called if a call to pvPortMalloc() fails.
pvPortMalloc() is called internally by the kernel whenever a task, queue,
timer or semaphore is created.  It is also called by various parts of the
demo application.  If heap_1.c or heap_2.c are used, then the size of the
heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
to query the size of free heap space that remains (although it does not
provide information on how the remaining heap might be fragmented). */
taskDISABLE_INTERRUPTS();
for( ;; );

}
/*-----------------------------------------------------------*/

And the one which works, but with nested if's

#include <string.h>
#include "FreeRTOS.h"
#include "task.h"
#ifdef __USE_CMSIS
#include "LPC17xx.h"
#endif

#include <cr_section_macros.h>
#include <NXP/crp.h>
#include "lpc17xx_gpio.h"
#include "lpc17xx_timer.h"
#include "lpc17xx_adc.h"
#include "lpc17xx_pinsel.h"
/* Library includes. */
#include "LPC17xx.h"
#include "LPC17xx_gpio.h"
#include "system_LPC17xx.h"



/* Used as a loop counter to create a very crude delay. */
IRQn_Type TIMER0;
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;
/* Used in the run time stats calculations. */
/* Used in the run time stats calculations. */
static uint32_t ulClocksPer10thOfAMilliSecond = 0UL;
#define mainDELAY_LOOP_COUNT    (0xfffff)
void CONFIG_GPIO(void);

static void init_adc(void);
extern int Timer0_Wait();

#define RGB_RED 0x01000000
#define RGB_BLUE 0x02000000
#define RGB_GREEN 0x04000000
void init_rgb (void);
void counter_rgb (void);

void vTaskKit( void *pvParameters );

int main( void )
{
init_adc();
init_rgb();
CONFIG_GPIO();

xTaskCreate (vTaskKit, "Kit", 240, NULL, 1, NULL );
/* Start the FreeRTOS scheduler. */
vTaskStartScheduler();

/* The following line should never execute.  If it does, it means there was
insufficient FreeRTOS heap memory available to create the Idle and/or timer
tasks.  See the memory management section on the http://www.FreeRTOS.org web
site for more information. */
for( ;; );
}


/*-----------------------------------------------------------*/


void CONFIG_GPIO(void)
            {
                GPIO_SetDir(0,0x000000FF, 1);
                GPIO_ClearValue(0, 0x000000FF);
                GPIO_SetDir(2,0x000000FF,0);
                GPIO_ClearValue(2, 0x000000FF);
            }
void init_rgb (void)
            {
                GPIO_SetDir (0,0x01000000, 1);
                GPIO_SetDir (0,0x02000000, 1);
                GPIO_SetDir (0,0x04000000, 1);
            }
static void init_adc(void)
{

/*
 * Init ADC pin connect
 * AD0.0 on P0.23
 */
PINSEL_CFG_Type PinCfg;
PinCfg.Funcnum = 1;
PinCfg.OpenDrain = 0;
PinCfg.Pinmode = 0;
PinCfg.Pinnum = 23;
PinCfg.Portnum = 0;
PINSEL_ConfigPin(&PinCfg);

/* Configuration for ADC :
 *  Frequency at 1Mhz
 *  ADC channel 0, no Interrupt
 */
ADC_Init(LPC_ADC, 100000);
ADC_IntConfig(LPC_ADC,ADC_ADINTEN0,ENABLE);
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_0,ENABLE);
ADC_EdgeStartConfig(LPC_ADC,ADC_START_ON_FALLING);
}

void vTaskKit( void *pvParameters )
{
volatile unsigned long ul;

uint32_t var1=0x00000001;
uint32_t del =0x000000FF;
uint32_t var2=0x00000001;
uint32_t analog = 0;
char var=0;
char sw=0x000000000;
char bin=0x00000001;
char inc=0x00000002;
char rgb=0x00000003;
char adcbin=0x00000004;
char adcrgb=0x00000005;

    while(1)
    {

      sw=GPIO_ReadValue(2);
        if(sw==bin)
        {
                    GPIO_SetValue(0,var);
                    var++;
                    vTaskDelay(100);
                    GPIO_ClearValue(0,0x000000FF);




        }


        if(sw==inc)
        {
        for(var2;var2<=7;var2++)
                {
                    GPIO_SetValue(0,var1);
                    var1= var1<<1;
                    for (ul =0; ul < mainDELAY_LOOP_COUNT; ul++ )
                        {
                        }

                    GPIO_ClearValue(0,del);
                }

                for(var2;var2>=2;var2--)
                {
                    GPIO_SetValue(0,var1);
                    var1= var1>>1;
                    for (ul =0; ul < mainDELAY_LOOP_COUNT; ul++ )

                    {
                    }
                    GPIO_ClearValue(0,del);

                        }
                    }
        if(sw==rgb)
        {
            GPIO_SetValue (0,RGB_RED);
            vTaskDelay( 200 / portTICK_RATE_MS );

            GPIO_ClearValue (0,RGB_RED);
            GPIO_SetValue (0,RGB_BLUE);
            vTaskDelay( 200 / portTICK_RATE_MS );

            GPIO_ClearValue (0,RGB_BLUE);
            GPIO_SetValue (0,(RGB_RED+RGB_BLUE));
            vTaskDelay( 200 / portTICK_RATE_MS );

            GPIO_ClearValue (0,(RGB_RED+RGB_BLUE));
            GPIO_SetValue (0,RGB_GREEN);
            vTaskDelay( 200 / portTICK_RATE_MS );

            GPIO_ClearValue (0,RGB_GREEN);
            GPIO_SetValue (0,RGB_GREEN+RGB_RED);
            vTaskDelay( 200 / portTICK_RATE_MS );

            GPIO_ClearValue (0,RGB_GREEN+RGB_RED);
            GPIO_SetValue (0,RGB_GREEN+RGB_BLUE);
            vTaskDelay( 200 / portTICK_RATE_MS );

            GPIO_ClearValue (0,RGB_GREEN+RGB_BLUE);
            GPIO_SetValue (0,RGB_GREEN+RGB_BLUE+RGB_RED);
            vTaskDelay( 200 / portTICK_RATE_MS );

            GPIO_ClearValue (0,RGB_GREEN+RGB_BLUE+RGB_RED);
            vTaskDelay( 200 / portTICK_RATE_MS );


            }

        if(sw==adcbin)
                    {
                        ADC_StartCmd(LPC_ADC,ADC_START_NOW);
                        analog=ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_0);
                        analog=analog/16;
                        GPIO_SetValue(0,analog);
                        vTaskDelay( 100 / portTICK_RATE_MS );

                        GPIO_ClearValue(0,0x000000FF);


                    }
        if(sw==adcrgb)
                    {
            ADC_StartCmd(LPC_ADC,ADC_START_NOW);
            analog=ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_0);
            if(analog<585)
            {
            GPIO_SetValue(0,RGB_RED);
            vTaskDelay( 50 / portTICK_RATE_MS );
            GPIO_ClearValue (0,RGB_RED);
            }
            if(585<analog && analog<1170)
            {
            GPIO_SetValue (0,RGB_BLUE);
            vTaskDelay( 50 / portTICK_RATE_MS );
            GPIO_ClearValue (0,RGB_BLUE);
            }
            if(1170<analog && analog<1755)
            {
            GPIO_SetValue (0,(RGB_RED+RGB_BLUE));
            vTaskDelay( 50 / portTICK_RATE_MS );
            GPIO_ClearValue (0,(RGB_RED+RGB_BLUE));
            }
            if(1755<analog && analog<2340)
            {
            GPIO_SetValue (0,RGB_GREEN);
            vTaskDelay( 50 / portTICK_RATE_MS );
            GPIO_ClearValue (0,RGB_GREEN);
            }
            if(2340<analog && analog<2925)
            {
            GPIO_SetValue (0,RGB_GREEN+RGB_RED);
            vTaskDelay( 50 / portTICK_RATE_MS );
            GPIO_ClearValue (0,RGB_GREEN+RGB_RED);
            }
            if(2925<analog && analog<3510)
            {
            GPIO_SetValue (0,RGB_GREEN+RGB_BLUE);
            vTaskDelay( 50 / portTICK_RATE_MS );
            GPIO_ClearValue (0,RGB_GREEN+RGB_BLUE);
            }
            if(3510<analog && analog<4095)
            {
            GPIO_SetValue
            (0,RGB_GREEN+RGB_BLUE+RGB_RED);

            vTaskDelay( 50 / portTICK_RATE_MS );

            GPIO_ClearValue

            (0,RGB_GREEN+RGB_BLUE+RGB_RED);

            }


                    }
                    }
                    }















void vMainConfigureTimerForRunTimeStats( void )
{
/* How many clocks are there per tenth of a millisecond? */
ulClocksPer10thOfAMilliSecond = configCPU_CLOCK_HZ / 10000UL;
}
/*-----------------------------------------------------------*/

uint32_t ulMainGetRunTimeCounterValue( void )
{
uint32_t ulSysTickCounts, ulTickCount, ulReturn;
const uint32_t ulSysTickReloadValue = ( configCPU_CLOCK_HZ /    configTICK_RATE_HZ ) - 1UL;
volatile uint32_t * const pulCurrentSysTickCount = ( ( volatile uint32_t *) 0xe000e018 );
volatile uint32_t * const pulInterruptCTRLState = ( ( volatile uint32_t *) 0xe000ed04 );
const uint32_t ulSysTickPendingBit = 0x04000000UL;

/* NOTE: There are potentially race conditions here.  However, it is used
anyway to keep the examples simple, and to avoid reliance on a separate
timer peripheral. */


/* The SysTick is a down counter.  How many clocks have passed since it was
last reloaded? */
ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount;

/* How many times has it overflowed? */
ulTickCount = xTaskGetTickCountFromISR();

/* Is there a SysTick interrupt pending? */
if( ( *pulInterruptCTRLState & ulSysTickPendingBit ) != 0UL )
{
    /* There is a SysTick interrupt pending, so the SysTick has overflowed
    but the tick count not yet incremented. */
    ulTickCount++;

    /* Read the SysTick again, as the overflow might have occurred since
    it was read last. */
    ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount;
}

/* Convert the tick count into tenths of a millisecond.  THIS ASSUMES
configTICK_RATE_HZ is 1000! */
ulReturn = ( ulTickCount * 10UL ) ;

/* Add on the number of tenths of a millisecond that have passed since the
tick count last got updated. */
ulReturn += ( ulSysTickCounts / ulClocksPer10thOfAMilliSecond );

return ulReturn;
}
/*-----------------------------------------------------------*/

void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
{
( void ) pcTaskName;
( void ) pxTask;

/* Run time stack overflow checking is performed if
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook
function is called if a stack overflow is detected. */
taskDISABLE_INTERRUPTS();
for( ;; );
}
/*-----------------------------------------------------------*/

void vApplicationMallocFailedHook( void )
{
/* vApplicationMallocFailedHook() will only be called if
configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook
function that will get called if a call to pvPortMalloc() fails.
pvPortMalloc() is called internally by the kernel whenever a task, queue,
timer or semaphore is created.  It is also called by various parts of the
demo application.  If heap_1.c or heap_2.c are used, then the size of the
heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
to query the size of free heap space that remains (although it does not
provide information on how the remaining heap might be fragmented). */
taskDISABLE_INTERRUPTS();
for( ;; );

}
/*-----------------------------------------------------------*/
c
switch-statement
embedded
lpcxpresso
asked on Stack Overflow Feb 23, 2017 by beto_gdo92

2 Answers

1

Ref unused parameter warning: Functions that implement FreeRTOS tasks must have the same prototype, and the prototype includes a parameter. However, not all tasks actually want to use the parameter, but if the parameter is left unused the compiler will generate the warning you see. The warning is benign, and you can't fix it by removing the parameter, so to keep the compiler quiet just perform a void read of the parameter by adding the following code to the task:

/* Remove compiler warnings about an unused parameter. */ ( void ) pvParameters;

Ref statement with no effect on line 123. Can't comment as I don't know which is line 123.

answered on Stack Overflow Feb 23, 2017 by Richard
0

GPIO_ReadValue() returns a uint32_t type. In the working program the return value is assigned to an 8-bit char type, which means that the most significant 24 bits are masked away and ignored. Only the least significant 8 bits of the value are used in the subsequent if comparison statements.

In the non-working program, the return value of GPIO_ReadValue() is assigned to a 32-bit value. The most significant 24 bits are NOT masked away. All 32-bits are used to determine the case for the switch statement. The case values assume that the most significant 24 bits are all zero. But if any of the most significant 24 bits are non-zero then none of your case statements will match the value. Perhaps you need to mask off those most significant 24 bits like this.

sw = (GPIO_ReadValue(2) & 0x000000FF);
switch(sw)
answered on Stack Overflow Feb 23, 2017 by kkrambo

User contributions licensed under CC BY-SA 3.0