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

libuarte: Connection between NRF9160dk and NRF52840

Hi,

If there is already a FAQ, Code or support ticket that I missed, I am more than happy to read it.  I have done a number of searches but cant quite get to what I am looking for.

Setup:
I am trying to get communications between the52840 and 9160 on the 9160DK, using libuarte.  I am using zephyr on the 9160 side an the  nrf-sdk on the 52840 side (as I need ANT+).

A few articles I read were using uart1 for this type of communications, so I cut/paste what was in there.  From what I could gather, a way to do this was to use the MCU_IF with pins 17/18 (9160) => 17/20 (52840)

9160 (.overlay file):

&uart1 {
compatible = "nordic,nrf-uarte";
status = "okay";
current-speed = <115200>;
hw-flow-control;
rx-pin = <17>; /* <&interface_to_nrf52840 0 0>; */
tx-pin = <18>; /* <&interface_to_nrf52840 1 0>; */
cts-pin = <19>; /* <&interface_to_nrf52840 2 0>; */
rts-pin = <21>; /* <&interface_to_nrf52840 3 0>; */
};
9160 (main.c)
Device binding is to UART_1:
struct device *uart = device_get_binding("UART_1");

52840 (main.c)

nrf_libuarte_async_config_t nrf_libuarte_async_config = {
        .tx_pin = 17,
        .rx_pin = 20,
        .baudrate = NRF_UARTE_BAUDRATE_115200,
        .parity = NRF_UARTE_PARITY_EXCLUDED,
        .hwfc = NRF_UARTE_HWFC_DISABLED,
        .timeout_us = 100,
        .int_prio = APP_IRQ_PRIORITY_LOW};

Question:

I can get all of this to work (or appears to) when I;
* start the 9160
* move sw to nRF52
* build->debug from SES
 -> click the green run button

* This appears to do everything correctly, receives ANT+, transmits from 52840 to 9160 and I can see it display on the 9160 tty port (using screen).

If I do it any other way, its as if the code on the 52840 is not running, or there is a problem with the connection or a timing issue ?

I added a nrf_delay_ms(5000) at the start of the 52840 code, just in case there was a timing issue between the 9160 and 52840 in that the UART was not ready - but that didnt work.

What am I missing here ?
I feel I have done every possible combination of switches, power and reset, but the only way I can get it to work is if I use SES Build->Debug 

thanks in advance

-brett

