• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ NVIC_EnableIRQ函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中NVIC_EnableIRQ函数的典型用法代码示例。如果您正苦于以下问题:C++ NVIC_EnableIRQ函数的具体用法?C++ NVIC_EnableIRQ怎么用?C++ NVIC_EnableIRQ使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NVIC_EnableIRQ函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: rt_uart_open

void rt_uart_open()
{
	/* Enable the UART Interrupt */
	NVIC_EnableIRQ(UART_IRQn);
}
开发者ID:AbuShaqra,项目名称:lpc1114fn28,代码行数:5,代码来源:main.cpp


示例2: main

/**
 *  \brief ACC example application entry point.
 *
 *  \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint8_t uc_key;
	int16_t s_volt = 0;
	uint32_t ul_value = 0;
	volatile uint32_t ul_status = 0x0;
	int32_t l_volt_dac0 = 0;

	/* Initialize the system */
	sysclk_init();
	board_init();

	/* Initialize debug console */
	configure_console();

	/* Output example information */
	puts(STRING_HEADER);

	/* Initialize DACC */
	/* Enable clock for DACC */
	pmc_enable_periph_clk(ID_DACC);
	/* Reset DACC registers */
	dacc_reset(DACC);
	/* External trigger mode disabled. DACC in free running mode. */
	dacc_disable_trigger(DACC);
	/* Half word transfer mode */
	dacc_set_transfer_mode(DACC, 0);
	/* Power save:
	 * sleep mode  - 0 (disabled)
	 * fast wakeup - 0 (disabled)
	 */
	dacc_set_power_save(DACC, 0, 0);
	/* Timing:
	 * refresh        - 0x08 (1024*8 dacc clocks)
	 * max speed mode -    0 (disabled)
	 * startup time   - 0xf (960 dacc clocks)
	 */
	dacc_set_timing(DACC, 0x08, 0, 0xf);
	/* Disable TAG and select output channel DACC_CHANNEL */
	dacc_set_channel_selection(DACC, DACC_CHANNEL_0);
	/* Enable output channel DACC_CHANNEL */
	dacc_enable_channel(DACC, DACC_CHANNEL_0);
	/* Setup analog current */
	dacc_set_analog_control(DACC, DACC_ANALOG_CONTROL);

	/* Set DAC0 output at ADVREF/2. The DAC formula is:
	 *
	 * (5/6 * VOLT_REF) - (1/6 * VOLT_REF)     volt - (1/6 * VOLT_REF)
	 * ----------------------------------- = --------------------------
	 *              MAX_DIGITAL                       digit
	 *
	 * Here, digit = MAX_DIGITAL/2
	 */
	dacc_write_conversion_data(DACC, MAX_DIGITAL / 2);
	l_volt_dac0 = (MAX_DIGITAL / 2) * (2 * VOLT_REF / 3) / MAX_DIGITAL +
			VOLT_REF / 6;

	/* Initialize ADC */
	/* Enable clock for ADC */
	pmc_enable_periph_clk(ID_ADC);
	/*
	 * Formula: ADCClock = MCK / ( (PRESCAL+1) * 2 )
	 * For example, MCK = 64MHZ, PRESCAL = 4, then:
	 *     ADCClock = 64 / ((4+1) * 2) = 6.4MHz;
	 */
	adc_init(ADC, sysclk_get_cpu_hz(), ADC_CLOCK, ADC_STARTUP_TIME_SETTING);

	/* Formula:
	 *     Startup  Time = startup value / ADCClock
	 *     Transfer Time = (TRANSFER * 2 + 3) / ADCClock
	 *     Tracking Time = (TRACKTIM + 1) / ADCClock
	 *     Settling Time = settling value / ADCClock
	 * For example, ADC clock = 6MHz (166.7 ns)
	 *     Startup time = 512 / 6MHz = 85.3 us
	 *     Transfer Time = (1 * 2 + 3) / 6MHz = 833.3 ns
	 *     Tracking Time = (0 + 1) / 6MHz = 166.7 ns
	 *     Settling Time = 3 / 6MHz = 500 ns
	 */
	/* Set ADC timing */
	adc_configure_timing(ADC, ADC_TRACK_SETTING, ADC_SETTLING_TIME_3,
			ADC_TRANSFER_SETTING);

	/* Channel 5 has to be compared */
	adc_enable_channel(ADC, ADC_CHANNEL_5);

	/* Enable clock for ACC */
	pmc_enable_periph_clk(ID_ACC);
	/* Initialize ACC */
	acc_init(ACC, ACC_MR_SELPLUS_AD5, ACC_MR_SELMINUS_DAC0,
			ACC_MR_EDGETYP_ANY, ACC_MR_INV_DIS);

	/* Enable ACC interrupt */
	NVIC_EnableIRQ(ACC_IRQn);

	/* Enable */
//.........这里部分代码省略.........
开发者ID:AndreyMostovov,项目名称:asf,代码行数:101,代码来源:acc_example.c


示例3: gpio_init_int

