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

is PSEL register setting for resp. peripheral automatically configure IO pin setting ?

#include "nrf_delay.h"
#include "nrf_gpio.h"

void uart_init()
{
   
     NRF_UART0->BAUDRATE = 0x01D7E000;
     NRF_UART0->CONFIG = 0x00000001;

     NRF_UART0->PSELRTS = 5;
     NRF_UART0->PSELTXD = 6;
     NRF_UART0->PSELCTS = 7;
     NRF_UART0->PSELRXD = 8;
    
//     nrf_gpio_cfg_output(6);
//     nrf_gpio_cfg_input(8, GPIO_PIN_CNF_PULL_Disabled);
// 
//     nrf_gpio_cfg_output(5);
//     nrf_gpio_cfg_input(7, GPIO_PIN_CNF_PULL_Disabled);

    NRF_UART0->ENABLE = 0x00000004;
    
    NRF_UART0->TASKS_STARTTX = 1;

}

void uart_write(unsigned char data)
{
    NRF_UART0->TXD = data;
        
    while(NRF_UART0->EVENTS_TXDRDY==0){}

    NRF_UART0->EVENTS_TXDRDY = 0; 

}

int main(void)
{
  NRF_P0->DIR |= 0x000E0000;
  NRF_P0->OUTSET |= 0x000E0000;
  
  uart_init();

  while(1) 
  {
 
    NRF_P0->OUT^=0x00080000;
     
    uart_write('@');
    
    nrf_delay_ms(100);

  }
}

This is working code for uart transmitter using direct register access. My question : is PSEL register setting for resp. peripheral automatically configure IO pin setting ?

As per my board pins. 5,6,7,8 are connected to RTS, TXD, CTS, RXD resp. to CP2101. So is it necessary to configure pins 5,6,7,8 for input, output, pull-up, pull-down OR PSEL setting automatically takes care of it ??

Because even after I comment out IO setting , there is no effect on working.

Excuse me for my English !!

Parents
  • I know. I guess I didn't explicitly answer your initial question. When you enable the UART it takes control of the pins and you don't have to configure pin 5-8 as inputs and outputs with pull resistors. What I was trying to convey is that your code seems to be working on the nRF5, so if your application doesn't work it is probably something wrong with your PCB or whatever it is you have connected to the "other end" of the UART?

Reply
  • I know. I guess I didn't explicitly answer your initial question. When you enable the UART it takes control of the pins and you don't have to configure pin 5-8 as inputs and outputs with pull resistors. What I was trying to convey is that your code seems to be working on the nRF5, so if your application doesn't work it is probably something wrong with your PCB or whatever it is you have connected to the "other end" of the UART?

Children
No Data
Related