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

How can an ANT slave re-connect to a different master?

I have based my app on the ant_io_demo example and I have one master and one slave communicating successfully.

In my application I can have several masters from time time time, each using a different device number. I find that when one master switches off and another switches on, the slave cannot see the new master. I can detect the loss of communications with the first master, but I have been unable to re-establish a connection with the new master. Attempts at calling ant_channel_init(), sd_ant_channel_open() etc gives fatal errors.

How do I reset my slave to a position where it is able to re-establish communications with a second master? Remember, I have used the ant_io_demo example code and am looking for a solution close to that.

As a supplementary question, how can a slave exchange messages with multiple masters?

Parents
  • Hi,

    What happens typically when a master is turned OFF is that the slave will experience some events in the following order:

    Several EVENT_RX_FAIL : A receive channel missed a message which it was expecting. This happens when a slave is tracking a master and is expecting a message at the set message rate.

    EVENT_RX_FAIL_GO_TO_SEARCH : The channel has dropped to search mode after missing too many messages. It will try to reconnect to the previous connected master.

    EVENT_CHANNEL_CLOSED : The channel has been successfully closed.

    Also see:
    https://www.thisisant.com/resources/an11-ant-channel-search-and-background-scanning-channel/

    So I suspect in this case is that if you don't wait for the channel closed then you may experience issues. After channel is closed, then you should be able to update channel ID to wildcards before opening channel again.

    It's also possible to close the channel by the close channel api, however I do believe you need to wait for the channel closed event before you do anything more with the channel (such as reconfigure and open again).

    Best regards,
    Kenneth

  • Hmmm. When I power off my master I get many EVENT_RX_FAIL events, then EVENT_RX_FAIL_GO_TO_SEARCH after 2s. I then see EVENT_RX_SEARCH_TIMEOUT and EVENT_CHANNEL_CLOSED after 30s, but only after I comment out this line (present in the ant_io_demo example):

    search_config.low_priority_timeout = ANT_LOW_PRIORITY_TIMEOUT_DISABLE

    After the EVENT_RX_FAIL_GO_TO_SEARCH event my slave does see the first master if I power it back on, but does not see a second master.

    I placed an sd_ant_channel_close() call in the EVENT_RX_FAIL_GO_TO_SEARCH event handler and immediately get a EVENT_CHANNEL_CLOSED event. In the EVENT_CHANNEL_CLOSED event handler I add an ant_search_init(), but it will not detect any master. If I add ant_search_init() then sd_ant_channel_open() it will detect my first master but not the second. If I try the full ant_io_rx_setup() sequence (from the ant_io_demo example) of ant_channel_init(), search_init(), sd_ant_channel_open() it crashes. So far the only way can communicate with a second master is to reset the nRF52 slave.

    Can I ask for specific instructions for establishing communications with a second master? Perhaps a variation of the ant_io_demo example with two masters?

  • Acutetech said:
    After the EVENT_RX_FAIL_GO_TO_SEARCH event my slave does see the first master if I power it back on, but does not see a second master.

    Likely due to my initial reply:

    "EVENT_RX_FAIL_GO_TO_SEARCH : The channel has dropped to search mode after missing too many messages. It will try to reconnect to the previous connected master." 

    Acutetech said:
    I placed an sd_ant_channel_close() call in the EVENT_RX_FAIL_GO_TO_SEARCH event handler and immediately get a EVENT_CHANNEL_CLOSED event. In the EVENT_CHANNEL_CLOSED event handler I add an ant_search_init(), but it will not detect any master.

    Did you follow my suggestion in initial reply:

    "After channel is closed, then you should be able to update channel ID to wildcards before opening channel again."

    So call sd_ant_channel_id_set(make sure .device_number=0) and then call sd_ant_channel_open(). 

    Acutetech said:
    If I try the full ant_io_rx_setup() sequence (from the ant_io_demo example) of ant_channel_init(), search_init(), sd_ant_channel_open() it crashes.

    You should look into what "crashes" means, if you are working on Debug (not Release) in SES, then typically the code should go to app_error_fault_handler() where you can find the file name, line number, and error code that caused the crash. I suspect the problem may be that you have not unassigned channel (see sd_ant_channel_unassign()) after channel is closed, this is required if you want to do a complete re-init of the channel.

  • Thanks. I will try your ideas as soon as I can. This is my first ANT project, and I picked one of Nordic's ANT demos that seemed similar to what I needed to do. That demo does not use many of the calls you mention, so of course these have not made their way into my own code...

    I guess the trouble with the demos is that they can be overly simplistic and fail when you try to push them a bit. Perhaps there is room for Nordic to create tutorials that provide background and guidance that are not found in either the example apps, nor the API specifications. I find myself often finding answers to my questions in these forums, where I join other newbies encountering the same problems as me.

  • Hi,

    I can understand.

    If you are interested in ANT, you should check out www.thisisant.com in general, and the ANT message protocol and usage document in specific:
    https://www.thisisant.com/resources/ant-message-protocol-and-usage/

    In specific chapter 5 and 6 is something you should check out.

    Best regards,
    Kenneth

Reply Children
No Data
Related