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

nRF52840 GPIO definition issue

Hi,

I am downloading my code to my custom board and sending commands through a USB virtual COM port. I basically echo and execute some GPIO operations after decoding the commands, then printing stuff to check that the right code was executed.

I have a small motor on my board, enabled by GPIO P0.14, and 3 LEDs. I have defined those GPIOs in custom_board.h as follows:

#define LEDS_NUMBER 3

#define RED_LED			NRF_GPIO_PIN_MAP(0,12)
#define GREEN_LED		NRF_GPIO_PIN_MAP(1,9)
#define BLUE_LED		NRF_GPIO_PIN_MAP(0,11)

#define LEDS_ACTIVE_STATE 0 
#define LEDS_LIST { RED_LED, GREEN_LED, BLUE_LED }

#define CONFIG_GPIO_AS_PINRESET

/Output GPIOs
#define MOTOR_EN_ERM	NRF_GPIO_PIN_MAP(0,14)
//And then some more GPIOs defined, and 2 SPI channels.

What is happening is that the motor GPIO works well by itself, responding to commands "motor on" and "motor off" as expected. But when I put LEDs to 1, the LEDs don't react, and when I put the LEDs to 0 the motor turns on, and I have to turn it off with "motor off".

Also, just after downloading the code to my board, I have to disconnect and reconnect the COM port, and after that, if I disconnect the COM port the motor turns on until I reconnect the COM port.

I have tinkered a bit with my code, and the signal that affects the motor is the Green LED signal, P1.9. Does anyone have any idea about what may be happening? Maybe I am missing something in my definitions? Thank you very much in advance.

Best regards,

Alin O. Dragomir

Parents
  • Hi,

    Today I have managed to make the GPIOs work by redefining them as outputs when I set or clear them. However, after that I cannot successfully read the value of the GPIO. I imagine that I could define the GPIO as input before reading its state, but i don't know if when doing that the nRF52840 would keep driving the GPIO or I would have to inmediately redefine the GPIO as output and re-write its value, which doesn't look quite optimal. If you could clarify me how is the best method of doing that, it would save me a lot of time and trial-and-error. Thank you

  • A GPIO pin can only be configured to be in or out, not in and out. But why would you want that in the first place? If you have set or cleared a gpio output pin, you know it's state, so why do you want to read it?

    That said, if you you change a pin to an input it will be in a high impedance state (not driven high or low), regardless of what it was before when it was configured as an output.

Reply Children
Related