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

nRF Beacon with Scanning Feature

Hi,

I have a couple of nRF Beacons and want to change the program so that it scans for iBeacon packets before starting to advertise.

The flashed program is just advertising and I think uses S110 soft device. Correct me if I'm wrong:

  • For adding the scan feature I have to program S130, and I expect that the same program (advertising) should work without any change, but it will just give me the feature of scanning too.

  • I need a simple example for "scanning". I think the "Sniffer" program does that on the nRF DKs but that one is in HEX only.

  • I found this topics: devzone.nordicsemi.com/.../

I think I should be able to use the scanning features from that program, but as the program was with S130 0.9.0-1 and PCA10001, would it cause a problem? I'm still a beginner about nRF MCU registers and board specific pins, but I think one of the tutorials was saying that you can change the target board in Keil and the required header files will be added, so that the program should run on a different board (here PCA20006).

Thanks, FA main_woPointer.c main_wPointer.c

Parents
  • Hi Petter,

    Thanks for the sample program. As I wanted to keep the advertising part of the Beacon program for nRF Beacon kit (PCA20006) I decided to keep all parts of that program and add the additional required lines (in the attached PDF, Yellow highlights are the codes that I added based on your program, and pink highlights are changes that I made to get rid of errors). Here is what happened:

    1- Beacon program was in SDK 7 and S110. So, I changed the include paths to S130 headers in SDK 9, and also removed "ble_dfu.h" and added the new one from SDK 9.

    2- By doing this I got few errors in some function calls (pink highlights), such as

    • no member named "timeout" in"ble_gap_sec_params_t"
    • one argument missing for "sd_ble_gap_sec_params_reply" and "sd_ble_gatts_sys_attr_set"
    • no member named "priph.keys" and "div" in CASE BLE_GAP_EVT_SEC_INFO_REQUEST (which I omitted completely from the cases!)

    3- I had to change LED1 to LED_RGB_BLUE which is the pin number for PCA20006 LED.

    The programs was built without error, but after programming S130 from SDK 9, I was getting error for programming the actual program. It was saying that the program has data in the Soft_Device part. I noticed that with S110, soft device was after x16000 in memory, while with S130 it was after x1C000. So, in the Target Options in Keil I changed the IROM start to x1C000.

    With these changes I could program the board. But! it seems the program in not actually running or there is an error inside.

    In the MAIN, the only change made is that, the program starts scanning and after the addresses are mateched, START=TRUE and it will exit a WHILE LOOP and should start Advertising like the normal beacon:

    scan_init(); scan_start(); led_softblink_start(LED_R_MSK); while (!start) { }

    As you can see even if it waits in the while loop, I think LED_SOFTBLINK_START should make the RED led blink, but nothing happens.

    So, I don't know if I had to update some more files to make it work (although Keil doesn't give any errors) or something else is going wrong.

    Attached are the main.c and the hex file.

    main.pdf main.c nrf51822_beacon_app.hex

