Efm32-chip peripherals-spi rx interrupt of usart

Source: Internet
Author: User

Based on the basic polling, set Rx to interrupt reception.

Hardware environment: tg stk, transient connection of PD0 and PD1, Tx and Rx of usart1, without using the internal loopback function. Corresponds to the 4th and 6th ports of the tg stk 20 pin expansion port.

Software environment: in the main loop, data is continuously sent. In the Rx interrupt, the received data is determined. If it is a special word, the LED control pin is reversed.

The Code is as follows:

# Include <stdint. h>
# Include <stdbool. h>
# Include "efm32.h"
# Include "efm32_chip.h"
# Include "efm32_cmu.h"
# Include "efm32_gpio.h"
# Include "efm32_usart.h"

Void usart+rx_irqhandler (void)
{
If (USART_Rx (USART1) = 0x5)
{
GPIO_PinOutToggle (gpioPortD, 7 );
}
}

Void SPI_Initial (void)
{
CMU_ClockEnable (cmuClock_HFPER, true );
Cmu_clockenable (cmuclock_gpio, true );
Cmu_clockenable (cmuclock_usart1, true );

Usart_initsync_typedef spi_init = usart_initsync_default;
Spi_init.baudrate = 200000;

Usart_initsync (usart1, & spi_init );

Usart1-> IFC = _ usart_ifc_mask;
Nvic_clearpendingirq (usart1_rx_irqn );
Nvic_enableirq (usart1_rx_irqn );
Usart1-> ien = usart_ien_rxdatav;

Gpio_pinmodeset (gpioportd, 0, gpiomodepushpull, 1); // TX
Gpio_pinmodeset (gpioportd, 1, gpiomodeinput, 1); // RX
GPIO_PinModeSet (gpioPortD, 2, gpioModePushPull, 1); // clk
GPIO_PinModeSet (gpioPortD, 3, gpioModePushPull, 1); // cs



USART1-> ROUTE | = USART_ROUTE_CSPEN | USART_ROUTE_CLKPEN | USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC1;
}

/*************************************** ***********************************//**
* @ Brief Main function
**************************************** *************************************/
/*************************************** ***********************************//**
* @ Brief Main function
**************************************** *************************************/
Int main (void)
{
/* Chip errata */
Chip_init ();
Systemcoreclockupdate ();

Spi_initial ();

Cmu_clockenable (cmuclock_gpio, true );
Gpio_pinmodeset (gpioportd, 7, gpiomodepushpull, 0 );

Unsigned char ucdata = 0;
/* Infinite blink loop */
While (1)
{
Unsigned long uldelay = 100000;
While (uldelay --);
If (ucdata <10) ucdata ++;
Else ucdata = 0;
Usart_tx (usart1, ucdata );
}
}

The effect is as follows:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.