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

i want ble sorce

hi i'm use nrf52dk 

and segger embedded studio

also i'm mcu beginner 

The value was obtained using a magnetic sensor.

now i want using the ble 

Now we want to send the value to bluetooth using ble.

but example src is hard..

i don understand..

so..

Could you tell me the source from which to interpret the sample source or send the sensor value using ble?

thankyou

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>

#include "nrf.h"
#include "nrf_drv_timer.h"
#include "bsp.h"
#include "app_error.h"
#include "app_uart.h"

#include "nrf_drv_timer.h"
#include "nrf_gpio.h"
#include "nrf_gpiote.h"
#include "nrf_delay.h"

#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"

#define FREQ_MEASURE_PIN 11

static void timer_init() {
  NRF_TIMER1->TASKS_STOP = 1; 
  NRF_TIMER1->MODE = TIMER_MODE_MODE_Timer;
  NRF_TIMER1->PRESCALER = 8; // Fhck / 2^8
  NRF_TIMER1->CC[0] = 62500; // 62500 - 1s

  NRF_TIMER1->BITMODE = (TIMER_BITMODE_BITMODE_16Bit << TIMER_BITMODE_BITMODE_Pos);

  NRF_TIMER1->TASKS_CLEAR = 1;
  NRF_TIMER1->INTENSET = (TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos);

  NRF_TIMER1->EVENTS_COMPARE[0] = 0;
}

static void counter_init() {
  NRF_TIMER2->TASKS_STOP = 1;
  NRF_TIMER2->MODE = TIMER_MODE_MODE_Counter;
  NRF_TIMER2->BITMODE = (TIMER_BITMODE_BITMODE_24Bit << TIMER_BITMODE_BITMODE_Pos);
  NRF_TIMER2->TASKS_CLEAR = 1;
  NRF_TIMER2->EVENTS_COMPARE[0] = 0;
}

static void gpiote_init(uint32_t pin)
{
	NRF_GPIOTE->CONFIG[0] 	
        = 	0x01 << 0; 								// MODE: Event
	NRF_GPIOTE->CONFIG[0] 	|= 	pin << 8;								// Pin number
	NRF_GPIOTE->CONFIG[0] 	|= 	NRF_GPIOTE_POLARITY_LOTOHI	<< 16;		// Event rising edge 	
}

static void ppi_timer_stop_counter_init() {
  NRF_PPI->CHEN |= 1 << 0;
  *(&(NRF_PPI->CH0_EEP)) = (uint32_t)&NRF_TIMER1->EVENTS_COMPARE[0];
  *(&(NRF_PPI->CH0_TEP)) = (uint32_t)&NRF_TIMER2->TASKS_STOP;
  NRF_PPI->CHENSET |= 1 << 0;
}

static void ppi_gpiote_counter_init() {
  NRF_PPI->CHEN |= 1 << 1;
  *(&(NRF_PPI->CH1_EEP)) = (uint32_t)&NRF_GPIOTE->EVENTS_IN[0];
  *(&(NRF_PPI->CH1_TEP)) = (uint32_t)&NRF_TIMER2->TASKS_COUNT;
  NRF_PPI->CHENSET |= 1 << 1;
}

int main(void)
{
    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();

  

    NVIC_EnableIRQ(TIMER1_IRQn);
    NVIC_SetPriority(TIMER1_IRQn, APP_IRQ_PRIORITY_LOW);	
    nrf_gpio_cfg_input(FREQ_MEASURE_PIN, NRF_GPIO_PIN_NOPULL);

    counter_init();
    timer_init();
    gpiote_init(FREQ_MEASURE_PIN);
    ppi_gpiote_counter_init();
    ppi_timer_stop_counter_init();

    while(true){
    
    NRF_TIMER1->TASKS_START = 1;
    NRF_TIMER2->TASKS_START = 1;
	
    nrf_delay_ms(1000);
    NRF_LOG_FLUSH();
  }
}

void TIMER1_IRQHandler(void) 
{
	if (NRF_TIMER1->EVENTS_COMPARE[0] != 0)
	{
		NRF_TIMER1->EVENTS_COMPARE[0] = 0;
		NRF_TIMER2->TASKS_CAPTURE[0] = 1;
			             
		NRF_LOG_INFO("cc: %dHz", NRF_TIMER2->CC[0]);

      	
		NRF_TIMER1->TASKS_CLEAR = 1;
		NRF_TIMER2->TASKS_CLEAR = 1;	
						
		NRF_TIMER2->TASKS_START = 1;			
    }
}

Related