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 Reply Children
  • Why don't you tell me how it works without SDK's? =)

    I will transfer 200 € to anyone for a working and understandable example of controlling the radio by register. Or for the correction of my code so that it works. So that the radio sends receivable adv_ind packet.

  • See BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 6, Part B 

    Chapter 3.1.1 CRC generation: 
    "...For all other Advertising Physical Channel PDUs, the shift register shall be preset with 0x555555."


    Chapter 3.2: DATA WHITENING:
    "Before whitening or dewhitening, the shift register is initialized with a sequence that is derived from the physical channel index in which the packet is transmitted in the following manner:

    • Position 0 is set to one.
    • Positions 1 to 6 are set to the channel index of the channel used when transmitting or receiving, from the most significant bit in position 1 to the least significant bit in position 6.

    For example, if the channel index = 23 (0x17), the positions would be set as follows:
    Position 0 = 1
    Position 1 = 0
    Position 2 = 1
    Position 3 = 0
    Position 4 = 1
    Position 5 = 1
    Position 6 = 1"

  • Thanks for the suggestion. According to nRF52832 documentation PDF at 23.14.26 for register 0x40001554:

    Data whitening initial value: Bit 6 is hard-wired to '1', writing '0' to it has no effect, and it will always be read back and used by the device as '1'. Bit 0 corresponds to Position 6 of the LSFR, Bit 1 to Position 5, etc.

    So it is enough to write here only the channel index. Which I have also done. But this does not bring me to the result that I can receive anything.

    CRC is already initialized with 0x555555. CRCPOLY I have initialized with 0x65B (there I do not know yet whether it is correct).

    Thus, I tried the suggested. Problem is not solved yet. I still need help. And the money is still waiting for its recipient, which helps me decisively here. Suggestions and recommendations are also welcome

  • What does BT core spec say on the matter of the CRC polynomial?

  • 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?

Related