Simple adv_ind with nrf52832

Hello,

I have here nrf52832 installed in a wristwatch called PineTime.

I program nrf52832 directly (only gcc none eabi), completely without SDK and without SoftDevice. This works very well so far.

Now for weeks I try in vain to activate Bluetooth and send ADV_IND. This does not succeed. To receive my tests I have nrf52840-dongle with WireShark. Somehow it doesn't matter what I do. I can not receive anything from my nrf52832. I receive all kinds of other devices around me. But not my nrf52832.

Can someone help me possibly? Or is there somewhere possibly a simple example how sending adv_ind works successfully. Or can you point me to errors in my code?

Thanks in advance.

#define BLUE_TASK_TX_ENABLE             *(volatile unsigned int *) 0x40001000
#define BLUE_TASK_RX_ENABLE             *(volatile unsigned int *) 0x40001004
#define BLUE_TASK_START                 *(volatile unsigned int *) 0x40001008
#define BLUE_TASK_STOP                  *(volatile unsigned int *) 0x4000100C
#define BLUE_TASK_DISABLE               *(volatile unsigned int *) 0x40001010
#define BLUE_EVENT_READY                *(volatile unsigned int *) 0x40001100
#define BLUE_EVENT_ADDRESS              *(volatile unsigned int *) 0x40001104
#define BLUE_EVENT_PAYLOAD              *(volatile unsigned int *) 0x40001108
#define BLUE_EVENT_END                  *(volatile unsigned int *) 0x4000110C
#define BLUE_EVENT_DISABLED             *(volatile unsigned int *) 0x40001110
#define BLUE_SHORTS                     *(volatile unsigned int *) 0x40001200
#define BLUE_INTERRUPT_SET              *(volatile unsigned int *) 0x40001304
#define BLUE_INTERRUPT_CLEAR            *(volatile unsigned int *) 0x40001308
#define BLUE_CRC_STATUS                 *(volatile unsigned int *) 0x40001400
#define BLUE_PACKET_PTR                 *(volatile unsigned int *) 0x40001504
#define BLUE_FREQUENCY                  *(volatile unsigned int *) 0x40001508
#define BLUE_TX_POWER                   *(volatile unsigned int *) 0x4000150C
#define BLUE_MODE                       *(volatile unsigned int *) 0x40001510
#define BLUE_PACKET_CONFIG_0            *(volatile unsigned int *) 0x40001514
#define BLUE_PACKET_CONFIG_1            *(volatile unsigned int *) 0x40001518
#define BLUE_BASE_ADDRESS_0             *(volatile unsigned int *) 0x4000151C
#define BLUE_BASE_ADDRESS_1             *(volatile unsigned int *) 0x40001520
#define BLUE_PREFIX_ADDRESS_0           *(volatile unsigned int *) 0x40001524
#define BLUE_PREFIX_ADDRESS_1           *(volatile unsigned int *) 0x40001528
#define BLUE_TX_ADDRESS                 *(volatile unsigned int *) 0x4000152C
#define BLUE_RX_ADDRESSES               *(volatile unsigned int *) 0x40001530
#define BLUE_CRC_CONFIG                 *(volatile unsigned int *) 0x40001534
#define BLUE_CRC_POLY                   *(volatile unsigned int *) 0x40001538
#define BLUE_CRC_INIT                   *(volatile unsigned int *) 0x4000153C
#define BLUE_STATE                      *(volatile unsigned int *) 0x40001550
#define BLUE_DATA_WHITENING_INIT_VALUE  *(volatile unsigned int *) 0x40001554
#define BLUE_RADIO_MODE_CONFIG          *(volatile unsigned int *) 0x40001650
#define BLUE_POWER                      *(volatile unsigned int *) 0x40001FFC

#define BLUETOOTH_STATE_DISABLED        0
#define BLUETOOTH_STATE_RX_RU           1
#define BLUETOOTH_STATE_RX_IDLE         2
#define BLUETOOTH_STATE_RX              3
#define BLUETOOTH_STATE_RX_DISABLE      4
#define BLUETOOTH_STATE_TX_RU           9
#define BLUETOOTH_STATE_TX_IDLE         10
#define BLUETOOTH_STATE_TX              11
#define BLUETOOTH_STATE_TX_DISABLE      12


static unsigned char blue_ram_tx_buffer[256];


// Bluetooth