Reply
  • Hi Petter,

    Thanks for the sample program. As I wanted to keep the advertising part of the Beacon program for nRF Beacon kit (PCA20006) I decided to keep all parts of that program and add the additional required lines (in the attached PDF, Yellow highlights are the codes that I added based on your program, and pink highlights are changes that I made to get rid of errors). Here is what happened:

    1- Beacon program was in SDK 7 and S110. So, I changed the include paths to S130 headers in SDK 9, and also removed "ble_dfu.h" and added the new one from SDK 9.

    2- By doing this I got few errors in some function calls (pink highlights), such as

    • no member named "timeout" in"ble_gap_sec_params_t"
    • one argument missing for "sd_ble_gap_sec_params_reply" and "sd_ble_gatts_sys_attr_set"
    • no member named "priph.keys" and "div" in CASE BLE_GAP_EVT_SEC_INFO_REQUEST (which I omitted completely from the cases!)

    3- I had to change LED1 to LED_RGB_BLUE which is the pin number for PCA20006 LED.

    The programs was built without error, but after programming S130 from SDK 9, I was getting error for programming the actual program. It was saying that the program has data in the Soft_Device part. I noticed that with S110, soft device was after x16000 in memory, while with S130 it was after x1C000. So, in the Target Options in Keil I changed the IROM start to x1C000.

    With these changes I could program the board. But! it seems the program in not actually running or there is an error inside.

    In the MAIN, the only change made is that, the program starts scanning and after the addresses are mateched, START=TRUE and it will exit a WHILE LOOP and should start Advertising like the normal beacon:

    scan_init(); scan_start(); led_softblink_start(LED_R_MSK); while (!start) { }

    As you can see even if it waits in the while loop, I think LED_SOFTBLINK_START should make the RED led blink, but nothing happens.

    So, I don't know if I had to update some more files to make it work (although Keil doesn't give any errors) or something else is going wrong.

    Attached are the main.c and the hex file.

    main.pdf main.c nrf51822_beacon_app.hex

Children
  • Hi FA,

    Next time please reply to a answer by using comment, not to create another answer. If you have trouble with the length limit, pleas split the comment into several comment. You can attach files by editing your question.

    We are on limited staff right now due to the summer period so I afraid we don't have enough resource to look into the code and fix the errors for you.

    My suggestion for you is:

    • Study the example for S130 in the nRF51 SDK where we do scanning. Such as the ble_app_hrs_c example. In that example we do both, scanning and advertising.

    • Try to add the code to advertise as a beacon into the S130 example instead of porting the code for S130 into the beacon example since the API changed.

    • If you want to have the extra feature such as configuration mode and bootloader mode, you would need to invest some more time on porting the code to the new SDK.

    • Try to get hold of a nRF51 DK or a board that has nRF51 revision 3 on board. The reason is that S130 is not officially support revision 2 chip and not tested with revision 2 chip. It's the same chip on the PCA20006 and the PCA10001.

  • Hi, Due to the application that I'm looking at, I have to use PCA20006. If you are saying that it can not go into scan mode because of chip revision, then that means I have to design a new hardware with a newer chip to test my program, which I'm trying to avoid at least for the initial tests. The program I posted will be built without any error, but the problem is that it seems after programmed it will never actually run on the board. So, maybe S130 on the board is an issue. I'll try to see if S130 examples will run on the board or not. But can you confirm that about changing the IROM start address I did the right changes and that's normal when programming different SDs?

  • @FA: For testing purpose, it should be ok to test S130 on chip revision 2. It's just not production tested on chip revision 2.

    You should try S130 example on your chip. Testing if it can scan for the beacon around. You can print out the log on UART.

    You will need to modify the IROM1 start address, same with IRAM1 and the sizes. Please follow what we have in the SDK example. Make sure you use latest SDK version.

    After you have it works with scanning, you can add the beacon advertising part.

  • I posted my latest results as a comment on the first answer by Petter. Please take a look at that. About the problem I having in that post (not coming out of the WHILE loop), do you think if the devie receives very fast packets (100msec interval) from the address is searching for it might just keep going to the BLE_EVT function and not continue the main program? I'm gonna test that by increasing the interval. Also, if I want to STOP scanning, what function should I call? Similar to STRT just with STOP at the end and any specific passing parameter?

  • @FA: How did you verify that address is matched but "start" was not changed ? It just doesn't make sense. Your approach should work.

    You can try to use UART log, or you can add a break point when the address is matched and then step through to see if the "start" changed or not. Note that when you stop for a break point the softdevice won't be able to continue but the application still can.

    The example I wanted you to test was the one from the SDK. But you can also try with the example from Petter. Try to not changing anything, make sure it works first, try to printout on UART some data about the advertising packet you receive.

    The scanner stop only when you call sd_ble_gap_connect() or when you call sd_ble_gap_scan_stop(), have a look at ble_gap.h for the list.

Related