Bluetooth

For Bluetooth communication, Nordic SDK is used (nRF5_SDK_17.0.0_9d13099. ble_app_uart example found in SDK is used as template for this project. Wanted functionality is used by modifying code. in following defines, Device name have been changed.

#define APP_BLE_CONN_CFG_TAG            1                                           /**< A tag identifying the SoftDevice BLE configuration. */

#define DEVICE_NAME                     "Nordic_malzca_UART"                               /**< Name of device. Will be included in the advertising data. */
#define NUS_SERVICE_UUID_TYPE           BLE_UUID_TYPE_VENDOR_BEGIN                  /**< UUID type for the Nordic UART Service (vendor specific). */

#define APP_BLE_OBSERVER_PRIO           3                                           /**< Application's BLE observer priority. You shouldn't need to modify this value. */

#define APP_ADV_INTERVAL                64                                          /**< The advertising interval (in units of 0.625 ms. This value corresponds to 40 ms). */

#define APP_ADV_DURATION                18000                                       /**< The advertising duration (180 seconds) in units of 10 milliseconds. */

#define MIN_CONN_INTERVAL               MSEC_TO_UNITS(20, UNIT_1_25_MS)             /**< Minimum acceptable connection interval (20 ms), Connection interval uses 1.25 ms units. */
#define MAX_CONN_INTERVAL               MSEC_TO_UNITS(75, UNIT_1_25_MS)             /**< Maximum acceptable connection interval (75 ms), Connection interval uses 1.25 ms units. */
#define SLAVE_LATENCY                   0                                           /**< Slave latency. */
#define CONN_SUP_TIMEOUT                MSEC_TO_UNITS(4000, UNIT_10_MS)             /**< Connection supervisory timeout (4 seconds), Supervision Timeout uses 10 ms units. */
#define FIRST_CONN_PARAMS_UPDATE_DELAY  APP_TIMER_TICKS(5000)                       /**< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds). */
#define NEXT_CONN_PARAMS_UPDATE_DELAY   APP_TIMER_TICKS(30000)                      /**< Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). */
#define MAX_CONN_PARAMS_UPDATE_COUNT    3                                           /**< Number of attempts before giving up the connection parameter negotiation. */

#define DEAD_BEEF                       0xDEADBEEF                                  /**< Value used as error code on stack dump, can be used to identify stack location on stack unwind. */

#define UART_TX_BUF_SIZE                256                                         /**< UART TX buffer size. */
#define UART_RX_BUF_SIZE                256                                         /**< UART RX buffer size. */

Following code is used to receive data from Nordic android application and modifying PWM based on received data.

/**@brief Function for handling the data from the Nordic UART Service.
 *
 * @details This function will process the data received from the Nordic UART BLE Service and send
 *          it to the UART module.
 *
 * @param[in] p_evt       Nordic UART Service event.
 */
/**@snippet [Handling the data received over BLE] */
static void nus_data_handler(ble_nus_evt_t * p_evt)
{

        if (p_evt->type == BLE_NUS_EVT_RX_DATA)
        {
                uint32_t err_code;

                if(p_evt->params.rx_data.length==4){
                  rx_size=p_evt->params.rx_data.length;
                  bufferiino[0]=p_evt->params.rx_data.p_data[0];
                  bufferiino[1]=p_evt->params.rx_data.p_data[1];
                  bufferiino[2]=p_evt->params.rx_data.p_data[2];
                  bufferiino[3]=p_evt->params.rx_data.p_data[3];
                  if(bufferiino[0]=='c'){
                        if(bufferiino[1]=='1'){
                                unsigned char tmp_buf[2];
                                tmp_buf[0]= bufferiino[2];
                                tmp_buf[1]= bufferiino[3];

                                PWM0_1[0]=100-atoi(tmp_buf);
                                NRF_PWM0->TASKS_SEQSTART[0]=1;
                                lcdbuf[4]=tmp_buf[0];
                                lcdbuf[5]=tmp_buf[1];
                                lcdkirj();

                        }

                        else if(bufferiino[1]=='2'){
                                unsigned char tmp_buf[2];
                                tmp_buf[0]= bufferiino[2];
                                tmp_buf[1]= bufferiino[3];

                                PWM0_1[1]=100-atoi(tmp_buf);
                                NRF_PWM0->TASKS_SEQSTART[0]=1;
                                lcdbuf[12]=tmp_buf[0];
                                lcdbuf[13]=tmp_buf[1];
                                lcdkirj();

                        }

                        else if(bufferiino[1]=='3'){
                                unsigned char tmp_buf[2];
                                tmp_buf[0]= bufferiino[2];
                                tmp_buf[1]= bufferiino[3];

                                PWM2_3[0]=100-atoi(tmp_buf);
                                NRF_PWM1->TASKS_SEQSTART[0]=1;
                                lcdbuf[20]=tmp_buf[0];
                                lcdbuf[21]=tmp_buf[1];
                                lcdkirj();

                        }

                        else if(bufferiino[1]=='4'){
                                unsigned char tmp_buf[2];
                                tmp_buf[0]= bufferiino[2];
                                tmp_buf[1]= bufferiino[3];

                                PWM2_3[1]=100-atoi(tmp_buf);
                                NRF_PWM1->TASKS_SEQSTART[0]=1;
                                lcdbuf[28]=tmp_buf[0];
                                lcdbuf[29]=tmp_buf[1];
                                lcdkirj();

                        }


                  }



                }
        }

}