//     Data
blue_ram_tx_buffer [ 0] = 0x00;                               // BLE Header (PDU_TYPE: SCAN_REQ, TXadd, RXadd)
blue_ram_tx_buffer [ 1] = 0x0C;                               // Length of payload: 12
blue_ram_tx_buffer [ 2] = 0xDE;                               // InitAddr LSByte first
blue_ram_tx_buffer [ 3] = 0xDE;
blue_ram_tx_buffer [ 4] = 0xDE;
blue_ram_tx_buffer [ 5] = 0xDE;
blue_ram_tx_buffer [ 6] = 0xDE;
blue_ram_tx_buffer [ 7] = 0xDE;
blue_ram_tx_buffer [ 8] = 0xAA;                               // AdvAddr LSByte first
blue_ram_tx_buffer [ 9] = 0xAA;
blue_ram_tx_buffer [10] = 0xAA;
blue_ram_tx_buffer [11] = 0xAA;
blue_ram_tx_buffer [12] = 0xAA;
blue_ram_tx_buffer [13] = 0xAA;


//    Bluetooth Reset
BLUE_POWER = 0; // Bluetooth PowerOFF
for (unsigned int i=0xFF;i>0;i--) {;} // Small break (how long, not defined anywhere)
BLUE_POWER = 1; // Bluetooth PowerON

//    Bluetooth Set signal strength 
BLUE_TX_POWER = 0; //   0 dBm

//    Frequency for transmission
BLUE_FREQUENCY = 2; // 2402 MHz - Corresponds to channel 37

//    Datawhithening Init
BLUE_DATA_WHITENING_INIT_VALUE = 0xFF; // Is that correct?

//    Advertising Address 0x8E89BED6
BLUE_PREFIX_ADDRESS_0 = 0x8E;
BLUE_BASE_ADDRESS_0 = 0x89BED600;

//    Select Address
BLUE_TX_ADDRESS = 0x00; // (prefix0 + base0) = 0x8E89BED6
BLUE_RX_ADDRESSES = 0x01;

// Radio Mode
BLUE_MODE = 3; // 3 - BLE 1Mbit

// Radio config
BLUE_RADIO_MODE_CONFIG = 1 | (2 << 8); // Fast Ramp-Up + Transmit-Center-Frequency

//    Konfiguration 
BLUE_PACKET_CONFIG_0 = 0; // 0 - LFLEN (bits); 0 - S0 (bytes); 0 - S1 (bits);
BLUE_PACKET_CONFIG_1 = 15 | (3 << 16) | (1 << 25); // 15 - Maxlen; 3 - Balen; 1 - Whiteening

//    CRC Config
BLUE_CRC_CONFIG = 3 | (1 << 8); // 3 - CRC-Bytes; 1 - Exclude address
BLUE_CRC_INIT = 0x00555555; // Initial value CRC (24 Bit)
BLUE_CRC_POLY = 0x0000065B; // Would be standart for BLE (24 Bit)

//    Clear events
BLUE_EVENT_READY = 0;
BLUE_EVENT_END = 0;
BLUE_EVENT_ADDRESS = 0;
BLUE_EVENT_PAYLOAD = 0;
BLUE_EVENT_DISABLED = 0;

//    PTR to Data
BLUE_PACKET_PTR = (unsigned int) &blue_ram_tx_buffer;

//    Radio Ramp Up
BLUE_TASK_RX_ENABLE = 0;
BLUE_TASK_TX_ENABLE = 1;

//    Wait until radio is ready
while (BLUE_EVENT_READY == 0) {;}
while (BLUE_STATE != BLUETOOTH_STATE_TX_IDLE) {;}


//    Start radio TX
BLUE_TASK_START = 1;

