Ярлыки

_GetPixelIndex (1) _SetPixelIndex (1) 3-phase (1) 800x480 (1) АЦП (1) генератор (1) синхронный усилитель (2) структура (1) учебный курс (1) шаговый двигатель (1) ШИМ (2) accert (1) AD7608 (1) AD8429 (1) ADC (5) amplifer (1) arccos (1) arcsin (1) arctang (2) arctg (3) ARM (2) arm_sqrt_q15 (2) assembler (6) ASSERT (1) atan (2) bit (1) Bitband (1) boot (3) bootlloader (1) BUTTON (1) C (5) C# (1) CAN (2) CC2530 (5) CMSIS (4) command (1) Cordic (1) Core746I (1) CubeMX (4) DBGMCU (2) debug (2) debug.ini (1) delegate (1) Digital Potentiometers (1) DigitalPOT (1) Discovery (1) DMA (9) DMA2D (1) DSP (1) DSP library (1) DWT (1) EFM32 (5) EmWin (9) EXTI (1) FATFS (1) FMC (2) FreeRTOS (2) gl868-dual cmux (1) GPIO (4) GUI (2) GUIBuilder (1) GUIDRV_CompactColor_16 (1) HAL (3) HappyGecko (1) Hard Fault (2) heap (1) I2C (1) ID (1) ILI9320 (1) ILI9325 (1) Initialisation (1) InitLTDC (1) Instrumentithion (1) Interrupt (4) ITR (1) JTAG (1) Keil (5) LCDConf (2) lock-in (1) LTCD (1) LTDC (3) main (1) memory (1) MINI_STM32 Revision 01 (1) nBoot0 (1) NVIC (1) OnePulse (2) OSAL (4) pack (1) phase (1) printf (3) Pulse (1) PWM (12) RCC (2) RCR (1) Register (1) RESET (2) RS232 (3) RSS (1) RTC (3) RTOS-RTX (1) RTT (1) RTX-RTOS (1) SDCard (1) SDRAM (6) Segger (2) SPI (3) sqrt (3) SSD1298 (1) SSD1963 (1) Standart Peripherial Library (3) STANDBAY (1) startup (1) STemWin (8) stepper motor (1) STlink (2) STM32 (17) STM32429ZI (1) STM32Cube (1) STM32DBG.IN (1) STM32F (28) STM32F0 (4) STM32F1 (13) STM32F4 (10) STM32F4 Discovery (1) STM32F407ZG (1) STM32F429 (2) STM32F746 (1) STOP (1) string (1) struct (1) SWD (1) SWD JTAG (1) Synhronization (1) system_stm32f4xx.c (1) SystemInit (1) SysTick (1) task (4) telit (1) TIM (27) typedef (1) UART (1) USART (9) viewer (2) WM_PAINT (1) Z-stack (5) ZigBee (5)

суббота, 19 марта 2016 г.

EFM32 Happy Gecko ARM Cortex M0+

UART API

for EFM32 Happy Gecko ARM Cortex M0+





#include "em_system.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "em_gpio.h"
#include "em_usart.h"
#define COM_PORT gpioPortC
#define TX_PIN   0
#define RX_PIN   1
const char test_string[] = "\n\EFM32 Happy Gecko!\n\r";
char rx_char;
int main () {
   
  uint8_t i;
  CHIP_Init();
   
  CMU_OscillatorEnable(cmuOsc_HFXO, truetrue);          // enable HF XTAL osc and wait for it to stabilize
  CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);        // select HF XTAL osc as system clock source (24MHz)
   
  CMU_ClockEnable(cmuClock_GPIO, true);                   // enable GPIO peripheral clock
  CMU_ClockEnable(cmuClock_USART1, true);                 // enable USART1 peripheral clock
   
  GPIO_PinModeSet(COM_PORT, TX_PIN, gpioModePushPull, 1); // set TX pin to push-pull output, initialize high (otherwise glitches can occur)
  GPIO_PinModeSet(COM_PORT, RX_PIN, gpioModeInput, 0);    // set RX pin as input (no filter)
   
  USART_InitAsync_TypeDef uartInit =
  {
    .enable = usartDisable,     // wait to enable transmitter and receiver
    .refFreq = 0,               // setting refFreq to 0 will invoke the CMU_ClockFreqGet() function and measure the HFPER clock
    .baudrate = 115200,         // desired baud rate
    .oversampling = usartOVS16, // set oversampling to x16
    .databits = usartDatabits8, // 8 data bits
    .parity = usartNoParity,    // no parity bits
    .stopbits = usartStopbits1, // 1 stop bit
    .mvdis = false,             // use majority voting
    .prsRxEnable = false,       // not using PRS input
    .prsRxCh = usartPrsRxCh0,   // doesn't matter what channel we select
  };
  USART_InitAsync(USART1, &uartInit);      // apply configuration to USART1
  USART1->ROUTE = USART_ROUTE_RXPEN | USART_ROUTE_TXPEN | _USART_ROUTE_LOCATION_LOC0; // clear buffers, enable transmitter and receiver pins
   
  USART_IntClear(USART1, _USART_IF_MASK);  // clear all USART interrupt flags
  NVIC_ClearPendingIRQ(USART1_RX_IRQn);    // clear pending RX interrupt flag in NVIC
  NVIC_ClearPendingIRQ(USART1_TX_IRQn);    // clear pending TX interrupt flag in NVIC
   
  USART_Enable(USART1, usartEnable);       // enable transmitter and receiver
   
  for(i=0; i<sizeof(test_string); i++) {
    while(!(USART1->STATUS & (1 << 6)));   // wait for TX buffer to empty
    USART1->TXDATA = test_string[i];       // send character
  }
     
  while(1) {
    if(USART1->STATUS & (1 << 7)) {        // if RX buffer contains valid data
      rx_char = USART1->RXDATA;            // store the data
    }
    if(rx_char) {                          // if we have a valid character
      while(!(USART1->STATUS & (1 << 6))); // wait for TX buffer to empty
      USART1->TXDATA = rx_char;            // echo received char
      rx_char = 0;                         // clear temp variable
    }
  }
}

Комментариев нет:

Отправить комментарий