This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

GPIO pin reading wrong value

There seems to be an issue when reading GPIO pins returning false readings. I am using two pins for I2C communication, 26 and 27, I am configuring them with the required configuration for using I2C and then setting them high. However, when I go to read the inputs of these pins (which are floating, the only thing attached to them is an oscilloscope) they are falsely read as high when they are low (verified on the scope). When I then manually read the pin status from gdb I correctly see that both pins are low. Even stranger is that on the first power up I do not see the issue and the pins are correctly read as low, but if run the code a second time without restarting then I start to see the issue.

NRF_GPIO->PIN_CNF[SCLPin] = 
    (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
  | (GPIO_PIN_CNF_DRIVE_S0D1     << GPIO_PIN_CNF_DRIVE_Pos)
  | (GPIO_PIN_CNF_PULL_Disabled  << GPIO_PIN_CNF_PULL_Pos)
  | (GPIO_PIN_CNF_INPUT_Connect  << GPIO_PIN_CNF_INPUT_Pos)
  | (GPIO_PIN_CNF_DIR_Output     << GPIO_PIN_CNF_DIR_Pos);    

NRF_GPIO->PIN_CNF[SDAPin] = 
    (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
  | (GPIO_PIN_CNF_DRIVE_S0D1     << GPIO_PIN_CNF_DRIVE_Pos)
  | (GPIO_PIN_CNF_PULL_Disabled  << GPIO_PIN_CNF_PULL_Pos)
  | (GPIO_PIN_CNF_INPUT_Connect  << GPIO_PIN_CNF_INPUT_Pos)
  | (GPIO_PIN_CNF_DIR_Output     << GPIO_PIN_CNF_DIR_Pos);    

nrf_gpio_pin_set(SDAPin);
nrf_gpio_pin_set(SCLPin);

unsigned int SDAVal = nrf_gpio_pin_read(SDAPin);
unsigned int SCLVal = nrf_gpio_pin_read(SCLPin);
SDAVal = nrf_gpio_pin_read(SDAPin);
SCLVal = nrf_gpio_pin_read(SCLPin);
SDAVal = nrf_gpio_pin_read(SDAPin);
SCLVal = nrf_gpio_pin_read(SCLPin);
SDAVal = nrf_gpio_pin_read(SDAPin);
SCLVal = nrf_gpio_pin_read(SCLPin);
SDAVal = nrf_gpio_pin_read(SDAPin);
SCLVal = nrf_gpio_pin_read(SCLPin);
SDAVal = nrf_gpio_pin_read(SDAPin);
SCLVal = nrf_gpio_pin_read(SCLPin);

if( SDAVal && SCLVal )
{
    //Continue with I2C initialisation here
}

I've added the pin reading multiple times to ensure it isn't related to errata 3.48 (using the Rev 1 sillicon). Here's output from debugging with GDB:

Breakpoint 1, ###
    at ###.c
:229
229         if( SDAVal && SCLVal )
(gdb) print SDAVal
$1 = 0 '\000'
(gdb) c
Continuing.

--- this is where I rerun the function ---

Breakpoint 1, ###
    at ###.c
:229
229         if( SDAVal && SCLVal )
(gdb) print SDAVal
$2 = 1 '\001'
(gdb) print nrf_gpio_pin_read(26)
$3 = 0
(gdb) print nrf_gpio_pin_read(27)
$4 = 0
(gdb) print nrf_gpio_pin_read(1)
$5 = 1

Any idea why this is happening? I'm using the S132 v5.0.0 softdevice on an nRF52832

Parents
    1. That seems to somewhat resolve it - for a short period of time. With a delay of 3ms it now works fine if I run the code as many times as I want in a row, if however I leave the module alone idle and then run it again after about 10 seconds, it goes back to the old behavior of wrongly detecting the pins as high.
    2. No reset at all, we have a command line interface for running parts of code, when no command is entered the system is idle.
    3. Both pins wrongly read high.
Reply
    1. That seems to somewhat resolve it - for a short period of time. With a delay of 3ms it now works fine if I run the code as many times as I want in a row, if however I leave the module alone idle and then run it again after about 10 seconds, it goes back to the old behavior of wrongly detecting the pins as high.
    2. No reset at all, we have a command line interface for running parts of code, when no command is entered the system is idle.
    3. Both pins wrongly read high.
Children
No Data
Related