int gpio_init_int(gpio_t dev, gpio_pp_t pullup, gpio_flank_t flank, gpio_cb_t cb, void *arg)
{
    int res;
    uint8_t pin;

    if (dev >= GPIO_NUMOF) {
        return -1;
    }

    pin = gpio_pin_map[dev];

    /* configure pin as input */
    res = gpio_init(dev, GPIO_DIR_IN, pullup);
    if (res < 0) {
        return res;
    }

    /* set interrupt priority (its the same for all EXTI interrupts) */
    NVIC_SetPriority(EXTI0_1_IRQn, GPIO_IRQ_PRIO);
    NVIC_SetPriority(EXTI2_3_IRQn, GPIO_IRQ_PRIO);
    NVIC_SetPriority(EXTI4_15_IRQn, GPIO_IRQ_PRIO);

    /* enable clock of the SYSCFG module for EXTI configuration */
    RCC->APB2ENR |= RCC_APB2ENR_SYSCFGCOMPEN;

    /* read pin number, set EXIT channel and enable global interrupt for EXTI channel */
    switch (dev) {
#ifdef GPIO_0_EN
        case GPIO_0:
            GPIO_0_EXTI_CFG();
            break;
#endif
#ifdef GPIO_1_EN
        case GPIO_1:
            GPIO_1_EXTI_CFG();
            break;
#endif
#ifdef GPIO_2_EN
        case GPIO_2:
            GPIO_2_EXTI_CFG();
            break;
#endif
#ifdef GPIO_3_EN
        case GPIO_3:
            GPIO_3_EXTI_CFG();
            break;
#endif
#ifdef GPIO_4_EN
        case GPIO_4:
            GPIO_4_EXTI_CFG();
            break;
#endif
#ifdef GPIO_5_EN
        case GPIO_5:
            GPIO_5_EXTI_CFG();
            break;
#endif
#ifdef GPIO_6_EN
        case GPIO_6:
            GPIO_6_EXTI_CFG();
            break;
#endif
#ifdef GPIO_7_EN
        case GPIO_7:
            GPIO_7_EXTI_CFG();
            break;
#endif
#ifdef GPIO_8_EN
        case GPIO_8:
            GPIO_8_EXTI_CFG();
            break;
#endif
#ifdef GPIO_9_EN
        case GPIO_9:
            GPIO_9_EXTI_CFG();
            break;
#endif
#ifdef GPIO_10_EN
        case GPIO_10:
            GPIO_10_EXTI_CFG();
            break;
#endif
#ifdef GPIO_11_EN
        case GPIO_11:
            GPIO_11_EXTI_CFG();
            break;
#endif
    }
    NVIC_EnableIRQ(gpio_irq_map[dev]);

    /* set callback */
    gpio_config[dev].cb = cb;
    gpio_config[dev].arg = arg;

    /* configure the event that triggers an interrupt */
    switch (flank) {
        case GPIO_RISING:
            EXTI->RTSR |= (1 << pin);
            EXTI->FTSR &= ~(1 << pin);
            break;
//.........这里部分代码省略.........
开发者ID:4dahalibut,项目名称:RIOT,代码行数:101,代码来源:gpio.c


示例4: HabilitarTimer

void HabilitarTimer(void)
{
	//	Habilita la interrupción para el timer
NVIC_EnableIRQ(RITIMER_IRQn);// irq11
}
开发者ID:jeracker,项目名称:HorcoMolle,代码行数:5,代码来源:timer.c


示例5: udd_enable

void udd_enable(void)
{
	irqflags_t flags;

	flags = cpu_irq_save();

#ifdef UHD_ENABLE
	// DUAL ROLE INITIALIZATION
	if (otg_dual_enable()) {
		// The current mode has been started by otg_dual_enable()
		cpu_irq_restore(flags);
		return;
	}
#else
	// SINGLE DEVICE MODE INITIALIZATION
	sysclk_enable_usb();
	pmc_enable_periph_clk(ID_UOTGHS);

	// Here, only the device mode is possible, then link UHDP interrupt to UDD interrupt
	NVIC_SetPriority((IRQn_Type) ID_UOTGHS, USB_INT_LEVEL);
	NVIC_EnableIRQ((IRQn_Type) ID_UOTGHS);

	// Always authorize asynchrony USB interrupts to exit of sleep mode
	// For SAM USB wake up device except BACKUP mode
	pmc_set_fast_startup_input(PMC_FSMR_USBAL);
#endif

#if (OTG_ID_IO) && (defined UHD_ENABLE)
	// Check that the device mode is selected by ID pin
	if (!Is_otg_id_device()) {
		cpu_irq_restore(flags);
		return; // Device is not the current mode
	}
#else
	// ID pin not used and force device mode
	otg_force_device_mode();
#endif
	// Enable USB hardware
	otg_enable();

	// Reset internal variables
#if (0!=USB_DEVICE_MAX_EP)
	udd_ep_job_table_reset();
#endif

#ifndef UDD_NO_SLEEP_MGR
	if (!udd_b_sleep_initialized) {
		udd_b_sleep_initialized = true;
		// Initialize the sleep mode authorized for the USB suspend mode
		udd_b_idle = false;
		sleepmgr_lock_mode(UHDP_SLEEP_MODE_USB_SUSPEND);
	} else {
		udd_sleep_mode(false); // Enter idle mode
	}
#endif

#if OTG_VBUS_IO
	/* Initialize VBus monitor */
	otg_vbus_init(udd_vbus_handler);
	udd_vbus_monitor_sleep_mode(true);
	/* Force VBus interrupt when VBus is always high
	 * This is possible due to a short timing between a Host mode stop/start.
	 */
	if (Is_otg_vbus_high()) {
		udd_vbus_handler(USB_VBUS_PIO_ID, USB_VBUS_PIO_MASK);
	}
#else
#  ifndef USB_DEVICE_ATTACH_AUTO_DISABLE
	udd_attach();
#  endif
#endif

	cpu_irq_restore(flags);
}
开发者ID:AndreyMostovov,项目名称:asf,代码行数:74,代码来源:uhdp_device.c


示例6: timer_init

int timer_init(tim_t dev, unsigned int ticks_per_us, void (*callback)(int))
{
    if (dev >= TIMER_NUMOF) {
        return -1;
    }

    /* save callback */
    timer_config[dev].cb = callback;
    /* power on timer */
    timer[dev]->POWER = 1;

    switch (dev) {
#if TIMER_0_EN
        case TIMER_0:
            TIMER_0_DEV->BITMODE = TIMER_0_BITMODE;
            NVIC_SetPriority(TIMER_0_IRQ, TIMER_IRQ_PRIO);
            NVIC_EnableIRQ(TIMER_0_IRQ);
            break;
#endif
#if TIMER_1_EN
        case TIMER_1:
            TIMER_1_DEV->BITMODE = TIEMR_1_BITMODE;
            NVIC_SetPriority(TIMER_1_IRQ, TIMER_IRQ_PRIO);
            NVIC_EnableIRQ(TIMER_1_IRQ);
            break;
#endif
#if TIMER_2_EN
        case TIMER_2:
            TIMER_2_DEV->BITMODE = TIMER_2_BITMODE;
            NVIC_SetPriority(TIMER_2_IRQ, TIMER_IRQ_PRIO);
            NVIC_EnableIRQ(TIMER_2_IRQ);
            break;
#endif
    case TIMER_UNDEFINED:
        return -1;
    }

    timer[dev]->TASKS_STOP = 1;
    timer[dev]->MODE = TIMER_MODE_MODE_Timer;        /* set the timer in Timer Mode. */
    timer[dev]->TASKS_CLEAR    = 1;                  /* clear the task first to be usable for later. */

    switch (ticks_per_us) {
        case 1:
            timer[dev]->PRESCALER = 4;
            break;
        case 2:
            timer[dev]->PRESCALER = 5;
            break;
        case 4:
            timer[dev]->PRESCALER = 6;
            break;
        case 8:
            timer[dev]->PRESCALER = 7;
            break;
        case 16:
            timer[dev]->PRESCALER = 8;
            break;
        default:
            return -1;
    }

    /* reset compare state */
    timer[dev]->EVENTS_COMPARE[0] = 0;
    timer[dev]->EVENTS_COMPARE[1] = 0;
    timer[dev]->EVENTS_COMPARE[2] = 0;

    /* start the timer */
    timer[dev]->TASKS_START = 1;
    return 0;
}
开发者ID:4dahalibut,项目名称:RIOT,代码行数:70,代码来源:timer.c


示例7: c_entry

/*********************************************************************//**
 * @brief		c_entry: Main UART program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry(void)
{
	// UART Configuration structure variable
	UART_CFG_Type UARTConfigStruct;
	// UART FIFO configuration Struct variable
	UART_FIFO_CFG_Type UARTFIFOConfigStruct;
	// Pin configuration for UART0
	PINSEL_CFG_Type PinCfg;

	uint32_t idx, len;
	__IO FlagStatus exitflag;
	uint8_t buffer[10];

	/*
	 * Initialize UART0 pin connect
	 */
	PinCfg.Funcnum = 1;
	PinCfg.OpenDrain = 0;
	PinCfg.Pinmode = 0;
	PinCfg.Pinnum = 2;
	PinCfg.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 3;
	PINSEL_ConfigPin(&PinCfg);


	/* Initialize UART Configuration parameter structure to default state:
	 * Baudrate = 9600bps
	 * 8 data bit
	 * 1 Stop bit
	 * None parity
	 */
	UART_ConfigStructInit(&UARTConfigStruct);

	// Initialize UART0 peripheral with given to corresponding parameter
	UART_Init((LPC_UART_TypeDef *)LPC_UART0, &UARTConfigStruct);


	/* Initialize FIFOConfigStruct to default state:
	 * 				- FIFO_DMAMode = DISABLE
	 * 				- FIFO_Level = UART_FIFO_TRGLEV0
	 * 				- FIFO_ResetRxBuf = ENABLE
	 * 				- FIFO_ResetTxBuf = ENABLE
	 * 				- FIFO_State = ENABLE
	 */
	UART_FIFOConfigStructInit(&UARTFIFOConfigStruct);

	// Initialize FIFO for UART0 peripheral
	UART_FIFOConfig((LPC_UART_TypeDef *)LPC_UART0, &UARTFIFOConfigStruct);


	// Enable UART Transmit
	UART_TxCmd((LPC_UART_TypeDef *)LPC_UART0, ENABLE);

    /* Enable UART Rx interrupt */
	UART_IntConfig((LPC_UART_TypeDef *)LPC_UART0, UART_INTCFG_RBR, ENABLE);
	/* Enable UART line status interrupt */
	UART_IntConfig((LPC_UART_TypeDef *)LPC_UART0, UART_INTCFG_RLS, ENABLE);
	/*
	 * Do not enable transmit interrupt here, since it is handled by
	 * UART_Send() function, just to reset Tx Interrupt state for the
	 * first time
	 */
	TxIntStat = RESET;

	// Reset ring buf head and tail idx
	__BUF_RESET(rb.rx_head);
	__BUF_RESET(rb.rx_tail);
	__BUF_RESET(rb.tx_head);
	__BUF_RESET(rb.tx_tail);

    /* preemption = 1, sub-priority = 1 */
    NVIC_SetPriority(UART0_IRQn, ((0x01<<3)|0x01));
	/* Enable Interrupt for UART0 channel */
    NVIC_EnableIRQ(UART0_IRQn);


	// print welcome screen
	print_menu();

	// reset exit flag
	exitflag = RESET;

    /* Read some data from the buffer */
    while (exitflag == RESET)
    {
       len = 0;
        while (len == 0)
        {
            len = UARTReceive((LPC_UART_TypeDef *)LPC_UART0, buffer, sizeof(buffer));
        }

        /* Got some data */
        idx = 0;
        while (idx < len)
//.........这里部分代码省略.........
开发者ID:m3y54m,项目名称:32bitmicro,代码行数:101,代码来源:uart_interrupt_test.c


示例8: gpio_irq_enable

void gpio_irq_enable(gpio_irq_t *obj) {
    NVIC_EnableIRQ(GPIO_IRQn);
}
开发者ID:1deus,项目名称:tmk_keyboard,代码行数:3,代码来源:gpio_irq_api.c


示例9: main

int main (void) {
	int i;
  /* Basic chip initialization is taken care of in SystemInit() called
   * from the startup code. SystemInit() and chip settings are defined
   * in the CMSIS system_<part family>.c file.
   */

	SysTick->LOAD  = (SystemCoreClock/100) -1;
	SysTick->VAL   = 0;                                          /* Load the SysTick Counter Value */
	SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk |
	                   SysTick_CTRL_ENABLE_Msk;                    /* Enable SysTick IRQ and SysTick Timer */

	while(1)
	{
		__disable_irq();
		LPC_IOCON->R_PIO0_11 &= ~0x3E;
		LPC_IOCON->R_PIO0_11 |=  0x81;
		LPC_GPIO0->DIR  = 0xBCE;			// PIO0_0 - PIO0_11 as output (exclude reset, I2C, swdclk)
		LPC_GPIO0->MASKED_ACCESS[0xBCE] = ~0; // Drive the pins high
		LPC_SYSCON->STARTAPRP0 = 0;  		// falling edge
		LPC_SYSCON->STARTRSRP0CLR = LPC_SYSCON->STARTRSRP0CLR;	// Clear all interrupts
		LPC_SYSCON->STARTERP0 = 0xBCE; 		// enable interrupts

		for(i=0;i<8;i++)
		{
			int irq;

			// The logic below converts our ordinal index 0-7 to an interrupt vector number.
			// For simplicity we skip vector 0 which is on PIO0_0 the reset pin, vectors 4,5
			// which are I2C pins and need pullups, and vector 10 which is PIO0_10 the SWDCLK pin.
			irq = i + 1;
			if(irq >= 4) irq += 2;
			if(irq == 10) irq++;
			NVIC_EnableIRQ(irq);

			// Create priority levels for different interrupts. For the Cortex-M0,
			// there are priorities 0-3. On the Cortex-M3 parts like the LPC1343,
			// priorities can be from 0-7.
			priLUT[irq] = i%4;

			NVIC_SetPriority(irq, priLUT[irq]);
		}
		LPC_GPIO0->MASKED_ACCESS[0xBCE] = 0; // Drive pins low

		// Zero the data structure
		for(i=0;i<30;i++)
		{
			IR[i].VectorNumber = IR[i].IntClocks = 0;
		}
		IRIdx = 0;

		LPC_GPIO0->MASKED_ACCESS[0xBCE] = ~0; // Drive the pins high again
		__enable_irq();

		// Wait 1 second
		for(i=0;i<100;i++)
			while(! (SysTick->CTRL&SysTick_CTRL_COUNTFLAG_Msk));

		// Now print out the interrupt results
		debug_printf(" N: Vec Pri Pending Cycles\n");
		for(i=0;i<IRIdx;i++)
		{
			debug_printf("%2d: %3d %3d %7x %d\n", i, IR[i].VectorNumber, priLUT[IR[i].VectorNumber], IR[i].Pending, IR[0].IntClocks - IR[i].IntClocks);
		}

		// Wait 5 seconds
		for(i=0;i<500;i++)
			while(! (SysTick->CTRL&SysTick_CTRL_COUNTFLAG_Msk));
	}
}
开发者ID:adamallaf,项目名称:LPC1114-sandbox,代码行数:70,代码来源:intpriority_main.c


示例10: ser_phy_interrupts_enable

void ser_phy_interrupts_enable(void)
{
    NVIC_EnableIRQ(UART0_IRQn);
    NVIC_EnableIRQ(GPIOTE_IRQn);
}
开发者ID:451506709,项目名称:automated_machine,代码行数:5,代码来源:ser_phy_nrf51_uart_stm_app.c


示例11: ser_phy_open

uint32_t ser_phy_open(ser_phy_events_handler_t events_handler)
{
    if (events_handler == NULL)
    {
        return NRF_ERROR_NULL;
    }

    //Check if function was not called before
    if (m_ser_phy_event_handler != NULL)
    {
        return NRF_ERROR_INVALID_STATE;
    }

    //GPIO Setup
    nrf_gpio_cfg_input(SER_PHY_UART_RTS, NRF_GPIO_PIN_NOPULL);

    NRF_GPIO->OUTSET = 1 << SER_PHY_UART_TX;
    nrf_gpio_cfg_output(SER_PHY_UART_TX);

    //Setup the gpiote to handle pin events on cts-pin.
    //For the UART we want to detect both low->high and high->low transitions in order to
    //know when to activate/de-activate the TX/RX in the UART.
    //Configure pin.
    m_pin_cts_mask = (1 << SER_PHY_UART_CTS);
    nrf_gpio_cfg_sense_input(SER_PHY_UART_CTS,
                             NRF_GPIO_PIN_PULLUP,
                             NRF_GPIO_PIN_SENSE_LOW);

    nrf_gpio_cfg_sense_input(SER_PHY_UART_RX,
                             NRF_GPIO_PIN_PULLUP,
                             NRF_GPIO_PIN_NOSENSE);

    (void)app_gpiote_input_event_handler_register(0,
                                                  SER_PHY_UART_CTS,
                                                  GPIOTE_CONFIG_POLARITY_Toggle,
                                                  gpiote_evt_handler);
    (void)app_gpiote_enable_interrupts();

    NVIC_ClearPendingIRQ(PendSV_IRQn);

    m_rx_state = UART_IDLE;
    m_tx_state = UART_IDLE;

    //Set header flag
    m_rx_stream_header = true;

    //UART setup
    NRF_UART0->PSELRXD  = SER_PHY_UART_RX;
    NRF_UART0->PSELTXD  = SER_PHY_UART_TX;
    NRF_UART0->PSELCTS  = UART_PIN_DISCONNECTED;
    NRF_UART0->PSELRTS  = UART_PIN_DISCONNECTED;
    NRF_UART0->BAUDRATE = SER_PHY_UART_BAUDRATE;
    NRF_UART0->CONFIG   = (UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
    NRF_UART0->ENABLE   = (UART_ENABLE_ENABLE_Disabled << UART_ENABLE_ENABLE_Pos);

    //Enable UART interrupt
    NRF_UART0->INTENCLR = 0xFFFFFFFF;
    NRF_UART0->INTENSET = (UART_INTENSET_TXDRDY_Set << UART_INTENSET_TXDRDY_Pos) |
                          (UART_INTENSET_RXDRDY_Set << UART_INTENSET_RXDRDY_Pos) |
                          (UART_INTENSET_ERROR_Set << UART_INTENSET_ERROR_Pos);

    NVIC_ClearPendingIRQ(UART0_IRQn);
    NVIC_SetPriority(UART0_IRQn, APP_IRQ_PRIORITY_MID);
    NVIC_EnableIRQ(UART0_IRQn);

    m_ser_phy_event_handler = events_handler;

    return NRF_SUCCESS;
}
开发者ID:451506709,项目名称:automated_machine,代码行数:69,代码来源:ser_phy_nrf51_uart_stm_app.c


示例12: CMU_ClockEnable

void DebugInterface::initializeDebugUart()
{
#if SentioEM_Emulator_Interface == OFF && SentioEM_Debug_Interface == ON
	// Configuration of the GPIO-Pins which belong to the UART/USART configured. Furthermore the RX-Interrupt
	//Service Routine of the UART is enabled.
	// In a first switch-case statement the UART/USART Module is selected. Then the RX/TX Pins which have
	// to be activated are selected

// Select module UART0, valid Location on the EFM32G280 are (0,1,2,3)
#if _DEBUG_USART_ < 8

	//Enable the required periphery clock
	CMU_ClockEnable(cmuClock_UART0,true);

	// Enable the RX-Interrupt Service Routine
	NVIC_EnableIRQ( UART0_RX_IRQn );

	#define DEBUG_USART  UART0

	// Select the IO-Pins dependent on Module-Location
	#if _DEBUG_USART_ == _UART0_LOC0_
		#define port  gpioPortF
		#define pinRX 7
		#define pinTX 6
		#define DEBUG_LOCATION  USART_ROUTE_LOCATION_LOC0

	#elif _DEBUG_USART_ == _UART0_LOC1_
		#define port  gpioPortE
		#define pinRX 1
		#define pinTX 0
		#define DEBUG_LOCATION  USART_ROUTE_LOCATION_LOC1

	#elif _DEBUG_USART_ == _UART0_LOC2_
		#define port  gpioPortA
		#define pinRX 4
		#define pinTX 3
		#define DEBUG_LOCATION  USART_ROUTE_LOCATION_LOC2

	#elif _DEBUG_USART_ == _UART0_LOC3_
		#define port  gpioPortC
		#define pinRX 15
		#define pinTX 14
		#define DEBUG_LOCATION  USART_ROUTE_LOCATION_LOC3
	#endif

// Select module USART0, valid Location on the EFM32G280 are (0,1,2)
#elif ( _DEBUG_USART_ > 9 ) && ( _DEBUG_USART_ < 19 )

	//Enable the required periphery clock
	CMU_ClockEnable(cmuClock_USART0,true);

	// Enable the RX-Interrupt Service Routine
	NVIC_EnableIRQ( USART0_RX_IRQn );

	#define _DEBUG_USART_  USART0

	// Select the IO-Pins dependent on Module-Location
	#if _DEBUG_USART_ == _USART0_LOC0_
		#define port  gpioPortE
		#define pinRX 11
		#define pinTX 10
		#define DEBUG_LOCATION  USART_ROUTE_LOCATION_LOC0

	#elif _DEBUG_USART_ == _USART0_LOC1_
		#define port  gpioPortE
		#define pinRX 6
		#define pinTX 7
		#define DEBUG_LOCATION  USART_ROUTE_LOCATION_LOC1

	#elif _DEBUG_USART_ == _USART0_LOC2_
		#define port  gpioPortC
		#define	pinRX 10
		#define pinTX 11
		#define DEBUG_LOCATION  USART_ROUTE_LOCATION_LOC2
	#endif


// Select module USART1, valid Location on the EFM32G280 are (0,1)
#elif( _DEBUG_USART_ > 19 ) && ( _DEBUG_USART_ < 29 )

	//Enable the required periphery clock
	CMU_ClockEnable(cmuClock_USART1,true);

	// Enable the RX-Interrupt Service Routine
	NVIC_EnableIRQ( USART1_RX_IRQn );

	#define DEBUG_USART  USART1

	// Select the IO-Pins dependent on Module-Location
	#if _DEBUG_USART_ == _USART1_LOC0_
		#define	port  gpioPortC
		#define	pinRX 1
		#define pinTX 0
		#define DEBUG_LOCATION  USART_ROUTE_LOCATION_LOC0

	#elif _DEBUG_USART_ == _USART1_LOC1_
		#define port  gpioPortD
		#define pinRX 1
		#define pinTX 0
		#define DEBUG_LOCATION  USART_ROUTE_LOCATION_LOC1
//.........这里部分代码省略.........
开发者ID:makr0900,项目名称:sentio-framework,代码行数:101,代码来源:DebugInterface.cpp


示例13: main

/*---------------------------------------------------------------------------------------------------------*/
int main(void)
{
    volatile uint32_t u32InitCount;

    /* Unlock protected registers */
    SYS_UnlockReg();

    /* Init System, peripheral clock and multi-function I/O */
    SYS_Init();

    /* Lock protected registers */
    SYS_LockReg();

    /* Init UART0 for printf */
    UART0_Init();

    printf("\n\nCPU @ %d Hz\n", SystemCoreClock);
    printf("+-------------------------------------------------+\n");
    printf("|    Timer1 External Counter Input Sample Code    |\n");
    printf("+-------------------------------------------------+\n\n");

    printf("# Timer Settings:\n");
    printf("  Timer1: Clock source is HCLK(50 MHz); Continuous counting mode; Interrupt enable;\n");
    printf("          External counter input enable; TCMP is 56789.\n");
    printf("# Connect P2.0 to T1 pin and pull P2.0 High/Low as T1 counter input source.\n\n");

    /* Configure P2.0 as GPIO output pin and pull pin status to Low first */
    P2->PMD = 0xFFFD;
    P20 = 0;

    /* Enable Timer1 NVIC */
    NVIC_EnableIRQ(TMR1_IRQn);

    /* Clear Timer1 interrupt counts to 0 */
    g_au32TMRINTCount[1] = 0;

    /* Enable Timer1 external counter input function */
    TIMER1->TCMPR = 56789;
    TIMER1->TCSR = TIMER_TCSR_CEN_Msk | TIMER_TCSR_IE_Msk | TIMER_TCSR_CTB_Msk | TIMER_CONTINUOUS_MODE;

    /* To check if TDR of Timer1 must be 0 as default value */
    if(TIMER_GetCounter(TIMER1) != 0)
    {
        printf("Default counter value is not 0. (%d)\n", TIMER_GetCounter(TIMER1));

        /* Stop Timer1 counting */
        TIMER1->TCSR = 0;
        while(1);
    }

    /* To generate one counter event to T1 pin */
    GeneratePORT2Counter(0, 1);

    /* To check if TDR of Timer1 must be 1 */
    while(TIMER_GetCounter(TIMER1) == 0);
    if(TIMER_GetCounter(TIMER1) != 1)
    {
        printf("Get unexpected counter value. (%d)\n", TIMER_GetCounter(TIMER1));

        /* Stop Timer1 counting */
        TIMER1->TCSR = 0;
        while(1);
    }

    /* To generate remains counts to T1 pin */
    GeneratePORT2Counter(0, (56789 - 1));

    while(1)
    {
        if((g_au32TMRINTCount[1] == 1) && (TIMER_GetCounter(TIMER1) == 56789))
        {
            printf("Timer1 external counter input function ... PASS.\n");
            break;
        }
    }

    /* Stop Timer1 counting */
    TIMER1->TCSR = 0;

    while(1);
}
开发者ID:wright0418,项目名称:Nuvoton-Zero,代码行数:82,代码来源:main.c


示例14: uart_init

int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
{
    if (uart != 0) {
        return UART_NODEV;
    }

    /* remember callback addresses and argument */
    uart_config.rx_cb = rx_cb;
    uart_config.arg = arg;

#ifdef CPU_FAM_NRF51
   /* power on the UART device */
    NRF_UART0->POWER = 1;
#endif
    /* reset configuration registers */
    NRF_UART0->CONFIG = 0;
    /* configure RX/TX pin modes */
    GPIO_BASE->DIRSET = (1 << UART_PIN_TX);
    GPIO_BASE->DIRCLR = (1 << UART_PIN_RX);
    /* configure UART pins to use */
    NRF_UART0->PSELTXD = UART_PIN_TX;
    NRF_UART0->PSELRXD = UART_PIN_RX;
    /* enable HW-flow control if defined */
#if UART_HWFLOWCTRL
    /* set pin mode for RTS and CTS pins */
    GPIO_BASE->DIRSET = (1 << UART_PIN_RTS);
    GPIO_BASE->DIRCLR = (1 << UART_PIN_CTS);
    /* configure RTS and CTS pins to use */
    NRF_UART0->PSELRTS = UART_PIN_RTS;
    NRF_UART0->PSELCTS = UART_PIN_CTS;
    NRF_UART0->CONFIG |= UART_CONFIG_HWFC_Msk;  /* enable HW flow control */
#else
    NRF_UART0->PSELRTS = 0xffffffff;            /* pin disconnected */
    NRF_UART0->PSELCTS = 0xffffffff;            /* pin disconnected */
#endif

    /* select baudrate */
    switch (baudrate) {
        case 1200:
            NRF_UART0->BAUDRATE = UART_BAUDRATE_BAUDRATE_Baud1200;
            break;
        case 2400:
            NRF_UART0->BAUDRATE = UART_BAUDRATE_BAUDRATE_Baud2400;
            break;
        case 4800:
            NRF_UART0->BAUDRATE = UART_BAUDRATE_BAUDRATE_Baud4800;
            break;
        case 9600:
            NRF_UART0->BAUDRATE = UART_BAUDRATE_BAUDRATE_Baud9600;
            break;
        case 14400:
            NRF_UART0->BAUDRATE = UART_BAUDRATE_BAUDRATE_Baud14400;
            break;
        case 19200:
            NRF_UART0->BAUDRATE = UART_BAUDRATE_BAUDRATE_Baud19200;
            break;
        case 28800:
            NRF_UART0->BAUDRATE = UART_BAUDRATE_BAUDRATE_Baud28800;
            break;
        case 38400:
            NRF_UART0->BAUDRATE = UART_BAUDRATE_BAUDRATE_Baud38400;
            break;
        case 57600:
            NRF_UART0->BAUDRATE = UART_BAUDRATE_BAUDRATE_Baud57600;
            break;
        case 76800:
            NRF_UART0->BAUDRATE = UART_BAUDRATE_BAUDRATE_Baud76800;
            break;
        case 115200:
            NRF_UART0->BAUDRATE = UART_BAUDRATE_BAUDRATE_Baud115200;
            break;
        case 230400:
            NRF_UART0->BAUDRATE = UART_BAUDRATE_BAUDRATE_Baud230400;
            break;
        case 250000:
            NRF_UART0->BAUDRATE = UART_BAUDRATE_BAUDRATE_Baud250000;
            break;
        case 460800:
            NRF_UART0->BAUDRATE = UART_BAUDRATE_BAUDRATE_Baud460800;
            break;
        case 921600:
            NRF_UART0->BAUDRATE = UART_BAUDRATE_BAUDRATE_Baud921600;
            break;
        default:
            return UART_NOBAUD;
    }

    /* enable the UART device */
    NRF_UART0->ENABLE = UART_ENABLE_ENABLE_Enabled;
    /* enable TX and RX */
    NRF_UART0->TASKS_STARTTX = 1;
    NRF_UART0->TASKS_STARTRX = 1;
    /* enable global and receiving interrupt */
    NVIC_EnableIRQ(UART_IRQN);
    NRF_UART0->INTENSET = UART_INTENSET_RXDRDY_Msk;
    return UART_OK;
}
开发者ID:kYc0o,项目名称:RIOT,代码行数:97,代码来源:uart.c


示例15: main

/**
 * \brief Application entry point for WDT example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint32_t wdt_mode, timeout_value;

	/* Initilize the system */
	sysclk_init();
	board_init();

	/* Configure pins of console UART, LED and push button on board. */
	configure_console();
	configure_led();
	configure_button();

	/* Output example information. */
	puts(STRING_HEADER);

	/* Systick configuration. */
	puts("Configure systick to get 1ms tick period.\r");
	if (SysTick_Config(sysclk_get_cpu_hz() / 1000)) {
		puts("-F- Systick configuration error\r");
	}

	/* Get timeout value. */
	timeout_value = wdt_get_timeout_value(WDT_PERIOD * 1000,
			BOARD_FREQ_SLCK_XTAL);
	if (timeout_value == WDT_INVALID_ARGUMENT) {
		while (1) {
			/* Invalid timeout value, error. */
		}
	}
	/* Configure WDT to trigger an interrupt (or reset). */
	wdt_mode = WDT_MR_WDFIEN |  /* Enable WDT fault interrupt. */
			WDT_MR_WDRPROC   |  /* WDT fault resets processor only. */
			WDT_MR_WDDBGHLT  |  /* WDT stops in debug state. */
			WDT_MR_WDIDLEHLT;   /* WDT stops in idle state. */
	/* Initialize WDT with the given parameters. */
	wdt_init(WDT, wdt_mode, timeout_value, timeout_value);
	printf("Enable watchdog with %d microseconds period\n\r",
			(int)wdt_get_us_timeout_period(WDT, BOARD_FREQ_SLCK_XTAL));

	/* Configure and enable WDT interrupt. */
	NVIC_DisableIRQ(WDT_IRQn);
	NVIC_ClearPendingIRQ(WDT_IRQn);
	NVIC_SetPriority(WDT_IRQn, 0);
	NVIC_EnableIRQ(WDT_IRQn);

	/* Initialize and enable push button (PIO) interrupt. */
	pio_handler_set_priority(PUSHBUTTON_PIO, PUSHBUTTON_IRQn, 0);
	pio_enable_interrupt(PUSHBUTTON_PIO, PUSHBUTTON_MASK);

	printf("Press %s to simulate a deadlock loop.\n\r", PUSHBUTTON_STRING);

	while (1) {

		if (g_b_systick_event == true) {
			g_b_systick_event = false;

			/* Toggle LED at the given period. */
			if ((g_ul_ms_ticks % BLINK_PERIOD) == 0) {
#if (SAM4E || SAM4N || SAM4C || SAMG)
				LED_Toggle(LED0);
#else
				LED_Toggle(LED0_GPIO);
#endif
			}

			/* Restart watchdog at the given period. */
			if ((g_ul_ms_ticks % WDT_RESTART_PERIOD) == 0) {
				wdt_restart(WDT);
			}
		}

		/* Simulate deadlock when button is pressed. */
		if (g_b_button_event == true) {
			puts("Program enters infinite loop for triggering watchdog interrupt.\r");
			while (1) {
			}
		}
	}
}
开发者ID:ThucVD2704,项目名称:femto-usb-blink-example,代码行数:85,代码来源:wdt_example.c


示例16: main

int
main (void)
{

  SystemCoreClockUpdate ();
  GPIOInit ();

  while (GPIOGetValue (BTN_PORT, BTN_PIN) == 0)
    ;

  POWER_ON;

  SSP_IOConfig (SSP_NUM); /* initialize SSP port, share pins with SPI1
   on port2(p2.0-3). */
  SSP_Init (SSP_NUM);
  UARTInit (115200);

  LED1_ON;

  TIMInit (0, 2 * SystemCoreClock);
  TIMInit (1, SystemCoreClock);
  TIMInit16 (1, SystemCoreClock);
  TIMInit16 (0, SystemCoreClock);
  enable_timer16 (0);

  // Initialize SYstick
  SysTick_Config ( SYSTICK_DELAY);

  MSP5701_init ();
  SST25_init ();

  //LED1_BLINK;

  // TODO: insert code here

  NVIC_ClearPendingIRQ (EINT0_IRQn);
  NVIC_ClearPendingIRQ (EINT1_IRQn);
  NVIC_EnableIRQ (EINT0_IRQn);
  NVIC_EnableIRQ (EINT1_IRQn);

  clearAllEvents();

  while (1)
    {

      if (checkEvent(BtnPressed))
	{
	  // Start measuring.
	  //GPIOSetValue(LED1_PORT, LED1_PIN, ~GPIOGetValue(LED1_PORT,LED1_PIN)&0x1);
	  clearEvent(BtnPressed);

	  if (measure == 1)
	    {
	      measure = 0;
	      live = 0;
	      /* Save data info */
	      storage_save_data_info (&actual_record);
	      meas_pointer = 0;
	      stop_systick ();
	    }
	  else
	    {
	      measure = 1;
	      meas_pointer = 0;
	      storage_init (&actual_record);
	      start_systick ();
	    }
	  clearEvent(BtnPressed);
	}
      if (checkEvent(PowerOff))
	{
	  // Turn off device.
	  storage_save_data_info (&actual_record);
	  meas_pointer = 0;
	  measure = 0;
	  LED1_OFF;
	  LED2_OFF;
	  UARTSend ((uint8_t*) "sleep\r\n", 7);
	  POWER_OFF
	  ;
	  while (1)
	    ;
	  clearEvent(PowerOff);

	}
      if (checkEvent(UART_data))
	{
	  clearEvent(UART_data);
	  uint8_t command = get_uart_char ();
	  switch (command)
	    {
	    case 'e':
	      stop_systick ();
	      SST25_erase (0, SIZE_FULL);
	      break;
	    case 'r':
	      measure = 0;
	      /* Save data info */
	      if (actual_record.rec_index != -1)
		{
//.........这里部分代码省略.........
开发者ID:krejzoljerzy,项目名称:SleepWatcher,代码行数:101,代码来源:main.c


示例17: main

/**
 * @brief	Main program body
 * @return	Does not return
 */
int main(void)
{
	uint32_t regVal;

	/* Generic Initialization */
	SystemCoreClockUpdate();
	Board_Init();

	/* Alarm/wake timer as chip wakeup source */
	Chip_SYSCTL_EnablePeriphWakeup(SYSCTL_WAKEUP_WKTINT);

	/* Enable and reset WKT clock */
	Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_WKT);
	Chip_SYSCTL_PeriphReset(RESET_WKT);

	/* Disable wakeup pad */
	Chip_PMU_ClearPowerDownControl(LPC_PMU, PMU_DPDCTRL_WAKEPAD | PMU_DPDCTRL_LPOSCDPDEN);

	/* Disable wakeup hysteresis by setting the bit (set to disable),
	   enable 10KHz oscillator for all power down modes including deep
	   power-down */
	Chip_PMU_SetPowerDownControl(LPC_PMU, PMU_DPDCTRL_WAKEUPPHYS | PMU_DPDCTRL_LPOSCEN |
								 PMU_DPDCTRL_LPOSCDPDEN);

	/* Enable WKT interrupt */
	NVIC_EnableIRQ(WKT_IRQn);

	/*
	 *	Note that deep power down causes a reset when it wakes up.
	 *	If the CPU was in deep power-down before the reset,
	 *	then PCON, DPDFLAG will be set.
	 *
	 *	This code clears DPDFLAG (by writing a one to it)
	 *	then sets the RED LED for about 500ms.
	 */
	if (LPC_PMU->PCON & PMU_PCON_DPDFLAG) {
		regVal = LPC_PMU->PCON;
		regVal |= PMU_PCON_DPDFLAG;
		LPC_PMU->PCON = regVal;
		Board_LED_Set(0, true);
		delay(0x100000);
	}

	/* Loop various tests */
	while (1) {
		/* You'll probably lose the debugger connection in the following
		   statements as the MCU goes into low power mode. */

		/* Wakeup test with 10KHz clock, 1s wakeup, and PMU sleep state */
		WakeupTest(WKT_CLKSRC_10KHZ, 1, PMU_MCU_SLEEP);

		/* Wakeup test with 10KHz clock, 1s wakeup, and PMU deep sleep state */
		WakeupTest(WKT_CLKSRC_10KHZ, 1, PMU_MCU_DEEP_SLEEP);

		/* Wakeup test with 10KHz clock, 1s wakeup, and PMU MCU power down state */
		WakeupTest(WKT_CLKSRC_10KHZ, 1, PMU_MCU_POWER_DOWN);

		/* Wakeup test with 10KHz clock, 1s wakeup, and PMU MCU deep power down state */
		WakeupTest(WKT_CLKSRC_10KHZ, 1, PMU_MCU_DEEP_PWRDOWN);
	}
}
开发者ID:Magicoe,项目名称:LPC820,代码行数:65,代码来源:main_wkt_example.c


示例18: UART0_init

void UART0_init(uint8_t nrf_tx_pin, uint8_t nrf_rx_pin, uint32_t baud_rate)
{
    if(UART0_State != UART0_NotStart)
        return;

    // Configurate TXD/RXD pin.
    NRF_GPIO->PIN_CNF[nrf_tx_pin] = ((GPIO_PIN_CNF_SENSE_Disabled<<GPIO_PIN_CNF_SENSE_Pos)   |
                                     (GPIO_PIN_CNF_DRIVE_S0S1<<GPIO_PIN_CNF_DRIVE_Pos)       |
                                     (GPIO_PIN_CNF_PULL_Disabled<<GPIO_PIN_CNF_PULL_Pos)     |
                                     (GPIO_PIN_CNF_INPUT_Disconnect<<GPIO_PIN_CNF_INPUT_Pos) |
                                     (GPIO_PIN_CNF_DIR_Output<<GPIO_PIN_CNF_DIR_Pos) );

    NRF_GPIO->PIN_CNF[nrf_rx_pin] = ((GPIO_PIN_CNF_SENSE_Disabled<<GPIO_PIN_CNF_SENSE_Pos)   |
                                     (GPIO_PIN_CNF_DRIVE_S0S1<<GPIO_PIN_CNF_DRIVE_Pos)       |
                                     (GPIO_PIN_CNF_PULL_Disabled<<GPIO_PIN_CNF_PULL_Pos)     |
                                     (GPIO_PIN_CNF_INPUT_Disconnect<<GPIO_PIN_CNF_INPUT_Pos) |
                                     (GPIO_PIN_CNF_DIR_Input<<GPIO_PIN_CNF_DIR_Pos) );

    NRF_UART0->PSELTXD = (uint32_t)nrf_tx_pin;
    NRF_UART0->PSELRXD = (uint32_t)nrf_rx_pin;
    NRF_UART0->PSELRTS = 0xFFFFFFFF;
    NRF_UART0->PSELCTS = 0xFFFFFFFF;

    uint32_t baud;
    switch(baud_rate)
    {
        case 1200: baud = UART_BAUDRATE_BAUDRATE_Baud1200; break;
        case 2400: baud = UART_BAUDRATE_BAUDRATE_Baud2400; break;
        case 4800: baud = UART_BAUDRATE_BAUDRATE_Baud4800; break;
        case 9600: baud = UART_BAUDRATE_BAUDRATE_Baud9600; break;
        case 14400: baud = UART_BAUDRATE_BAUDRATE_Baud14400; break;
        case 19200: baud = UART_BAUDRATE_BAUDRATE_Baud19200; break;
        case 28800: baud = UART_BAUDRATE_BAUDRATE_Baud28800; break;
        case 38400: baud = UART_BAUDRATE_BAUDRATE_Baud38400; break;
        case 57600: baud = UART_BAUDRATE_BAUDRATE_Baud57600; break;
        case 76800: baud = UART_BAUDRATE_BAUDRATE_Baud76800; break;
        case 115200: baud = UART_BAUDRATE_BAUDRATE_Baud115200; break;
        case 230400: baud = UART_BAUDRATE_BAUDRATE_Baud230400; break;
        case 250000: baud = UART_BAUDRATE_BAUDRATE_Baud250000; break;
        case 460800: baud = UART_BAUDRATE_BAUDRATE_Baud460800; break;
        case 921600: baud = UART_BAUDRATE_BAUDRATE_Baud921600; break;
        case 1000000: baud = UART_BAUDRATE_BAUDRATE_Baud1M; break;
        default: baud = UART_BAUDRATE_BAUDRATE_Baud115200;break;
    }
    NRF_UART0->BAUDRATE = (baud<<UART_BAUDRATE_BAUDRATE_Pos);
    NRF_UART0->CONFIG = ((UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos) | (UART_CONFIG_HWFC_Disabled << UART_CONFIG_HWFC_Pos));

    NRF_UART0->INTENCLR = 0xFFFFFFFF;
    NRF_UART0->INTENSET = (UART_INTENSET_RXDRDY_Enabled << UART_INTENSET_RXDRDY_Pos);

    NVIC_SetPriority(UART0_IRQn, 3);
    NVIC_ClearPendingIRQ(UART0_IRQn);
    NVIC_EnableIRQ(UART0_IRQn);

    NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos);

    NRF_UART0->EVENTS_RXDRDY    = 0;
    //NRF_UART0->EVENTS_TXDRDY    = 0;
    NRF_UART0->TASKS_STARTTX    = 1;
    NRF_UART0->TASKS_STARTRX    = 1;

    UART0_State = UART0_BeforeFirstTX;
}
开发者ID:zoujixing,项目名称:nRF52-Arduino,代码行数:63,代码来源:uart.c


示例19: SSP_Init

/*****************************************************************************
** Function name:		SSP_Init
**
** Descriptions:		SSP port initialization routine
**				
** parameters:			None
** Returned value:		None
** 
*****************************************************************************/
void SSP_Init( uint8_t portNum )
{
  uint8_t i, Dummy=Dummy;

  if ( portNum == 0 )
  {
  /* Set DSS data to 8-bit, Frame format SPI, CPOL = 0, CPHA = 0, and SCR is 15 */
	LPC_SSP0->CR0 = 0x000F;

  /* SSPCPSR clock prescale register, master mode, minimum divisor is 0x02 */
	LPC_SSP0->CPSR = 16;

  for ( i = 0; i < FIFOSIZE; i++ )
  {
	  Dummy = LPC_SSP0->DR;		/* clear the RxFIFO */
  }

  /* Enable the SSP Interrupt */
	NVIC_EnableIRQ(SSP0_IRQn);
	
  /* Device select as master, SSP Enabled */
#if LOOPBACK_MODE
	LPC_SSP0->CR1 = SSPCR1_LBM | SSPCR1_SSE;
#else
#if SSP_SLAVE
  /* Slave mode */
	if ( LPC_SSP0->CR1 & SSPCR1_SSE )
  {
	/* The slave bit can't be set until SSE bit is zero. */
	  LPC_SSP0->CR1 &= ~SSPCR1_SSE;
  }
	LPC_SSP0->CR1 = SSPCR1_MS;		/* Enable slave bit first */
	LPC_SSP0->CR1 |= SSPCR1_SSE;	/* Enable SSP */
#else
  /* Master mode */
	LPC_SSP0->CR1 = SSPCR1_SSE;
#endif
#endif
  /* Set SSPINMS registers to enable interrupts */
  /* enable all error related interrupts */
	LPC_SSP0->IMSC = SSPIMSC_RORIM | SSPIMSC_RTIM;
  }
  else
  {
	/* Set DSS data to 8-bit, Frame format SPI, CPOL = 0, CPHA = 0, and SCR is 15 */
	LPC_SSP1->CR0 = 0x0707;

	/* SSPCPSR clock prescale register, master mode, minimum divisor is 0x02 */
	LPC_SSP1->CPSR = 0x2;

	for ( i = 0; i < FIFOSIZE; i++ )
	{
	  Dummy = LPC_SSP1->DR;		/* clear the RxFIFO */
	}

	/* Enable the SSP Interrupt */
	NVIC_EnableIRQ(SSP1_IRQn);
	
	/* Device select as master, SSP Enabled */
#if LOOPBACK_MODE
	LPC_SSP1->CR1 = SSPCR1_LBM | SSPCR1_SSE;
#else
#if SSP_SLAVE
	/* Slave mode */
	if ( LPC_SSP1->CR1 & SSPCR1_SSE )
	{
	  /* The slave bit can't be set until SSE bit is zero. */
	  LPC_SSP1->CR1 &= ~SSPCR1_SSE;
	}
	LPC_SSP1->CR1 = SSPCR1_MS;		/* Enable slave bit first */
	LPC_SSP1->CR1 |= SSPCR1_SSE;	/* Enable SSP */
#else
	/* Master mode */
	LPC_SSP1->CR1 = SSPCR1_SSE;
#endif
#endif
	/* Set SSPINMS registers to enable interrupts */
	/* enable all error related interrupts */
	LPC_SSP1->IMSC = SSPIMSC_RORIM | SSPIMSC_RTIM;
  }
  return;
}
开发者ID:jacksonpugh,项目名称:womprats,代码行数:91,代码来源:ssp.c


示例20:


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ NVIC_EncodePriority函数代码示例发布时间:2022-05-30
下一篇:
C++ NVIC_DisableIRQ函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap