you have problem with your code.
You need to set your gpio. On reset All gpios are set to be 0x1f in function . Which is ?????
To prove my point I just made your example , in c-sdk , but set 4 gpios to output and change the value.
B.T.W. register access is 32bit! Don't make a union pointer. You could use a union variable and transfer the 32bit into it and then read each byte.
You need to set your gpio. On reset All gpios are set to be 0x1f in function . Which is ?????
To prove my point I just made your example , in c-sdk , but set 4 gpios to output and change the value.
B.T.W. register access is 32bit! Don't make a union pointer. You could use a union variable and transfer the 32bit into it and then read each byte.
Code:
#include "hardware/structs/sio.h"#include "hardware/gpio.h"void main() { stdio_init_all(); // set gpio 2,3,4,= and 5 output HIGH for(int pin=2;pin<6;pin++) { gpio_init(pin); gpio_set_dir(pin, GPIO_OUT); // set high } while(true) { gpio_set_mask(0b111100); for(int pin=2;pin<6;pin++) gpio_put(pin,1); sleep_us(1); printf("Set gpio 2,3,4 ,5 high!\n"); printf("sio_hw->gpio_in: 0x%X\r\n", sio_hw->gpio_in); printf("Set gpio 2,3,4 ,5 low!\n"); for(int pin=2;pin<6;pin++) gpio_put(pin,0); sleep_us(1); printf("sio_hw->gpio_in: 0x%X\r\n", sio_hw->gpio_in); sleep_ms(1000); }}
Set gpio 2,3,4 ,5 high!
sio_hw->gpio_in: 0x3C
Set gpio 2,3,4 ,5 low!
sio_hw->gpio_in: 0x0
Set gpio 2,3,4 ,5 high!
sio_hw->gpio_in: 0x3C
Set gpio 2,3,4 ,5 low!
sio_hw->gpio_in: 0x0
Statistics: Posted by danjperron — Thu Apr 18, 2024 2:29 am