Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read switch display on led #49

Open
WazaAbdulkadir opened this issue Mar 27, 2023 · 0 comments
Open

Read switch display on led #49

WazaAbdulkadir opened this issue Mar 27, 2023 · 0 comments

Comments

@WazaAbdulkadir
Copy link

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,&register_value);
 
 		switch1 = (register_value >> 12) & 0x01;
 		
 		if (switch1==1) {
 			hal_write_gpio(14,1);
 		}

 		else {
 			hal_write_gpio(14,0);

 		}

 	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant