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

nRF9160 how to change baud rate of UART1 to 9600?

I'm successfully printing to the UART1 com port at baud rate 115200, but I have a peripheral I plan to connect that requires 9600.  What is the proper way to go about this?  Are there multiple places this needs to be changed or is there one config I can set?

I did try changing the config here:

zephyr\ext\hal\nordic\nrfx_config_nrf9160.h

but it didn't appear to work as I expected

Thank you!

  • EDIT: I'm just gonna ask, when i posted that snippet of code at the start, did you change the RX and TX pins to reflect your board? I just noticed your output from your build folder has my pins 22 and 23 as TX and RX, is that your pins as well? This would explain why you are no longer seeing anything on UART1.

  • Sorry but I'm missing one thing..  I'm currently building my project with these commands:

    mkdir -p build
    rm -r build/*
      
    west build -b nrf9160_pca10090ns -d build && \
    nrfjprog --eraseall -f nrf91 && \
    nrfjprog --program build/zephyr/merged.hex --sectorerase -r -f nrf91 --verify

    Are you referring to the spm directory in the build folder?  Isn't that generated by west build command?  And rebuilding the spm directory would result in erasing the overlay file, correct?  

    Just in case, I went ahead and reverted the .dts, added the two overlay files, and rebuilt without cleaning the build directory at all.  It appears to be the same behavior and here is my generated_dts_board_unfixed.h:

    /* uart@9000 */
    #define DT_NORDIC_NRF_UARTE_1				1
    #define DT_NORDIC_NRF_UARTE_40009000_BASE_ADDRESS	0x40009000
    #define DT_NORDIC_NRF_UARTE_40009000_CTS_PIN		31
    #define DT_NORDIC_NRF_UARTE_40009000_CURRENT_SPEED	9600
    #define DT_NORDIC_NRF_UARTE_40009000_IRQ_0		9
    #define DT_NORDIC_NRF_UARTE_40009000_IRQ_0_PRIORITY	1
    #define DT_NORDIC_NRF_UARTE_40009000_LABEL		"UART_1"
    #define DT_NORDIC_NRF_UARTE_40009000_RTS_PIN		30
    #define DT_NORDIC_NRF_UARTE_40009000_RX_PIN		23
    #define DT_NORDIC_NRF_UARTE_40009000_SIZE		4096
    #define DT_NORDIC_NRF_UARTE_40009000_TX_PIN		22
    #define DT_NORDIC_NRF_UARTE_1_BASE_ADDRESS		DT_NORDIC_NRF_UARTE_40009000_BASE_ADDRESS
    #define DT_NORDIC_NRF_UARTE_1_CTS_PIN			DT_NORDIC_NRF_UARTE_40009000_CTS_PIN
    #define DT_NORDIC_NRF_UARTE_1_CURRENT_SPEED		DT_NORDIC_NRF_UARTE_40009000_CURRENT_SPEED
    #define DT_NORDIC_NRF_UARTE_1_IRQ_0			DT_NORDIC_NRF_UARTE_40009000_IRQ_0
    #define DT_NORDIC_NRF_UARTE_1_IRQ_0_PRIORITY		DT_NORDIC_NRF_UARTE_40009000_IRQ_0_PRIORITY
    #define DT_NORDIC_NRF_UARTE_1_LABEL			DT_NORDIC_NRF_UARTE_40009000_LABEL
    #define DT_NORDIC_NRF_UARTE_1_RTS_PIN			DT_NORDIC_NRF_UARTE_40009000_RTS_PIN
    #define DT_NORDIC_NRF_UARTE_1_RX_PIN			DT_NORDIC_NRF_UARTE_40009000_RX_PIN
    #define DT_NORDIC_NRF_UARTE_1_SIZE			DT_NORDIC_NRF_UARTE_40009000_SIZE
    #define DT_NORDIC_NRF_UARTE_1_TX_PIN			DT_NORDIC_NRF_UARTE_40009000_TX_PIN
    #define DT_NORDIC_NRF_UARTE_UART_1_BASE_ADDRESS		DT_NORDIC_NRF_UARTE_40009000_BASE_ADDRESS
    #define DT_NORDIC_NRF_UARTE_UART_1_CTS_PIN		DT_NORDIC_NRF_UARTE_40009000_CTS_PIN
    #define DT_NORDIC_NRF_UARTE_UART_1_CURRENT_SPEED	DT_NORDIC_NRF_UARTE_40009000_CURRENT_SPEED
    #define DT_NORDIC_NRF_UARTE_UART_1_IRQ			DT_NORDIC_NRF_UARTE_40009000_IRQ_0
    #define DT_NORDIC_NRF_UARTE_UART_1_IRQ_PRIORITY		DT_NORDIC_NRF_UARTE_40009000_IRQ_0_PRIORITY
    #define DT_NORDIC_NRF_UARTE_UART_1_LABEL		DT_NORDIC_NRF_UARTE_40009000_LABEL
    #define DT_NORDIC_NRF_UARTE_UART_1_RTS_PIN		DT_NORDIC_NRF_UARTE_40009000_RTS_PIN
    #define DT_NORDIC_NRF_UARTE_UART_1_RX_PIN		DT_NORDIC_NRF_UARTE_40009000_RX_PIN
    #define DT_NORDIC_NRF_UARTE_UART_1_SIZE			DT_NORDIC_NRF_UARTE_40009000_SIZE
    #define DT_NORDIC_NRF_UARTE_UART_1_TX_PIN		DT_NORDIC_NRF_UARTE_40009000_TX_PIN
    #define UART_1_BASE_ADDRESS __DEPRECATED_MACRO 		DT_NORDIC_NRF_UARTE_40009000_BASE_ADDRESS
    #define UART_1_CTS_PIN __DEPRECATED_MACRO 		DT_NORDIC_NRF_UARTE_40009000_CTS_PIN
    #define UART_1_CURRENT_SPEED __DEPRECATED_MACRO 	DT_NORDIC_NRF_UARTE_40009000_CURRENT_SPEED
    #define UART_1_IRQ __DEPRECATED_MACRO 			DT_NORDIC_NRF_UARTE_40009000_IRQ_0
    #define UART_1_IRQ_PRIORITY __DEPRECATED_MACRO 		DT_NORDIC_NRF_UARTE_40009000_IRQ_0_PRIORITY
    #define UART_1_LABEL __DEPRECATED_MACRO 		DT_NORDIC_NRF_UARTE_40009000_LABEL
    #define UART_1_RTS_PIN __DEPRECATED_MACRO 		DT_NORDIC_NRF_UARTE_40009000_RTS_PIN
    #define UART_1_RX_PIN __DEPRECATED_MACRO 		DT_NORDIC_NRF_UARTE_40009000_RX_PIN
    #define UART_1_SIZE __DEPRECATED_MACRO 			DT_NORDIC_NRF_UARTE_40009000_SIZE
    #define UART_1_TX_PIN __DEPRECATED_MACRO 		DT_NORDIC_NRF_UARTE_40009000_TX_PIN

  • I am referring to this when I refer to SPM

    https://github.com/NordicPlayground/fw-nrfconnect-nrf/tree/master/samples/nrf9160/spm

    This is your Secure Partition Manager. It must be rebuilt each time you alter the dts. When you build here, you are building for the secure part of flash. When you build in your projects, you are building for the non-secure region of flash and that's why both need overlays and their own dts files.

    Did you see my last message about making sure your UART pins are configured correctly in your files? Your TX and RX pins are the same as what I originally shared and it's unlikely that they were also your intended pins for UART1 Grinning

  • YES!! Nice catch!  The final solution is changing my .dts files at 

    ncs/zephyr/boards/arm/nrf9160_pca10090/nrf9160_pca10090ns.dts 

    and 

    ncs/zephyr/boards/arm/nrf9160_pca10090/nrf9160_pca10090.dts 

    to have this at the end:

    &uart1 {
      status = "ok";
      current-speed = <9600>;
      tx-pin = <1>;
      rx-pin = <0>;
      rts-pin = <14>;
      cts-pin = <15>;
    };

    You are amazing thanks again!!

  • Glad to hear you got it working. Happy coding! Smile

Related