註冊 登錄
Android 台灣中文網 返回首頁

wenhao61的個人空間 https://www.apk.tw/?929518 [收藏] [複製] [分享] [RSS]

日誌

[M3] UART Interrupt Backdoor....

已有 326 次閱讀2017-9-28 15:33 |個人分類:CM3| Interrupt

int main(void)
{
char sCmd[32];
char sArg[8][32];
    /* Init Test Status LED */ 
    TestStatusLedInit();
    
    /* Flash LED for test */
    FlashLED ( 1  );
    
    /* Enable GPIOA clock */
    RCC_APB2PeriphClock_Enable( RCC_APB2PERIPH_GPIOA  , ENABLE );
    
    /* Enable USART1 APB clock */
    RCC_APB2PeriphClock_Enable( RCC_APB2PERIPH_USART1  , ENABLE );
      
    /* USART1 Pins configuration **************************************************/
    {
        /* Configure the GPIO ports */
        GPIO_InitPara  GPIO_InitStructure;
       
        GPIO_InitStructure.GPIO_Pin     = GPIO_PIN_9 ;
        GPIO_InitStructure.GPIO_Mode    = GPIO_MODE_AF_PP;
        GPIO_InitStructure.GPIO_Speed   = GPIO_SPEED_50MHZ;
        GPIO_Init( GPIOA , &GPIO_InitStructure); 
        GPIO_InitStructure.GPIO_Pin     = GPIO_PIN_10;
        GPIO_InitStructure.GPIO_Mode    = GPIO_MODE_IN_FLOATING;;
        GPIO_Init( GPIOA , &GPIO_InitStructure); 
    }

    {
        USART_InitPara  USART_InitStructure;
        
        USART_DeInit( USART1 );        
        USART_InitStructure.USART_BRR                 = 115200;
        USART_InitStructure.USART_WL                  = USART_WL_8B;
        USART_InitStructure.USART_STBits              = USART_STBITS_1;
        USART_InitStructure.USART_Parity              = USART_PARITY_RESET;
        USART_InitStructure.USART_HardwareFlowControl = USART_HARDWAREFLOWCONTROL_NONE;
        USART_InitStructure.USART_RxorTx              = USART_RXORTX_RX | USART_RXORTX_TX;
        USART_Init(USART1, &USART_InitStructure);
    }

    /* USART enable */
    USART_Enable(USART1, ENABLE);

    /* Output a message on Hyperterminal using printf function */
    printf(" USART Printf Example: Please press the Key ");

{
    NVIC_InitPara NVIC_InitStructure;
    
    /* Enable the USARTx Interrupt */
    NVIC_InitStructure.NVIC_IRQ = USART1_IRQn;
    NVIC_InitStructure.NVIC_IRQPreemptPriority = 0;
    NVIC_InitStructure.NVIC_IRQSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQEnable = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
}
       /* Enable the USART1 Receive interrupt */
    USART_INT_Set( USART1, USART_INT_RBNE, ENABLE );
    /* Loop until the end of transmission */
    /* The software must wait until TC=1. The TC flag remains cleared during all data
    transfers and it is set by hardware at the last frame? end of transmission*/
    while ( USART_GetBitState( USART1 , USART_FLAG_TC  ) == RESET )
    {}

uart_cmd=0;
    while (1)
    {
if(uart_cmd==1){


路過

雞蛋

鮮花

握手

雷人

全部作者的其他最新日誌

評論 (0 個評論)

facelist

您需要登錄後才可以評論 登錄 | 註冊