Parents
  • Is you board capable of transmitting?

    Have you tested your custom board with any of our BLE examples? 

  • of course, the original firmware, in my case from PineTime, works and is able to send.

    I think I made a mistake somewhere, for example in the access address (Prefix+Base) or possibly several errors in different places at the same time.

    The radio goes through all the states as described in the instructions for nrf52832-v1.4 under the point 23.7. These states can be read from the register 0x40001550. After initiating and starting the radio goes normally into TX and then into TXIDLE. Everything as it should be, except that I can not receive anything.

  • There I did not find much understandable, on the value of 0x65B I came, because I saw it here so: https://github.com/NordicPlayground/nRF51-multi-role-conn-observer-advertiser/blob/master/btle_hci/scanner/radio.c

    I don't know if the accuracy CRC or whitening gets us anywhere at all. I receive via USB dongle also many erroneous packets (CRC is wrong). So I suppose even if CRC is calculated wrong, packet will still be sent and will be able to be received.

    Do you know if I still need to initialize any hardware to make bluetooth radio work? Maybe I forgot to initialize something else?


  • "3.1.1 CRC generation
    ...
    The CRC polynomial is a 24-bit CRC and all bits in the PDU shall be processed in transmitted order starting from the least significant bit. The polynomial has
    the form of x24 + x10 + x9 + x6 + x4 + x3 + x + 1. "

    From CRCPOLY register specs:
    "Each term in the CRC polynomial is mapped to a bit in this register which index corresponds to the term's exponent. The least significant term/bit is hard-wired internally to 1, and bit number 0 of the register content is ignored by the hardware. The following example is for an 8 bit CRC polynomial: x8 + x7 + x3 + x2 + 1 = 1 1000 1101 . "

    ---> 100000000000011001011011b = 0x80065B. Remove the lsb (x^24) and you end up with 0x65B.

    32mb said:
    I don't know if the accuracy CRC or whitening gets us anywhere at all. I receive via USB dongle also many erroneous packets (CRC is wrong). So I suppose even if CRC is calculated wrong, packet will still be sent and will be able to be received.
    Somehow it doesn't matter what I do. I can not receive anything from my nrf52832.

    Are you receiving packets from your device or not?

  • no, I still cannot receive anything.

    in the PDF at 23.8 "Transmit sequence" I also read that Ready and Start must be connected (as well as End and Disabled) so that the timing for the carrier frequency is correct. I have tried that too.

    BLUE_SHORTS = 1 | (1 << 1); // Ready -> Start; End -> Disable

    In this case the radio must be started like this:

    BLUE_TASK_TX_ENABLE = 1;

    Unfortunately, that didn't help either.

    The radio goes through all states normally. But I still can not receive anything.

  • Is the HFXO turned on before you start transmitting? 

    See this old example for how to send BLE advertisement broadcasts: https://github.com/NordicPlayground/solar_sensor_beacon 

  • Bingo! It works! The reason was HFXO. In the section 23 for radio is nowhere written that HFXO is necessary and I actually only read LFXO and only turned on LFXO. But in section 19.1 about HFCLK it is written that you absolutely need HFXO for Bluetooth.

    Now I can receive an undefined packet of 170 bytes (196 in total) with my code from above:

    Frame 8098: 196 bytes on wire (1568 bits), 196 bytes captured (1568 bits) on interface /tmp/wireshark_extcap_-dev-ttyACM0-3.4DXQA11, id 0
    Nordic BLE Sniffer
    Bluetooth Low Energy Link Layer
        Access Address: 0x8e89bed6
        Packet Header: 0xaaaa (PDU Type: Unknown)
            .... 1010 = PDU Type: 0xa Unknown
            ...0 .... = Reserved: 0
            ..1. .... = Reserved: 1
            .0.. .... = Reserved: 0
            1... .... = Reserved: 1
            Length: 170
        Unknown data
            [Expert Info (Note/Protocol): Unknown data]
                [Unknown data]
                [Severity level: Note]
                [Group: Protocol]
        CRC: 0x185c3f
            [Expert Info (Warning/Checksum): Incorrect CRC]
    

    Now I can continue to experiment myself =D

    Thank you very much. Especially for your patience. Now come my obligations. I can transfer by PayPal or WesternUnion. For this I need your contact details. Either here in the forum or email me at: info-at-32mb.de

Reply
  • Bingo! It works! The reason was HFXO. In the section 23 for radio is nowhere written that HFXO is necessary and I actually only read LFXO and only turned on LFXO. But in section 19.1 about HFCLK it is written that you absolutely need HFXO for Bluetooth.

    Now I can receive an undefined packet of 170 bytes (196 in total) with my code from above:

    Frame 8098: 196 bytes on wire (1568 bits), 196 bytes captured (1568 bits) on interface /tmp/wireshark_extcap_-dev-ttyACM0-3.4DXQA11, id 0
    Nordic BLE Sniffer
    Bluetooth Low Energy Link Layer
        Access Address: 0x8e89bed6
        Packet Header: 0xaaaa (PDU Type: Unknown)
            .... 1010 = PDU Type: 0xa Unknown
            ...0 .... = Reserved: 0
            ..1. .... = Reserved: 1
            .0.. .... = Reserved: 0
            1... .... = Reserved: 1
            Length: 170
        Unknown data
            [Expert Info (Note/Protocol): Unknown data]
                [Unknown data]
                [Severity level: Note]
                [Group: Protocol]
        CRC: 0x185c3f
            [Expert Info (Warning/Checksum): Incorrect CRC]
    

    Now I can continue to experiment myself =D

    Thank you very much. Especially for your patience. Now come my obligations. I can transfer by PayPal or WesternUnion. For this I need your contact details. Either here in the forum or email me at: info-at-32mb.de

Children
Related