Read switch display on led
I am trying to read switch value and display it on led using hal functions on nexsys board.
When I read switch value it is always 1 regardless of switch position.
From debugging I get Hex:0x1116 Binary:1000100010110 for register_value, this shows program excepts gpio_22 as input. What could be the problem? Is this the right usage of hal_read_status_raw() function.
Here is my code:
int main(void)
{
prvSetupHardware();
// SET LED AS OUTPUT
hal_setpinmux(21,2);
hal_set_gpio_mode(14,1);
// SET SWITCH AS INPUT
hal_setpinmux(29,2);
hal_setpullup(29,1);
hal_set_gpio_mode(22,0);
uint8_t switch1 = 0;
uint32_t register_value = 0;
hal_write_gpio(14,0);
while(1){
hal_read_gpio_status_raw(22,®ister_value);
switch1 = (register_value >> 12) & 0x01;
if (switch1==1) {
hal_write_gpio(14,1);
}
else {
hal_write_gpio(14,0);
}
}
}