Parents
  • Hi Brett,

    On the 52840 side, could you try to call sd_clock_hfclk_request() after enabling the Softdevice? This will make the Softdevice keep the HF crystal oscillator (HFXO) on and in turn increase the accuracy of the UART baudrate generator (it runs off the less accurate HFINT clock by default). I think it's worth trying since you seem to get more stable performance when you keep the chip in debug mode.

    I will try to see if I can replicate it here if the above doesn't help.

    Best regards,

    Vidar

  • Hi Vidar,

    No difference.  It still works in debug mode but fails otherwise.

    -brett

  • OK, thanks for confirming. I've set up a simple loopback test here now with libuarte running on the 52840 and the Zephyr async driver on the nRF9160 and that seems to work fine. Could you try these 2 projects on your end and see if it works for you as well? Maybe you can spot what we're doing differently.

    uart_com_test_52840_9160.zip

    -Vidar

    Edit: This example selected the wrong UARTE instance. Use the updated projects I uploaded here https://devzone.nordicsemi.com/f/nordic-q-a/79351/libuarte-connection-between-nrf9160dk-and-nrf52840/330790#330790 instead.

  • Hi Vidar,

    I compiled you code (west build -c -p -b nrf9160dk_nrf9160ns), which worked fine and the flash went fine, but on the 9160 I get the following error.

    BTW: The 52840 complied and loaded fine.

    *** Booting Zephyr OS build v2.6.0-rc1-ncs1 ***
    Flash regions Domain Permissions
    00 01 0x00000 0x10000 Secure rwxl
    02 31 0x10000 0x100000 Non-Secure rwxl

    Non-secure callable region 0 placed in flash region 1 with size 32.

    SRAM region Domain Permissions
    00 07 0x00000 0x10000 Secure rwxl
    08 31 0x10000 0x40000 Non-Secure rwxl

    Peripheral Domain Status
    00 NRF_P0 Non-Secure OK
    01 NRF_CLOCK Non-Secure OK
    02 NRF_RTC0 Non-Secure OK
    03 NRF_RTC1 Non-Secure OK
    04 NRF_NVMC Non-Secure OK
    05 NRF_UARTE1 Non-Secure OK
    06 NRF_UARTE2 Secure SKIP
    07 NRF_TWIM2 Non-Secure OK
    08 NRF_SPIM3 Non-Secure OK
    09 NRF_TIMER0 Non-Secure OK
    10 NRF_TIMER1 Non-Secure OK
    11 NRF_TIMER2 Non-Secure OK
    12 NRF_SAADC Non-Secure OK
    13 NRF_PWM0 Non-Secure OK
    14 NRF_PWM1 Non-Secure OK
    15 NRF_PWM2 Non-Secure OK
    16 NRF_PWM3 Non-Secure OK
    17 NRF_WDT Non-Secure OK
    18 NRF_IPC Non-Secure OK
    19 NRF_VMC Non-Secure OK
    20 NRF_FPU Non-Secure OK
    21 NRF_EGU1 Non-Secure OK
    22 NRF_EGU2 Non-Secure OK
    23 NRF_DPPIC Non-Secure OK
    24 NRF_REGULATORS Non-Secure OK
    25 NRF_PDM Non-Secure OK
    26 NRF_I2S Non-Secure OK
    27 NRF_GPIOTE1 Non-Secure OK

    SPM: NS image at 0x10000
    SPM: NS MSP at 0x20010a80
    SPM: NS reset vector at 0x11885
    SPM: prepare to jump to Non-Secure image.
    *** Booting Zephyr OS build v2.6.0-rc1-ncs1 ***
    uart_init() failed. (err: -6)

    cheers

    -brett

Reply
  • Hi Vidar,

    I compiled you code (west build -c -p -b nrf9160dk_nrf9160ns), which worked fine and the flash went fine, but on the 9160 I get the following error.

    BTW: The 52840 complied and loaded fine.

    *** Booting Zephyr OS build v2.6.0-rc1-ncs1 ***
    Flash regions Domain Permissions
    00 01 0x00000 0x10000 Secure rwxl
    02 31 0x10000 0x100000 Non-Secure rwxl

    Non-secure callable region 0 placed in flash region 1 with size 32.

    SRAM region Domain Permissions
    00 07 0x00000 0x10000 Secure rwxl
    08 31 0x10000 0x40000 Non-Secure rwxl

    Peripheral Domain Status
    00 NRF_P0 Non-Secure OK
    01 NRF_CLOCK Non-Secure OK
    02 NRF_RTC0 Non-Secure OK
    03 NRF_RTC1 Non-Secure OK
    04 NRF_NVMC Non-Secure OK
    05 NRF_UARTE1 Non-Secure OK
    06 NRF_UARTE2 Secure SKIP
    07 NRF_TWIM2 Non-Secure OK
    08 NRF_SPIM3 Non-Secure OK
    09 NRF_TIMER0 Non-Secure OK
    10 NRF_TIMER1 Non-Secure OK
    11 NRF_TIMER2 Non-Secure OK
    12 NRF_SAADC Non-Secure OK
    13 NRF_PWM0 Non-Secure OK
    14 NRF_PWM1 Non-Secure OK
    15 NRF_PWM2 Non-Secure OK
    16 NRF_PWM3 Non-Secure OK
    17 NRF_WDT Non-Secure OK
    18 NRF_IPC Non-Secure OK
    19 NRF_VMC Non-Secure OK
    20 NRF_FPU Non-Secure OK
    21 NRF_EGU1 Non-Secure OK
    22 NRF_EGU2 Non-Secure OK
    23 NRF_DPPIC Non-Secure OK
    24 NRF_REGULATORS Non-Secure OK
    25 NRF_PDM Non-Secure OK
    26 NRF_I2S Non-Secure OK
    27 NRF_GPIOTE1 Non-Secure OK

    SPM: NS image at 0x10000
    SPM: NS MSP at 0x20010a80
    SPM: NS reset vector at 0x11885
    SPM: prepare to jump to Non-Secure image.
    *** Booting Zephyr OS build v2.6.0-rc1-ncs1 ***
    uart_init() failed. (err: -6)

    cheers

    -brett

