nRF51422-QFAB (GPIO/ADC)
๋ชฉ์ฐจ
NORDIC nRF51422 Link : https://www.nordicsemi.com/eng/Products/ANT/nRF51422
๐ NORDIC ์์ ๋ง๋ Cortex-M0 ๊ธฐ๋ฐ์ Bluetooth 4.0 Single Mode ๋ฐ ANT+ ๋ฅผ ๋์์ ์ ์ฉํ ์ ์๋ Chip์ผ๋ก ์ฌ์์ ์๋์ ๊ฐ๋ค.
๐ Pin P0.08, P0.09๋ฅผ ์ด์ฉํ์ฌ GPIO๋ฅผ ํ์ฑํ ํ๊ณ , LED๋ฅผ ON์์ผ๋ณด์.
SDK Download Url : https://www.nordicsemi.com/eng/nordic/Products/nRF51822/nRF5-SDK-v12-zip/54280
SDK์ ์ ๊ณต๋๋ examples ์ experimental_ble_app_blinky๋ฅผ ์ฐธ๊ณ ํ์ฌ Source๋ฅผ ๋ถ์ํ์๋ค.
main()
ํจ์์์ ํธ์ถ๋๋ leds_init()
ํจ์ ๋ด๋ถ์๋ bsp์์ ์ ๊ณตํ๋ bsp_board_leds_init()
ํจ์๋ฅผ ํธ์ถํ๋ค.
#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๊ฐ ์ฌ์ฉํจ์ผ๋ก ์๋์ ๊ฐ์ด ์์ ํ์๋ค.
#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๋ฅผ ํ์ฑํ ์ํจ๋ค.
__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
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 ํ์ด ํ์ฑํ ๋์ด ์ฌ์ฉ์ด ๊ฐ๋ฅํด์ง๋ค.
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_BASE
address์ ์ ๊ทผํ์ฌ 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 ์ฌ์ฉ์ค๋น๊ฐ ์๋ฃ ๋๋ค.
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 |