【问题标题】:EFM32 Giant Gecko, Interrupt procedure not workingEFM32 Giant Gecko,中断程序不起作用
【发布时间】:2015-01-26 11:34:59
【问题描述】:

我正在使用 EFM32 Giant Gecko 3700 入门套件进行基本的 UART 回显。 当我在我的 main 函数中的 while(1) 循环中将 RX 回显到 TX 时,它可以工作。但是,当我想使用中断功能时,它不再起作用。检查寄存器表明我的数据被正确读取,只是没有发回。

我的代码:

#include "efm32gg990f1024.h"
#include "em_chip.h"    // required for CHIP_Init() function
#include <string.h>

#define COM_PORT 3 // gpioPortD (USART location #1: PD0 and PD1)
#define UART_TX_pin 0

char rx_char = 0;                              // Temp variable for storing received characters

int main() {
  CHIP_Init();                                   // This function addresses some chip errata and should be called at the start of every EFM32 application (need em_system.c)
  uint8_t i;
  char test_string[] = "\n\rHello World!\n\r";


  CMU->CTRL |= (1 << 14);                         // Set HF clock divider to /2 to keep core frequency <32MHz
  CMU->OSCENCMD |= 0x4;                           // Enable XTAL Oscillator
  while(! (CMU->STATUS & 0x8) );                  // Wait for XTAL osc to stabilize
  CMU->CMD = 0x2;                                 // Select HF XTAL osc as system clock source. 48MHz XTAL, but we divided the system clock by 2, therefore our HF clock should be 24MHz

  CMU->HFPERCLKEN0 = (1 << 13) | (1 << 1);        // Enable GPIO, and USART1 peripheral clocks

  GPIO->P[COM_PORT].MODEL = (1 << 4) | (4 << 0);  // Configure PD0 as digital output and PD1 as input
  GPIO->P[COM_PORT].DOUTSET = (1 << UART_TX_pin); // Initialize PD0 high since UART TX idles high (otherwise glitches can occur)

  // Use default value for USART1->CTRL: asynch mode, x16 OVS, lsb first, CLK idle low
  // Default frame options: 8-none-1-none
  USART1->CLKDIV = (48  << 6);                               // 48  will give 115200 baud rate (using 16-bit oversampling with 24MHz peripheral clock)
  USART1->CMD = (1 << 11) | (1 << 10) | (1 << 2) | (1 << 0); // Clear RX/TX buffers and shif regs, Enable Transmitter and Receiver
  USART1->IFC = 0x1FF9;                                      // clear all USART interrupt flags
  USART1->ROUTE = 0x103;                                     // Enable TX and RX pins, use location #1 (UART TX and RX located at PD0 and PD1, see EFM32GG990 datasheet for details)

  // Print test string
  for(i=0; i<strlen(test_string); i++) {
    while( !(USART1->STATUS & (1 << 6)) ); // wait for TX buffer to empty
    USART1->TXDATA = test_string[i];       // print each character of the test string
  }

  while(1) {
// what used to be in main loop
        /*
        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
                      if(USART1->STATUS & (1 << 6)) { // check if TX buffer is empty
                        USART1->TXDATA = rx_char;     // echo received char
                        rx_char = 0;                  // reset temp variable
                      }
                    }
        */
  }
}

void USART1_RX_IRQHandler(void)
{
    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
                      if(USART1->STATUS & (1 << 6)) { // check if TX buffer is empty
                        USART1->TXDATA = rx_char;     // echo received char
                        rx_char = 0;                  // reset temp variable
                      }
                    }


}

【问题讨论】:

  • 我没有看到你在哪里设置了中断控制器或者用'USART1_RX_IRQHandler'的地址加载了IRQ向量?
  • 您在 Cortex M3 上两者都不做。

标签: c interrupt uart gecko


【解决方案1】:

您忘记在 NVIC 和 USART 中启用中断向量。

USART1->IEN = USART_IEN_RXDATAV;
NVIC_EnableIRQ(USART1_RX_IRQn);

【讨论】:

    猜你喜欢
    • 2012-03-03
    • 2017-12-07
    • 2019-08-02
    • 1970-01-01
    • 2015-09-03
    • 2021-11-06
    • 2019-11-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多