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

Problem When I Adding C File in Main.c

I created c file which name of Tus_Tarama.c

#include <stdbool.h>
#include <stdint.h>
#include "boards.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "nrf.h"
#include "nrf_drv_gpiote.h"
#include "app_error.h"
#include "nrf_drv_timer.h"
#include "app_timer.h"
#include "app_button.h"
#include "nrf_drv_ppi.h"

#define PIN_IN     BSP_BUTTON_3
#define PIN_IN_1   BSP_BUTTON_2
#define PIN_OUT    BSP_LED_3
#define PIN_OUT_1  BSP_LED_2
#define PIN_OUT_2  BSP_LED_1
#define PIN_OUT_3  BSP_LED_0
int a, b, c ,d;
signed int sayac;
uint8_t sifre[] ="abcd"; 
unsigned char Tus_Registeri = 0;
//void Tarama_Basla(void)
//{
//  nrf_gpio_cfg_output(PIN_OUT);
//  nrf_gpio_cfg_input(PIN_IN, NRF_GPIO_PIN_PULLUP);
//  for(;;)
//    {
//      if(nrf_gpio_pin_read(PIN_IN))
//        nrf_gpio_pin_clear(PIN_OUT);
//      else
//        nrf_gpio_pin_set(PIN_OUT);
//    }
//}
/////*******************************************************************************************//////

void bunu_yap(void)
{
  nrf_gpio_pin_clear(PIN_OUT);
  nrf_gpio_pin_set(PIN_OUT_1);
  nrf_gpio_pin_set(PIN_OUT_2);
  nrf_gpio_pin_set(PIN_OUT_3);
}

void sunu_yap(void)
{
  nrf_gpio_pin_clear(PIN_OUT_1);
  nrf_gpio_pin_set(PIN_OUT);
  nrf_gpio_pin_set(PIN_OUT_2);
  nrf_gpio_pin_set(PIN_OUT_3);
}

void onu_yap(void)
{
  nrf_gpio_pin_clear(PIN_OUT_2);
  nrf_gpio_pin_set(PIN_OUT_1);
  nrf_gpio_pin_set(PIN_OUT);
  nrf_gpio_pin_set(PIN_OUT_3);
}

void onu_da_yap(void)
{
  nrf_gpio_pin_set(PIN_OUT_1);
  nrf_gpio_pin_set(PIN_OUT);
  nrf_gpio_pin_set(PIN_OUT_2);
  nrf_gpio_pin_clear(PIN_OUT_3);
}
void kontrol(void)
{
  while(sifre)
    {
      nrf_gpio_pin_clear(PIN_OUT_2);
      nrf_delay_ms(1000);
      nrf_gpio_pin_set(PIN_OUT_2);
      nrf_delay_ms(1000);
      nrf_gpio_pin_clear(PIN_OUT_1);
      nrf_delay_ms(1000);
      nrf_gpio_pin_set(PIN_OUT_1);
    }
}
void button_event_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action){
    if(action == NRF_GPIOTE_POLARITY_TOGGLE  && pin == PIN_IN){
        nrf_gpio_pin_toggle(PIN_OUT);
    }
}
void button_event_handler2(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action){
    if(action == NRF_GPIOTE_POLARITY_TOGGLE  && pin == PIN_IN_1){
       sayac++;
       if(sayac == 2)
        {
          bunu_yap();
          a = 1;
        }
        else if(sayac == 4)
        {
         sunu_yap();
         b = 2;
        }
        else if(sayac == 6)
        {
         onu_yap();
         c = 3;
        }
        else if(sayac == 8)
        {
          onu_da_yap();
          d = 4;
          kontrol();
          sayac = 0;
        }
    }
}
void Tarama_Basla(void)
{
    nrf_gpio_cfg_output(PIN_OUT);
    nrf_gpio_pin_set(PIN_OUT);
    nrf_gpio_cfg_output(PIN_OUT_1);
    nrf_gpio_pin_set(PIN_OUT_1);
    //Initialize GPIOTE driver
    nrf_drv_gpiote_init();
    
    //Configure button with pullup and event on both high and low transition
    nrf_drv_gpiote_in_config_t config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);
    config.pull = NRF_GPIO_PIN_PULLUP;
    nrf_drv_gpiote_in_init(PIN_IN, &config, button_event_handler); //Assign button config to a GPIOTE channel
    nrf_drv_gpiote_in_init(PIN_IN_1, &config, button_event_handler2);                                                           //and assigning the interrupt handler
    nrf_drv_gpiote_in_event_enable(PIN_IN, true);                  //Enable event and interrupt
    nrf_drv_gpiote_in_event_enable(PIN_IN_1, true);
    for(;;) __WFE(); //CPU sleep while waiting for event

}

and main.c

int main(void)
{
    // Initialize.
    leds_init();
    timers_init();
    log_init();
    Tarama_Basla();
    buttons_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();
    sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE);
    sd_ble_gap_tx_power_set(0);
    // Start execution.
    NRF_LOG_INFO("Blinky example started.");
    advertising_start();
    Tarama_Basla();                         // This is the problem!1!
    // Enter main loop.
    for (;;)
    {
        if (NRF_LOG_PROCESS() == false)
        {
            power_manage();
        }
    }
}

When i adding Tus_Tarama file advertising is stop! Why am i customize blinky example!

Related