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

How to Change Channel Map for exchanging DaTa ?

Hi , I want to set the channels used for exchanging DATA (after connection) when peripheral and master are connected. i searched and i find that it's like this :

//Set data channel to be used
                ble_opt_t new_opt_config;
		memset(&new_opt_config, 0, sizeof(new_opt_config));
		new_opt_config.gap_opt.ch_map.ch_map[0] = 0xFF;
		new_opt_config.gap_opt.ch_map.ch_map[1] = 0x0F;
		new_opt_config.gap_opt.ch_map.ch_map[2] = 0x00;
		new_opt_config.gap_opt.ch_map.ch_map[3] = 0x00;
		new_opt_config.gap_opt.ch_map.ch_map[4] = 0x00;
		error=sd_ble_opt_set(BLE_GAP_OPT_CH_MAP, &new_opt_config) ;

but when i put sd_ble_opt_get() (after some seconds after the connection, so i give the device the time to move to the new configuration) to read the channel map working i get the default one : FF FF FF 1F :/

My Questions :

  1. channel map is uint8_t ch_map[5]; that means 40 bits =number of channels including the ones of ADV. how can i choose to change one of the 37 channels of data , and not the 3 for ADV ?
  2. Should i use sd_ble_opt_set at the master side or peripheral side? because what i did is use it at peripheral side.
Parents
    1. The advertisement channels are outside of this scope. To decide which channels to advertise on, there's a bitfield in ble_gap_adv_params_t called ble_gap_adv_ch_mask_t. Setting one of the members to 1 will turn off that specific channel. The ch_map[5] is only 37 bits, as mentioned in the comment in the API documentation.

    It's only the master that can set the channel map, so setting the option on a peripheral will not have any immediate effect. It will only affect future central links, which is why it is allowed to do to begin with.

    So to change the mask, you have to initiate this from the central side.

  • Look at it as a bitfield, and you can represent the array like a binary number: 0b0001111111111111111111111111111111111111. The last bit (LSB) represent channel 0, and is 1 if you want to use it. The second to last bit is channel 1 etc. The three most significant bits are ignored, because these represent non-data channels. The API is only defined like this because it was easier than splitting it up into multiple fields.

Reply
  • Look at it as a bitfield, and you can represent the array like a binary number: 0b0001111111111111111111111111111111111111. The last bit (LSB) represent channel 0, and is 1 if you want to use it. The second to last bit is channel 1 etc. The three most significant bits are ignored, because these represent non-data channels. The API is only defined like this because it was easier than splitting it up into multiple fields.

Children
No Data
Related