This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Setting value of GPIO Output

Hello all,

I am trying to do a simple task, yet I cannot manage to make it work. My goal is to use the GPIO 1.01 (defined as Digital I/O in the Data Sheet) as an output pin, set its logical value to High/Low and observe all changes in a Logic Analyzer.

The problem is that the pin stays always at High, no matter how many times I try to set it to Low.

Here is my implementation:

prj.conf

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
CONFIG_NCS_SAMPLES_DEFAULTS=y
CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="Nordic_LBS"
# Enable the LBS service
CONFIG_BT_LBS=y
CONFIG_BT_LBS_POLL_BUTTON=y
CONFIG_DK_LIBRARY=y
CONFIG_SPI=y
CONFIG_GPIO=y
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

CMakeLists.txt

Fullscreen
1
2
3
4
5
6
7
8
9
10
cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(NONE)
target_sources(app PRIVATE
src/main.c
)
zephyr_library_include_directories(.)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Code snippet in main.c where I configure the pin and try to modify its value.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//Get GPIO_1 device
struct device * trfEN;
trfEN = device_get_binding("GPIO_1");
if(trfEN == NULL) {
printk("Could not get trfEN device\n");
} else {
printk("Found device trfEN\n");
}
//Configure pin as output
gpio_pin_configure(trfEN, 1, GPIO_OUTPUT_LOW);
//Enable TRF by setting GPIO to HIGH
int ret = gpio_pin_set(trfEN, 1, 1); //Set pin 1.01 to 1
if(ret != 0) {
printk("Error setting pin to high\n");
} else {
printk("Pin set to high successfully\n"); //This line is printed -> No error setting pin
}
//Try to set pin to low
k_sleep(K_MSEC(1000));
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I attach also the output that I see with a logic analyzer:

Any idea where I am doing something wrong?

Many thanks in advance!