Children
  • Hi Brett,

    Can you try to build for "nrf9160dk_nrf9160" instead? Seems like the UART instance I selected won't initialize in the non-secure domain for some reason.  

    Cheers

    Vidar

    Update: I had forgotten to include an overlay file for nrf9160dk_nrf9160_ns so that's why it didn't work. To fix this you can make a copy of the nrf9160dk_nrf9160.overlay file in "boards" and and name it nrf9160dk_nrf9160_ns.overlay.

  • Hi Vidar,

    It worked on the nrf9160df_nrf9160, and after I copied the overlay to nrf9160dk_nrf9160ns.overlay it works as well.  (note: I used nrf9160dk_nrf9160ns and not nrf9160dk_nrf9160_ns).

    I will work from this to see if I can work out what the differences are.

    cheers

    -brett

  • Hi Vidar,

    Your code by itself works fine, so I have tried to identify any differences between them.

    Both lots of settings basically the same now (not identical as I have softdevice/ANT+ code) and the same thing happens, I can run the code in SES-Debug mode and all works, but as soon as I just run or power cycle the unit, I dont get the data through.

    Q: I am using the s340 soft device, doest that influence the clock or timers I need to use ?

    Q: Does the SES debug provide clock differently than not using it ?

    The obvious difference I have between the 2 code bases is below, hence the reason for my timer/RTC question.

    Mine:

    NRF_LIBUARTE_ASYNC_DEFINE(libuarte, 0, 1, 2, NRF_LIBUARTE_PERIPHERAL_NOT_USED, 255, 4);

    Yours:

    NRF_LIBUARTE_ASYNC_DEFINE(libuarte, 0, 0, 0, NRF_LIBUARTE_PERIPHERAL_NOT_USED, 255, 3);

    cheers

    -brett

  • Hi Brett,

    Your configuration looks fine. You have to select TIMER1  like you did as TIMER0 is reserved to the Softdevice.

    Brett said:
    Q: I am using the s340 soft device, doest that influence the clock or timers I need to use ?

    The only difference is that you can't use TIMER0 like mentioned above.

    Brett said:
    Q: Does the SES debug provide clock differently than not using it ?

    The HF clock is kept always on while in debug mode, but you will get the same effect by calling sd_clock_hfclk_request()  like I suggested in my initial reply. So I don't think the issue is clock related.

    Have you enabled flow control on the 52840 side like I did in my example? I noticed you only had it on the 9160 in the initial code you posted. In that case, do you get a "busy" error if you try to send data from the 9160?

    Cheers,

    Vidar

  • Hi Vidar,

    For now I am only trying to send data from the 52840 to the 9160 - so the flow-control should not be an issue ?

    I have attached the code that I have, if you are able to try this on your board to see if it works for you, and/or if there is something obvious I have missed.

    Note; This code is a cut/paste from one of the BLE examples which I have not completely cleaned up yet.
    This code has also been cut down to send `1` every 5 seconds over the UART connection, so your 9160 receiver should be able to get the message and log it.

    cheers

    -brett

    app_libUARTE.tar.gz

Related