8 years, 2 months ago.

RTC in BLE Nano

Hi,

Does anybody know if the BleNano has an internal RTC? I am trying to do something like this but it doesn´t work...

set_time(1256729737); while(true) { time_t seconds = time(NULL); printf("Time as seconds since January 1, 1970 = %d\r\n", seconds); printf("Time as a basic string = %s\r\n", ctime(&seconds));

char buffer[32]; strftime(buffer, 32, "%I:%M %p\r\n", localtime(&seconds)); printf("Time as a custom formatted string = %s\r\n\n", buffer); }

Thank you!

Question relating to:

BLE Nano is the smallest Bluetooth 4.1 Low Energy (BLE) development board in the market. The core is Nordic nRF51822 (an ARM Cortex-M0 SoC plus BLE capability) running at 16MHz …

3 Answers

8 years, 2 months ago.

The platform page does indicate RTC use, however it will not work on Mbed because the device.h setting has:

  1. define DEVICE_RTC 0

Which means no RTC, also there is no RTC_api.c in the library.

So if the hardware has the capabilities, then unless the API is written then the answer is no RTC is available.

I find this quite ridiculous, if the hardware has the capability then it should be available before Mbed adds it to the Platform page.

Hi Paul,

It is a pity we cannot use the RTC the deivce has, just because of the mbed API. Anyway I will figure out how to simulate something like a RTC...maybe a ticker (even though I´ll lose precision)...

Thank you very much for your quick reply!!

posted by Saul Davila Gonzalez 09 Feb 2016
8 years, 2 months ago.

Hi,
I do not have access to BLE Nano so I'm no able to test it but you might give the Clock library a try. It's a real time clock driven by a Ticker. A demo is also available for testing. However, since the Clock library is using the attach_rtc() function to make C time functions available I'm not sure it will work with BLE Nano.

Hi Tom,

I do not use the official mbed SDFileSystem. It is old and needs major updating. Instead, I use Neil Thiessen's version. It is more robust and he continually improves the library. Again, I've only tried this on a nRF51-DK, but it should work on a NANO as long as you change the pin names. I also used an Arduino based SD Flash card to make wiring everything up easier. I just had to add a wire for the SD Chip Detect pin.

Code Snippets:

#include "SDFileSystem.h"                   //SD file system

//SPI (PinName mosi, PinName miso, PinName sclk, PinName ssel=NC)

//    SPI_PSELMOSI0 = p25, D11 = p25,
//    SPI_PSELMISO0 = p28, D12 = p28,
//    SPI_PSELSS0   = p24, D10 = p24,
//    SPI_PSELSCK0  = p29, D13 = p29,

//    SPI_PSELMOSI1 = p13, D1  = p13,
//    SPI_PSELMISO1 = p14, D2  = p14,
//    SPI_PSELSS1   = p12, D0  = p12,
//    SPI_PSELSCK1  = p15, D3  = p15,

#define SDFILEPINS          D11, D12, D13, D10
#define NEWSD_ADDPINS       D9, SDFileSystem::SWITCH_NEG_NO   //using Arduino SPI pins on connector
SDFileSystem sd(SDFILEPINS, "sd", NEWSD_ADDPINS, 25000000);

int main() {
    sd.crc(true);
    sd.large_frames(false); //NOTE: 16 bit frames do not work with the K64F or KL25Z
    sd.write_validation(true);

//Make sure a card is present
    if (!sd.card_present()) {
        pc.printf("No card present!\r\n");
    } else {
        //Try to mount the SD card
        pc.printf(" - Mounting disk...  ");
        if (sd.mount() != 0) {
            pc.printf("***failed!\r\n");
        } else {
            pc.printf("success!\r\n");
        }

        pc.printf(" - SD Flash Card type: ");
        
        SDFileSystem::CardType cardType = sd.card_type();
        if (cardType == SDFileSystem::CARD_NONE) pc.printf("None\r\n");
        else if (cardType == SDFileSystem::CARD_MMC) pc.printf("MMC\r\n");
        else if (cardType == SDFileSystem::CARD_SD) pc.printf("SD\r\n");
        else if (cardType == SDFileSystem::CARD_SDHC) pc.printf("SDHC\r\n");
        else pc.printf("Unknown\r\n");
 
        //Display the card capacity
        pc.printf(" - Sectors: %llu\r\n" sd.disk_sectors());
        pc.printf(" - Capacity: %.1fMB\r\n", (sd.disk_sectors() * 512) / 1048576.0);
    }
    while(1) {
    }
}
posted by Kevin Braun 15 Apr 2016
8 years, 2 months ago.

Saul,

Here is an RTC hack made by Francis Schumacher last summer:

https://developer.mbed.org/users/fxschumacher/code/nrf51_rtc/

I have successfully used it in a nRF51-DK. It works, but it does have limitations.

1. The RTC is set to 0 at every reset, not just power cycles. You will need a way of reloading the RTC on every reboot. I use a DS3232M RTC chip.

2. If you use SDFileSystem, the file timestamp is always the same. This is probably due to the fact that the RTC hack output is not exactly the same as the mbed RTC output.

...kevin

Hi Kevin,

Thank you very much for your reply. I´ve tried it and it works perfectly.

Kind regards.

posted by Saul Davila Gonzalez 11 Feb 2016

hello Kevin, can you explain me that how using Ble nano at 1.8 v is different from using it at 3.3 v. does it affect the range of signal strength. Is there any way to increase the signal strength.?

thank you

posted by jayendra mishra 18 Feb 2016

Hi Jay,

I know nothing about the NANO, except that is uses a nRF51822.

I do own nRF51-mkit, nRF51-dongle, nRF51-dk and nRF52-dk. The later to which I am still waiting for mbed support on since Sept :-((

posted by Kevin Braun 18 Feb 2016

Hi Kevin,

Thanks for the info, RTC hack works perfectly on my BLE Nano v1.5 (32K nRF51822).

Sounds like you're using SDFileSystem on an nRF51822?

Any tips please? I'm having a hard time getting it working (not worried about timestamps) using https://developer.mbed.org/teams/mbed/code/SDFileSystem/

I'm new to mbed & debugging h/w, s/w issues on this platform. Any insight, links etc *very* much appreciated.

cheers, Tom

posted by Tom Gilbert 15 Apr 2016