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

Timer and Multirole for PCA20006

Hello, I have implemented the code below for my project based on switching central and peripheral role in S130. The code works fine on the Devkit PCA10028 but on porting it to PCA20006 I noticed some bugs in the final steps.

  • Without line 195 and 271 to 310 everything seems to work well on the Beacon, the LED is toggling in the right frequency. However after some time the frequency seems to roughly double. I cannot solidly quantify this observation.
  • Adding the above lines, the beacon does not switch on any LED at all. Only in debug mode the LEDs are switched on and the timer handler is entered. It seems there is a problem with my timer interrupt handling, but I dont know what.
  • I Am unsure if this code will be capable of handling 120 interacting nodes (well, mostly only up to 20 should be in close proximity)

Does anybody have an idea what could be my problem when porting to PCA20006? I am also grateful for any ideas to improve the code.

edit1: attached file instead of code: Corrected line numbers to reflect recent changes, as I corrected functionality. edit2: For completness I attached to whole (ecplise) project folder. Putting it into /central_and_peripheral/experimental/ should work. The makefile is currently set for PCA20006.

edit2: attached updated code

edit3: final code

  • Thank you for testing the code. The red LED/LED3 (indicating the status) should be on 1 sec, off 1 sec, etc. The DK works well for me, but the Beacon seemed to blink faster after some time. The blue LED/LED2 should signal any incoming ad from a tag with status I. The counter should show the seconds since power up (actually the number of times my main loop was called.) I planned to increase the adv_interval to 1000ms, the scan window to 100ms and the scan interval to 200ms to lower the collision rate. In connected mode, only 8 partners would work? But I did not plan to use that anyway. (Maybe in an upgrade to record the network, but then only one connection to a central)

  • There is no point in changing the scan parameters, as passive scanning is pure RX (and as such can be done by an infinite number of devices simultaneously). Reducing the scan time would only decrease the chances of catching advertising packets (although it would of course save battery on the scanning device to scan half as much.)

    The current s130 can only have one link as peripheral, but you can have multiple links as central. This has to do with timing constraints; the central decides connection parameters so you can schedule multiple connections in central role, but the peripheral has to accept whatever schedule the central provides meaning multiple connections in peripheral role would be a scheduling nightmare with a lot of scheduling collisions.

  • One last comment before the weekend: You are not checking that infect_source[sender_id >> 3] on line 195 is within the bounds of the infect_source array. Any chance the sender_id is 120 or higher (or read from the wrong position)? Although you specify IDs to be in the range 0-119 it would still be wise to do a check before writing the value, as that would let you know an error there right away instead of getting mysterious behaviour.

  • Hello Terje. You are right, I still have a lot of safeguards to implement. I implemented a couple over the weekend and fixed some minor bugs in the functionality (updated atteachment). Now on the DK the code is behaving exactly as it should.

    On the beacon however something is wrong. I oberserve the following:

    • If I do not call scan_start() everything seems to work alright. The advertisment is correct and updates to show the right time counter for a long time. No LEDs are blinking (as intended).

    • If I switch on scanning by calling scan_start I oberserve different behaviour. If I do a cold start, i.e. the beacon was without power for several minutes (~30), at the start everything looks fine, i.e. same behaviour as before. After some time (varying, observed up to 350 s) the LEDs flash and the counter is reset. The counter increases again and is reset at shorter and shorter intervals.

    • Each time with a flash of the LEDs.I could verify that this LED flashing is in fact the LED initialization I do in main. So it seems, that with scanning the beacon reboots at irregular intervals.
    • If I manually reset it from this state the reset frequency initially seems to correlate with the scanning interval (checked by increasing it). However later on the frequency increases s.t. it is practically always flashing.

    Do you know what could be the reason for this? The only thing I found is that I am using Beacon rev. 1.2. with S130 which apparently was a problem one year ago. It would be great if we could solve this strange bug by the end of the week, as that is my deadline for ordering the hardware for the summer school. Thanks in advance Tobias

Related