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

Reading ADC in nRF52840

Hi,

I am new to development with Nordic chips. I am using nRF52840-DK (SES,nRF5_SDK_15.3.0_59ac345) to read analog input on ADC pin AIN0. I want to continuously read the adc after pairing is established and then broadcast the data over Bluetooth. In order to achieve my objective, I am trying to run ble_app_hrs example by combining the SAADC example with it. Is this approach correct.

When I compile my program using SES, I am getting the following error in nrfx_timer.h(line 74). I don't get this error if run the these examples individually.

'NRFX_TIMER0_INST_IDX' undeclared here (not in a function); did you mean 'NRFX_TIMER_INSTANCE'?

Thanks,

Jagbir

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* Copyright (c) 2014 - 2019, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Parents
  • Andreas,

    I was able to use the new function but I my program always ends up in a break point condition after log_init(). Am I initializing something multiple times ? See the following link.

    devzone.nordicsemi.com/.../nRF5_5F00_SDK_5F00_16.0.0_5F00_98a08e2_5F00_ble_5F00_app_5F00_uart_5F00_saadc_5F00_10_5F00_31.zip

  • Hi 

    Andreas has left Nordic unfortunately, and I will take over the case instead. 

    The problem with your code is that you initialize the UART before you enable logging. 

    Since the log module is configured to use the UART this means you are initializing it twice. 

    If you comment out the call to uart_init() your code should run. It crashes again because the RAM settings are incorrect, but the UART log will inform you how to fix this. 

    Best regards
    Torbjørn Øvrebekk

  • I am still getting the same error after disabling the uart_init().

    Couple of questions:

    1) In the source navigator window on SES, I do see an error message "unknown register name 'vfpcc' in asm" but this issue is not preventing me from building. I did search the devzone for this issue , in the Case ID: 208419 it's mentioned that this issue is just a visual distraction and doesn't impact building/code execution . I have confirmed that I use gcc instead of clang in my project but I am unsure why I am getting this error.

    2) How to access the UART log. How did you diagnose the RAM settings.

    Thanks.

  • Hi

    1) The reply from Johannes in the case you link to is describing the reason for this issue, no?
    Did you try his suggested fix, by making some modifications to the cmsis_gcc.h file?

    2) You have to connect to the CDC comport of your development kit, and set the baudrate to 115200. Then you should see the log output when you run your code, and the log will include the correct RAM settings for your project. 

    Best regards
    Torbjørn

  • 1) Yes, I did change the cmsis_gcc but it did not fix the error. Can we the ignore errors displayed the source navigator window on SES, 

    2) I have connected the dev kit to putty terminal with the desired setting but I don't see any output on putty screen.I have already attached the full project in the attachments here. Can you recreate the errors with nRf52840 DK with SES and debug it.

Reply
  • 1) Yes, I did change the cmsis_gcc but it did not fix the error. Can we the ignore errors displayed the source navigator window on SES, 

    2) I have connected the dev kit to putty terminal with the desired setting but I don't see any output on putty screen.I have already attached the full project in the attachments here. Can you recreate the errors with nRf52840 DK with SES and debug it.

Children
  • Hi 

    1) Yes, this error does not affect the program itself, it is only a convenience issue. 

    2) Yes, I get the following log output when I run your code (after commenting out the uart_init() call): 

    <info> app_timer: RTC: initialized.
    <warning> nrf_sdh_ble: Insufficient RAM allocated for the SoftDevice.
    <warning> nrf_sdh_ble: Change the RAM start location from 0x20002AE8 to 0x20002BE0.
    <warning> nrf_sdh_ble: Maximum RAM size for application is 0x3D420.
    <error> nrf_sdh_ble: sd_ble_enable() returned NRF_ERROR_NO_MEM.
    <error> app: Fatal error
    <warning> app: System reset

    After fixing this issue I got another problem related to the initialization of the ble_nus service. 
    The reason for this problem is that in order to use a proprietary service you need to set the NRF_SDH_BLE_VS_UUID_COUNT define in sdk_config.h equal to the number of unique 128-bit UUID's you are using in your application. 

    The ble_nus service needs 1 128-bit UUID, so you have to set this value to 1 or more and once again change the RAM settings to make room for this:

    <warning> nrf_sdh_ble: Change the RAM start location from 0x20002BE8 to 0x20002BF0.
    <warning> nrf_sdh_ble: Maximum RAM size for application is 0x3D410.

    After fixing the RAM settings again I now got an error because you are trying to initialize timer 0 in the application. The TIMER0 module is used by the SoftDevice, and can not be used by the application when the SoftDevice is in use. 

    To fix this problem I had to change this line (line 127 of main.c):

    static const nrf_drv_timer_t m_timer = NRF_DRV_TIMER_INSTANCE(0);

    to this:

    static const nrf_drv_timer_t m_timer = NRF_DRV_TIMER_INSTANCE(1);

    Then I had to modify sdk_config.h to enable TIMER1 instead of TIMER0. 

    With all this fixed the application appears to run nicely, and I can connect to the kit from my phone. 

    I attached the modified project for your reference:

    ble_app_uart.zip

    The only project I updated was the one in this folder:
    \ble_app_uart\pca10056\s140\ses

    Best regards
    Torbjørn

  • Ovrebekk,

    Thanks for your help.

    I am trying, step by step to replicate what you did to fix my code and I have few questions.

    As you mentioned, I was able to remove error 0x08 (Invalid state ) by commenting uart_init().

    After that I I started getting error 0x04 (No Memory for operation). I need to output the log to find the RAM address to fix this error. My problem is that I was not able to print any log output. How were you able to print the log output to find the RAM address.

    I tried using both the UART as well RTT logging to print the debug message. I found that both UART and RTT works for me with the sadc example.

    Thanks

  • I was able to print ouput on uart by initializing log but not on RTT. 

     uint32_t err_code = NRF_LOG_INIT(NULL);

  • I am not getting a reliable connection over UART. When I stop debugging then I getting following error. The message on the UART to change RAM parameters was different than that you found..

    RAM_START=0x20002BE0

    RAM_SIZE=0x3D420

    After changing the RAM settings to above, the call stack still gives me error 0x04 again and the UART prints following.

    <info> app_timer: RTC: initialized.
    <error> app: Fatal error
    <warning> app: System reset

    How do I debug this problem.Can you provide the steps you followed for debugging the problem related to the initialization of the ble_nus service.

  • Hi 

    Sorry for the late reply, I was on travel all last week. 

    Can you not get the project I sent you to work either?
    It is based on the code you sent me originally. 

    If you diff my code with yours you should see a list of all the changes I made. 

    Best regards
    Torbjørn