Microprocessor/STM32 nRF51422-QFAB(GPIO/ADC)
  • 728x90
    ๋ฐ˜์‘ํ˜•

     

     

    nRF51422-QFAB (GPIO/ADC)


     

     

    ๋ชฉ์ฐจ

       

       

      Specification

       

       

      NORDIC nRF51422 Link : https://www.nordicsemi.com/eng/Products/ANT/nRF51422

       

      nRF51422 - Nordic Semiconductor

      nRF51422 - Bluetooth Low Energy, ANT and 2.4 GHz SoC

      www.nordicsemi.com

       

      ๐Ÿ“Œ NORDIC ์—์„œ ๋งŒ๋“  Cortex-M0 ๊ธฐ๋ฐ˜์˜ Bluetooth 4.0 Single Mode ๋ฐ ANT+ ๋ฅผ ๋™์‹œ์— ์ ์šฉํ•  ์ˆ˜ ์žˆ๋Š” Chip์œผ๋กœ ์‚ฌ์–‘์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

       

      • Single Chip, highly flexible, 2.4GHz multi-protocol device
      • 32-bit ARM Cortex M0 CPU core
      • 128/256KB flash 16KB RAM
      • Supports ANT and Bluetooth low energy protocol stacks
      • Thread-safe and run-time protected
      • 3 data rates (2Mbs/1Mbs/250kBs)
      • +4dBm to -20dBm output power
      • PPI system for maximum power-efficient applications and code simplification
      • Flexible power managem ent feaures
      • Configurable I/O mapping for analog and digital I/O

       

      ๐Ÿ“Œ Bluetooth 4.0 ๋ฐ ANT+ Stack ์œผ๋กœ๋Š” NORDIC์—์„œ ์ œ๊ณตํ•˜๋Š” S210 (ANT+ Only)/S310 (Bluetooth 4.0 / ANT+)์„ ์‚ฌ์šฉํ•œ๋‹ค.

       

       

      GPIO (General Purpose I/O)

      ๐Ÿ“Œ Pin P0.08, P0.09๋ฅผ ์ด์šฉํ•˜์—ฌ GPIO๋ฅผ ํ™œ์„ฑํ™” ํ•˜๊ณ , LED๋ฅผ ON์‹œ์ผœ๋ณด์ž.

       

      • Toolchain ์€ Keil v5๋ฅผ ์‚ฌ์šฉํ•˜์˜€๊ณ , ๋ฒ„์ „์€ MDK-Lite Version: 5.18 ์ด๋‹ค.
      • SDK๋Š” nRF5 SDK 12.2.0๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜์˜€๋‹ค.

       

      SDK Download Url : https://www.nordicsemi.com/eng/nordic/Products/nRF51822/nRF5-SDK-v12-zip/54280

       

      Pin P0.08, P0.09๋Š” ์•„๋ž˜์˜ ๊ทธ๋ฆผ์—์„œ ์œ„์น˜๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.
       

       

      SDK์— ์ œ๊ณต๋˜๋Š” examples ์˜ experimental_ble_app_blinky๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ Source๋ฅผ ๋ถ„์„ํ•˜์˜€๋‹ค.

      main()ํ•จ์ˆ˜์—์„œ ํ˜ธ์ถœ๋˜๋Š” leds_init()ํ•จ์ˆ˜ ๋‚ด๋ถ€์—๋Š” bsp์—์„œ ์ œ๊ณตํ•˜๋Š” bsp_board_leds_init()ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค.

       
      Boards.c
      #if LEDS_NUMBER > 0
      static const uint8_t m_board_led_list[LEDS_NUMBER] = LEDS_LIST;
      #endif
      
      void bsp_board_leds_init(void)
      {
          uint32_t i;
          for (i = 0; i < LEDS_NUMBER; ++i) {
              nrf_gpio_cfg_output(m_board_led_list[i]);
          }
          bsp_board_leds_off();
      }

       

      LEDS_NUMBER ๋ณ€์ˆ˜๋Š” Pca10028.h ํŒŒ์ผ์— ์„ ์–ธ๋˜์–ด ์žˆ๋‹ค.

      LED๋ฅผ 2๊ฐœ ์‚ฌ์šฉํ•จ์œผ๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด ์ˆ˜์ •ํ•˜์˜€๋‹ค.

       

      Pca10028.h
      #define LEDS_NUMBER                 2
      
      #define LED_START                   8
      #define LED_1                       8
      #define LED_2                       9
      #define LED_STOP                    9
      #define LEDS_ACTIVE_STATE           0
      #define LEDS_LIST                   {LED_1, LED_2}
      #define LEDS_INV_MASK               LEDS_MASK
      #define BSP_LED_0                   LED_1
      #define BSP_LED_1                   LED_2
       

      ์ด์ œ bsp_board_leds_init()ํ•จ์ˆ˜์˜ ๋ฐ˜๋ณต๋ฌธ์—์„œ LED 2๊ฐœ๋ฅผ nrf_gpio_cfg_output() ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ GPIO๋ฅผ ํ™œ์„ฑํ™” ์‹œํ‚จ๋‹ค.

       

      components\drivers_nrf\hal\nrf_gpio.h
      __STATIC_INLINE void nrf_gpio_cfg(
          uint32_t             pin_number,
          nrf_gpio_pin_dir_t   dir,
          nrf_gpio_pin_input_t input,
          nrf_gpio_pin_pull_t  pull,
          nrf_gpio_pin_drive_t drive,
          nrf_gpio_pin_sense_t sense)
      {
          NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
      
          reg->PIN_CNF[pin_number] = ((uint32_t)dir << GPIO_PIN_CNF_DIR_Pos)
                                     | ((uint32_t)input << GPIO_PIN_CNF_INPUT_Pos)
                                     | ((uint32_t)pull << GPIO_PIN_CNF_PULL_Pos)
                                     | ((uint32_t)drive << GPIO_PIN_CNF_DRIVE_Pos)
                                     | ((uint32_t)sense << GPIO_PIN_CNF_SENSE_Pos);
      }
      
      __STATIC_INLINE void nrf_gpio_cfg_output(uint32_t pin_number)
      {
          nrf_gpio_cfg(
              pin_number,
              NRF_GPIO_PIN_DIR_OUTPUT,
              NRF_GPIO_PIN_INPUT_DISCONNECT,
              NRF_GPIO_PIN_NOPULL,
              NRF_GPIO_PIN_S0S1,
              NRF_GPIO_PIN_NOSENSE);
      }

       

      nrf_gpio_cfg_output() ํ•จ์ˆ˜๋Š” ์œ„์™€ ๊ฐ™์ด ํ•€๋ฒˆํ˜ธ๋ฅผ ๋ฐ›๊ณ  output ๊ธฐ๋ณธ ์˜ต์…˜์œผ๋กœ nrf_gpio_cfg() ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ์ดˆ๊ธฐํ™” ํ•œ๋‹ค.

       

      nrf_gpio_cfg()ํ•จ์ˆ˜์—์„œ ์‚ฌ์šฉํ•˜๋Š” NRF_GPIO_Type *reg๋ณ€์ˆ˜๋Š” nrf_gpio_pin_port_decode()ํ•จ์ˆ˜์— ์˜ํ•ด NRF_P0์ฆ‰ GPIO ๋ ˆ์ง€์Šคํ„ฐ์˜ Base Address๋ฅผ ๊ฐ€๋ฆฌํ‚ค๊ฒŒ ๋œ๋‹ค.

       

      components\device\nrf52.h

      #define NRF_P0                  ((NRF_GPIO_Type           *) NRF_P0_BASE)
      #define NRF_P0_BASE             0x50000000UL

       

       
      data sheet Page 36.

       

      NRF_GPIO_Type *reg ๋ณ€์ˆ˜์˜ ๊ตฌ์กฐ๋Š” ์•„๋ž˜์™€ ๊ฐ™์œผ๋ฉฐ ๊ตฌ์กฐ์ฒด์˜ ํฌ๊ธฐ๋Š” Table 1. Instances์™€ ๊ฐ™๋‹ค.

       

      components\device\nrf52.h

      /**  
       * @brief GPIO Port 1 (GPIO)  
       */ 
      typedef struct {						/*!< GPIO Structure */  
          __I  uint32_t  RESERVED0[321];  
          __IO uint32_t  OUT;					/*!< Write GPIO port */  
          __IO uint32_t  OUTSET;					/*!< Set individual bits in GPIO port */ 
          __IO uint32_t  OUTCLR;					/*!< Clear individual bits in GPIO port */  
          __I  uint32_t  IN;						/*!< Read GPIO port */  
          __IO uint32_t  DIR;					/*!< Direction of GPIO pins */  
          __IO uint32_t  DIRSET;					/*!< DIR set register */  
          __IO uint32_t  DIRCLR;					/*!< DIR clear register */  
          __IO uint32_t  LATCH;					/*!< Latch register indicating what GPIO pins that have met the criteria set in the PIN_CNF[n].SENSE registers */ 
          __IO uint32_t  DETECTMODE;				/*!< Select between default DETECT signal behaviour and LDETECT mode */  
          __I  uint32_t  RESERVED1[118];  
          __IO uint32_t  PIN_CNF[32];			/*!< Description collection[0]: Configuration of GPIO pins */
      } NRF_GPIO_Type;

       

       

      ์•„๋ž˜ Table์€ NORDIC Info center ์—์„œ ์ œ๊ณตํ•˜๋Š” ์ž๋ฃŒ์ด๋ฉฐ URL์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

       

      ๊ตฌ์กฐ์ฒด์— ์˜ํ•ด GPIO ๋ ˆ์ง€์Šคํ„ฐ์— ๊ฐ’์ด ์„ค์ •๋˜๋ฉด GPIO ํ•€์ด ํ™œ์„ฑํ™” ๋˜์–ด ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•ด์ง„๋‹ค.

       

       

      ADC (Analog to Digital Converter)

      components\drivers_nrf\hal\nrf5_adc.h

      /**@brief Analog-to-digital converter configuration. */
      typedef struct
      {
          nrf_adc_config_resolution_t resolution; /**< ADC resolution. */
          nrf_adc_config_scaling_t    scaling;    /**< ADC scaling factor. */
          nrf_adc_config_reference_t  reference;  /**< ADC reference. */
      } nrf_adc_config_t;
      
      /** Default ADC configuration. */
      #define NRF_ADC_CONFIG_DEFAULT { NRF_ADC_CONFIG_RES_10BIT,               \
                                       NRF_ADC_CONFIG_SCALING_INPUT_ONE_THIRD, \
                                       NRF_ADC_CONFIG_REF_VBG }

       

      ์œ„์˜ nrf_adc_config_t ๊ตฌ์กฐ์ฒด ํƒ€์ž… ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ  NRF_ADC_CONFIG_DEFAULT ๊ฐ’์œผ๋กœ ๋ณ€์ˆ˜๋ฅผ ์ดˆ๊ธฐํ™” ํ•œ๋‹ค.

      ์•„๋ž˜์™€ ๊ฐ™์ด ๋ฏธ๋ฆฌ ์„ ์–ธ๋œ adc config default ๊ฐ’์œผ๋กœ ์‚ฌ์šฉ.

       

      nrf_adc_config_t config = NRF_ADC_CONFIG_DEFAULT;   /* resolution : 2, scaling : 2, reference : 0 */
       

       

      ์œ„์—์„œ ์„ ์–ธํ•œ ๋ณ€์ˆ˜๋ฅผ ์ธ์ž ๊ฐ’์œผ๋กœ nrf_adc_configure()ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ADC Config ๊ฐ’์„ ADC ๋ ˆ์ง€์Šคํ„ฐ์— ์„ค์ •ํ•œ๋‹ค.

       

      components\drivers_nrf\hal\nrf_adc.c

      /**
       * @brief Function for configuring ADC.
       *
       * This function powers on ADC and configures it. ADC is in DISABLE state after configuration,
       * so it should be enabled before using it.
       *
       * @param[in] config  Requested configuration.
       */
      void nrf_adc_configure(nrf_adc_config_t * config)
      {
          uint32_t config_reg = 0;
      
          config_reg |= ((uint32_t)config->resolution << ADC_CONFIG_RES_Pos) & ADC_CONFIG_RES_Msk;
          config_reg |= ((uint32_t)config->scaling << ADC_CONFIG_INPSEL_Pos) & ADC_CONFIG_INPSEL_Msk;
          config_reg |= ((uint32_t)config->reference << ADC_CONFIG_REFSEL_Pos) & ADC_CONFIG_REFSEL_Msk;
      
          if (config->reference & ADC_CONFIG_EXTREFSEL_Msk) {
              config_reg |= config->reference & ADC_CONFIG_EXTREFSEL_Msk;
          }
      
          /* select input */
          nrf_adc_input_select(NRF_ADC_CONFIG_INPUT_DISABLED);
      
          /* set new configuration keeping selected input */
          NRF_ADC->CONFIG = config_reg | (NRF_ADC->CONFIG & ADC_CONFIG_PSEL_Msk);
      }
       

       

      nrf_adc_configure()ํ•จ์ˆ˜๋Š” ์•„๋ž˜์˜ NRF_ADC_BASEaddress์— ์ ‘๊ทผํ•˜์—ฌ Config ๊ฐ’์„ ์„ค์ •ํ•œ๋‹ค.

       

      components\device\nrf51.h

      /**
        * @brief Analog to digital converter. (ADC)
        */
      
      typedef struct {                                    /*!< ADC Structure                                                         */
        __O  uint32_t  TASKS_START;                       /*!< Start an ADC conversion.                                              */
        __O  uint32_t  TASKS_STOP;                        /*!< Stop ADC.                                                             */
        __I  uint32_t  RESERVED0[62];
        __IO uint32_t  EVENTS_END;                        /*!< ADC conversion complete.                                              */
        __I  uint32_t  RESERVED1[128];
        __IO uint32_t  INTENSET;                          /*!< Interrupt enable set register.                                        */
        __IO uint32_t  INTENCLR;                          /*!< Interrupt enable clear register.                                      */
        __I  uint32_t  RESERVED2[61];
        __I  uint32_t  BUSY;                              /*!< ADC busy register.                                                    */
        __I  uint32_t  RESERVED3[63];
        __IO uint32_t  ENABLE;                            /*!< ADC enable.                                                           */
        __IO uint32_t  CONFIG;                            /*!< ADC configuration register.                                           */
        __I  uint32_t  RESULT;                            /*!< Result of ADC conversion.                                             */
        __I  uint32_t  RESERVED4[700];
        __IO uint32_t  POWER;                             /*!< Peripheral power control.                                             */
      } NRF_ADC_Type;
      
      #define NRF_ADC                 ((NRF_ADC_Type            *) NRF_ADC_BASE)
      #define NRF_ADC_BASE            0x40007000UL
       

       

      data sheet Page 36.

       

      ์ด๋กœ์จ ADC ์‚ฌ์šฉ์ค€๋น„๊ฐ€ ์™„๋ฃŒ ๋œ๋‹ค.

       

       

       

       

       

      728x90
      ๋ฐ˜์‘ํ˜•

      'Microprocessor > STM32' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

      Open103V(STM32F103VET) ๋น„ํŠธ๋งต ํŒŒ์ผ ๋‹ค๋ฃจ๊ธฐ  (0) 2019.02.01
      STM32F130C8T6 (feat.TDCR1050M FND)  (0) 2018.11.19
      MPU-9250 Module  (2) 2016.12.12
      PLM-100 RF Module  (6) 2016.12.12
      STM32F103VCT6 for MPU-9250 ์ž์ด๋กœ ์„ผ์„œ StartUp  (0) 2016.09.26
    ์ƒ๋‹จ์œผ๋กœ