STM32F10x 學習筆記6(USART實現(xiàn)串口通訊 2)
另外,Cortex-M3內核中還有個NVIC,可以控制這里的中斷信號是否觸發(fā)中斷處理函數(shù)的執(zhí)行,還有這些外部中斷的級別。關于NVIC可以參考《ARMCortexM3權威指南》,里面講解的非常詳細。
簡單的說,為了開啟中斷,我們需要如下的代碼:
- NVIC_InitTypeDefNVIC_InitStructure;
- NVIC_InitStructure.NVIC_IRQChannel=USART1_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
- NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);//開啟接收中斷
- USART_ITConfig(USART1,USART_IT_TXE,ENABLE);//開啟發(fā)送中斷
這里多說一句,串口的發(fā)送中斷有兩個,分別是:
- l發(fā)送數(shù)據(jù)寄存器空中斷(TXE)
- l發(fā)送完成中斷(TC)
一般來說我們會使用發(fā)送數(shù)據(jù)寄存器空中斷,用這個中斷發(fā)送的效率會高一些。
中斷處理函數(shù)的框架如下,如果檢測到錯誤就清除錯誤,收到數(shù)了就處理。發(fā)完當前數(shù)據(jù)了就發(fā)下一個。
- voidUSART1_IRQHandler(void)
- {
- unsignedintdata;
- if(USART1->SR&0x0F)
- {
- //Seeifwehavesomekindoferror,Clearinterrupt
- data=USART1->DR;
- }
- elseif(USART1->SR&USART_FLAG_RXNE)//ReceiveDataRegFullFlag
- {
- data=USART1->DR;
- //對收到的數(shù)據(jù)進行處理,或者干些其他的事
- }
- elseif(USART1->SR&USART_FLAG_TXE)
- {
- {//可以發(fā)送數(shù)據(jù)了,如果沒有數(shù)據(jù)需要發(fā)送,就在這里關閉發(fā)送中斷
- USART1->DR=something;//Yes,Sendcharacter
- }
- }
- }
下面給一個利用環(huán)形緩沖區(qū)的串口驅動程序。
- #ifndef_COM_BUFFERED_H_
- #define_COM_BUFFERED_H_
- #defineCOM10
- #defineCOM21
- #defineCOM_RX_BUF_SIZE64/*NumberofcharactersinRxringbuffer*/
- #defineCOM_TX_BUF_SIZE64/*NumberofcharactersinTxringbuffer*/
- #defineCOM_NO_ERR0/*Functioncallwassuccessful*/
- #defineCOM_BAD_CH1/*Invalidcommunicationsportchannel*/
- #defineCOM_RX_EMPTY2/*Rxbufferisempty,nocharacteravailable*/
- #defineCOM_TX_FULL3/*Txbufferisfull,couldnotdepositcharacter*/
- #defineCOM_TX_EMPTY4/*IftheTxbufferisempty.*/
- /************************************************************
- *function:COMGetCharB
- *parameter:charport,portcanbeCOM1/COM2
- *parameter:char*errisapointertowhereanerrorcodewillbeplaced:
- **errissettoCOM_NO_ERRifacharacterisavailable
- **errissettoCOM_RX_EMPTYiftheRxbufferisempty
- **errissettoCOM_BAD_CHifyouhavespecifiedaninvalidchannel
- *return:char
- *usage:Thisfunctioniscalledbyyourapplicationtoobtainacharacterfromthecommunications
- *channel.
- *changelog:
- *************************************************************/
- unsignedcharCOMGetCharB(unsignedcharch,unsignedchar*err);
- /************************************************************
- *function:COMPutCharB
- *parameter:charport,portcanbeCOM1/COM2
- *return:COMM_NO_ERRifthefunctionwassuccessful(thebufferwasnotfull)
- *COMM_TX_FULLifthebufferwasfull
- *COMM_BAD_CHifyouhavespecifiedanincorrectchannel
- *usage:Thisfunctioniscalledbyyourapplicationtosendacharacteronthecommunications
- *channel.ThecharactertosendisfirstinsertedintotheTxbufferandwillbesentby
- *theTxISR.Ifthisisthefirstcharacterplacedintothebuffer,theTxISRwillbe
- *enabled.IftheTxbufferisfull,thecharacterwillnotbesent(i.e.itwillbelost)
- *changelog:
- *************************************************************/
- unsignedcharCOMPutCharB(unsignedcharport,unsignedcharc);
- /************************************************************
- *function:COMBufferInit
- *parameter:
- *return:
- *usage:Thisfunctioniscalledbyyourapplicationtoinitializethecommunicationsmodule.You
- *mustcallthisfunctionbeforecallinganyotherfunctions.
- *changelog:
- *************************************************************/
- voidCOMBufferInit(void);
- /************************************************************
- *function:COMBufferIsEmpty
- *parameter:charport,portcanbeCOM1/COM2
- *return:char
- *usage:Thisfunctioniscalledbyyourapplicationtosee
- *ifanycharacterisavailablefromthecommunicationschannel.
- *Ifatleastonecharacterisavailable,thefunctionreturns
- *FALSE(0)otherwise,thefunctionreturnsTRUE(1).
- *changelog:
- *************************************************************/
- unsignedcharCOMBufferIsEmpty(unsignedcharport);
- /************************************************************
- *function:COMBufferIsFull
- *parameter:charport,portcanbeCOM1/COM2
- *return:char
- *usage:Thisfunctioniscalledbyyourapplicationtoseeifanymorecharacterscanbeplaced
- *intheTxbuffer.Inotherwords,thisfunctionchecktoseeiftheTxbufferisfull.
- *Ifthebufferisfull,thefunctionreturnsTRUEotherwise,thefunctionreturnsFALSE.
- *changelog:
- *************************************************************/
- unsignedcharCOMBufferIsFull(unsignedcharport);
- #endif
- /*
- *file:com_buffered.c
- *author:LiYuan
- *platform:STM32F107
- *date:2013-5-5
- *version:0.0.1
- *description:UARTRingBuffer
- **/
- #include"stm32f10x_usart.h"
- #include"com_buffered.h"
- #defineOS_ENTER_CRITICAL()__set_PRIMASK(1)
- #defineOS_EXIT_CRITICAL()__set_PRIMASK(0)
- /**
- *EnablesTransmiterinterrupt.
- **/
- staticvoidCOMEnableTxInt(unsignedcharport)
- {
- staticUSART_TypeDef*map[2]={USART1,USART2};
- USART_ITConfig(map[port],USART_IT_TXE,ENABLE);
- }
- /*
- *********************************************************************************************************
- *DATATYPES
- *********************************************************************************************************
- */
- typedefstruct{
- shortRingBufRxCtr;/*NumberofcharactersintheRxringbuffer*/
- unsignedchar*RingBufRxInPtr;/*Pointertowherenextcharacterwillbeinserted*/
- unsignedchar*RingBufRxOutPtr;/*Pointerfromwherenextcharacterwillbeextracted*/
- unsignedcharRingBufRx[COM_RX_BUF_SIZE];/*Ringbuffercharacterstorage(Rx)*/
- shortRingBufTxCtr;/*NumberofcharactersintheTxringbuffer*/
- unsignedchar*RingBufTxInPtr;/*Pointertowherenextcharacterwillbeinserted*/
- unsignedchar*RingBufTxOutPtr;/*Pointerfromwherenextcharacterwillbeextracted*/
- unsignedcharRingBufTx[COM_TX_BUF_SIZE];/*Ringbuffercharacterstorage(Tx)*/
- }COM_RING_BUF;
- /*
- *********************************************************************************************************
- *GLOBALVARIABLES
- *********************************************************************************************************
- */
- COM_RING_BUFCOM1Buf;
- COM_RING_BUFCOM2Buf;
- /************************************************************
- *function:COMGetCharB
- *parameter:charport,portcanbeCOM1/COM2
- *parameter:char*errisapointertowhereanerrorcodewillbeplaced:
- **errissettoCOM_NO_ERRifacharacterisavailable
- **errissettoCOM_RX_EMPTYiftheRxbufferisempty
- **errissettoCOM_BAD_CHifyouhavespecifiedaninvalidchannel
- *return:char
- *usage:Thisfunctioniscalledbyyourapplicationtoobtainacharacterfromthecommunications
- *channel.
- *changelog:
- *************************************************************/
- unsignedcharCOMGetCharB(unsignedcharport,unsignedchar*err)
- {
- //unsignedcharcpu_sr;
- unsignedcharc;
- COM_RING_BUF*pbuf;
- switch(port)
- {/*Obtainpointertocommunicationschannel*/
- caseCOM1:
- pbuf=&COM1Buf;
- break;
- caseCOM2:
- pbuf=&COM2Buf;
- break;
- default:
- *err=COM_BAD_CH;
- return(0);
- }
- OS_ENTER_CRITICAL();
- if(pbuf->RingBufRxCtr>0)/*Seeifbufferisempty*/
- {
- pbuf->RingBufRxCtr--;/*No,decrementcharactercount*/
- c=*pbuf->RingBufRxOutPtr++;/*Getcharacterfrombuffer*/
- if(pbuf->RingBufRxOutPtr==&pbuf->RingBufRx[COM_RX_BUF_SIZE])
- {
- pbuf->RingBufRxOutPtr=&pbuf->RingBufRx[0];/*WrapOUTpointer*/
- }
- OS_EXIT_CRITICAL();
- *err=COM_NO_ERR;
- return(c);
- }else{
- OS_EXIT_CRITICAL();
- *err=COM_RX_EMPTY;
- c=0;/*Bufferisempty,return0*/
- return(c);
- }
- }
- /************************************************************
- *function:COMPutCharB
- *parameter:charport,portcanbeCOM1/COM2
- *return:COMM_NO_ERRifthefunctionwassuccessful(thebufferwasnotfull)
- *COMM_TX_FULLifthebufferwasfull
- *COMM_BAD_CHifyouhavespecifiedanincorrectchannel
- *usage:Thisfunctioniscalledbyyourapplicationtosendacharacteronthecommunications
- *channel.ThecharactertosendisfirstinsertedintotheTxbufferandwillbesentby
- *theTxISR.Ifthisisthefirstcharacterplacedintothebuffer,theTxISRwillbe
- *enabled.IftheTxbufferisfull,thecharacterwillnotbesent(i.e.itwillbelost)
- *changelog:
- *1.firstimplimentedbyliyuan2010.11.5
- *************************************************************/
- unsignedcharCOMPutCharB(unsignedcharport,unsignedcharc)
- {
- //unsignedcharcpu_sr;
- COM_RING_BUF*pbuf;
- switch(port)
- {/*Obtainpointertocommunicationschannel*/
- caseCOM1:
- pbuf=&COM1Buf;
- break;
- caseCOM2:
- pbuf=&COM2Buf;
- break;
- default:
- return(COM_BAD_CH);
- }
- OS_ENTER_CRITICAL();
- if(pbuf->RingBufTxCtr
- pbuf->RingBufTxCtr++;/*No,incrementcharactercount*/
- *pbuf->RingBufTxInPtr++=c;/*Putcharacterintobuffer*/
- if(pbuf->RingBufTxInPtr==&pbuf->RingBufTx[COM_TX_BUF_SIZE]){/*WrapINpointer*/
- pbuf->RingBufTxInPtr=&pbuf->RingBufTx[0];
- }
- if(pbuf->RingBufTxCtr==1){/*Seeifthisisthefirstcharacter*/
- COMEnableTxInt(port);/*Yes,EnableTxinterrupts*/
- OS_EXIT_CRITICAL();
- }else{
- OS_EXIT_CRITICAL();
- }
- return(COM_NO_ERR);
- }else{
- OS_EXIT_CRITICAL();
- return(COM_TX_FULL);
- }
- }
- /************************************************************
- *function:COMBufferInit
- *parameter:
- *return:
- *usage:Thisfunctioniscalledbyyourapplicationtoinitializethecommunicationsmodule.You
- *mustcallthisfunctionbeforecallinganyotherfunctions.
- *changelog:
- *************************************************************/
- voidCOMBufferInit(void)
- {
- COM_RING_BUF*pbuf;
- pbuf=&COM1Buf;/*InitializetheringbufferforCOM0*/
- pbuf->RingBufRxCtr=0;
- pbuf->RingBufRxInPtr=&pbuf->RingBufRx[0];
- pbuf->RingBufRxOutPtr=&pbuf->RingBufRx[0];
- pbuf->RingBufTxCtr=0;
- pbuf->RingBufTxInPtr=&pbuf->RingBufTx[0];
- pbuf->RingBufTxOutPtr=&pbuf->RingBufTx[0];
- pbuf=&COM2Buf;/*InitializetheringbufferforCOM1*/
- pbuf->RingBufRxCtr=0;
- pbuf->RingBufRxInPtr=&pbuf->RingBufRx[0];
- pbuf->RingBufRxOutPtr=&pbuf->RingBufRx[0];
- pbuf->RingBufTxCtr=0;
- pbuf->RingBufTxInPtr=&pbuf->RingBufTx[0];
- pbuf->RingBufTxOutPtr=&pbuf->RingBufTx[0];
- }
- /************************************************************
- *function:COMBufferIsEmpty
- *parameter:charport,portcanbeCOM1/COM2
- *return:char
- *usage:Thisfunctioniscalledbyyourapplicationtosee
- *ifanycharacterisavailablefromthecommunicationschannel.
- *Ifatleastonecharacterisavailable,thefunctionreturns
- *FALSE(0)otherwise,thefunctionreturnsTRUE(1).
- *changelog:
- *************************************************************/
- unsignedcharCOMBufferIsEmpty(unsignedcharport)
- {
- //unsignedcharcpu_sr;
- unsignedcharempty;
- COM_RING_BUF*pbuf;
- switch(port)
- {/*Obtainpointertocommunicationschannel*/
- caseCOM1:
- pbuf=&COM1Buf;
- break;
- caseCOM2:
- pbuf=&COM2Buf;
- break;
- default:
- return(1);
- }
- OS_ENTER_CRITICAL();
- if(pbuf->RingBufRxCtr>0)
- {/*Seeifbufferisempty*/
- empty=0;/*BufferisNOTempty*/
- }
- else
- {
- empty=1;/*Bufferisempty*/
- }
- OS_EXIT_CRITICAL();
- return(empty);
- }
- /************************************************************
- *function:COMBufferIsFull
- *parameter:charport,portcanbeCOM1/COM2
- *return:char
- *usage:Thisfunctioniscalledbyyourapplicationtoseeifanymorecharacterscanbeplaced
- *intheTxbuffer.Inotherwords,thisfunctionchecktoseeiftheTxbufferisfull.
- *Ifthebufferisfull,thefunctionreturnsTRUEotherwise,thefunctionreturnsFALSE.
- *changelog:
- *************************************************************/
- unsignedcharCOMBufferIsFull(unsignedcharport)
- {
- //unsignedcharcpu_sr;
- charfull;
- COM_RING_BUF*pbuf;
- switch(port)
- {/*Obtainpointertocommunicationschannel*/
- caseCOM1:
- pbuf=&COM1Buf;
- break;
- caseCOM2:
- pbuf=&COM2Buf;
- break;
- default:
- return(1);
- }
- OS_ENTER_CRITICAL();
- if(pbuf->RingBufTxCtr
- full=0;/*BufferisNOTfull*/
- }else{
- full=1;/*Bufferisfull*/
- }
- OS_EXIT_CRITICAL();
- return(full);
- }
- //ThisfunctioniscalledbytheRxISRtoinsertacharacterintothereceiveringbuffer.
- staticvoidCOMPutRxChar(unsignedcharport,unsignedcharc)
- {
- COM_RING_BUF*pbuf;
- switch(port)
- {/*Obtainpointertocommunicationschannel*/
- caseCOM1:
- pbuf=&COM1Buf;
- break;
- caseCOM2:
- pbuf=&COM2Buf;
- break;
- default:
- return;
- }
- if(pbuf->RingBufRxCtr
- pbuf->RingBufRxCtr++;/*No,incrementcharactercount*/
- *pbuf->RingBufRxInPtr++=c;/*Putcharacterintobuffer*/
- if(pbuf->RingBufRxInPtr==&pbuf->RingBufRx[COM_RX_BUF_SIZE]){/*WrapINpointer*/
- pbuf->RingBufRxInPtr=&pbuf->RingBufRx[0];
- }
- }
- }
- //ThisfunctioniscalledbytheTxISRtoextractthenextcharacterfromtheTxbuffer.
- //ThefunctionreturnsFALSEifthebufferisemptyafterthecharacterisextractedfrom
- //thebuffer.ThisisdonetosignaltheTxISRtodisableinterruptsbecausethisisthe
- //lastcharactertosend.
- staticunsignedcharCOMGetTxChar(unsignedcharport,unsignedchar*err)
- {
- unsignedcharc;
- COM_RING_BUF*pbuf;
- switch(port)
- {/*Obtainpointertocommunicationschannel*/
- caseCOM1:
- pbuf=&COM1Buf;
- break;
- caseCOM2:
- pbuf=&COM2Buf;
- break;
- default:
- *err=COM_BAD_CH;
- return(0);
- }
- if(pbuf->RingBufTxCtr>0){/*Seeifbufferisempty*/
- pbuf->RingBufTxCtr--;/*No,decrementcharactercount*/
- c=*pbuf->RingBufTxOutPtr++;/*Getcharacterfrombuffer*/
- if(pbuf->RingBufTxOutPtr==&pbuf->RingBufTx[COM_TX_BUF_SIZE])
- {
- pbuf->RingBufTxOutPtr=&pbuf->RingBufTx[0];/*WrapOUTpointer*/
- }
- *err=COM_NO_ERR;
- return(c);/*Charactersarestillavailable*/
- }else{
- *err=COM_TX_EMPTY;
- return(0);/*Bufferisempty*/
- }
- }
- voidUSART1_IRQHandler(void)
- {
- unsignedintdata;
- unsignedcharerr;
- if(USART1->SR&0x0F)
- {
- //Seeifwehavesomekindoferror
- //Clearinterrupt(donothingaboutit!)
- data=USART1->DR;
- }
- elseif(USART1->SR&USART_FLAG_RXNE)//ReceiveDataRegFullFlag
- {
- data=USART1->DR;
- COMPutRxChar(COM1,data);//Insertreceivedcharacterintobuffer
- }
- elseif(USART1->SR&USART_FLAG_TXE)
- {
- data=COMGetTxChar(COM1,&err);//Getnextcharactertosend.
- if(err==COM_TX_EMPTY)
- {//Dowehaveanymorecharacterstosend?
- //No,DisableTxinterrupts
- //USART_ITConfig(USART1,USART_IT_TXE|USART_IT_TC,ENABLE);
- USART1->CR1&=~USART_FLAG_TXE|USART_FLAG_TC;
- }
- else
- {
- USART1->DR=data;//Yes,Sendcharacter
- }
- }
- }
- voidUSART2_IRQHandler(void)
- {
- unsignedintdata;
- unsignedcharerr;
- if(USART2->SR&0x0F)
- {
- //Seeifwehavesomekindoferror
- //Clearinterrupt(donothingaboutit!)
- data=USART2->DR;
- }
- elseif(USART2->SR&USART_FLAG_RXNE)//ReceiveDataRegFullFlag
- {
- data=USART2->DR;
- COMPutRxChar(COM2,data);//Insertreceivedcharacterintobuffer
- }
- elseif(USART2->SR&USART_FLAG_TXE)
- {
- data=COMGetTxChar(COM2,&err);//Getnextcharactertosend.
- if(err==COM_TX_EMPTY)
- {//Dowehaveanymorecharacterstosend?
- //No,DisableTxinterrupts
- //USART_ITConfig(USART2,USART_IT_TXE|USART_IT_TC,ENABLE);
- USART2->CR1&=~USART_FLAG_TXE|USART_FLAG_TC;
- }
- else
- {
- USART2->DR=data;//Yes,Sendcharacter
- }
- }
- }
下面給個例子主程序,來演示如何使用上面的串口驅動代碼。
- #include"misc.h"
- #include"stm32f10x.h"
- #include"com_buffered.h"
- voidUART_PutStrB(unsignedcharport,uint8_t*str)
- {
- while(0!=*str)
- {
- COMPutCharB(port,*str);
- str++;
- }
- }
- voidUSART1_Init(void)
- {
- GPIO_InitTypeDefGPIO_InitStructure;
- USART_InitTypeDefUSART_InitStructure;
- NVIC_InitTypeDefNVIC_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_USART1,ENABLE);
- /*ConfigureUSARTTxasalternatefunctionpush-pull*/
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_Init(GPIOA,&GPIO_InitStructure);
- /*ConfigureUSARTRxasinputfloating*/
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;
- GPIO_Init(GPIOA,&GPIO_InitStructure);
- USART_InitStructure.USART_BaudRate=9600;
- USART_InitStructure.USART_WordLength=USART_WordLength_8b;
- USART_InitStructure.USART_StopBits=USART_StopBits_1;
- USART_InitStructure.USART_Parity=USART_Parity_No;
- USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
- USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
- USART_Init(USART1,&USART_InitStructure);
- USART_Cmd(USART1,ENABLE);
- NVIC_InitStructure.NVIC_IRQChannel=USART1_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
- NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
- voidUSART2_Init(void)
- {
- GPIO_InitTypeDefGPIO_InitStructure;
- USART_InitTypeDefUSART_InitStructure;
- NVIC_InitTypeDefNVIC_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO,ENABLE);
- /*ConfigureUSARTTxasalternatefunctionpush-pull*/
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5;
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_Init(GPIOD,&GPIO_InitStructure);
- /*ConfigureUSARTRxasinputfloating*/
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6;
- GPIO_Init(GPIOD,&GPIO_InitStructure);
- GPIO_PinRemapConfig(GPIO_Remap_USART2,ENABLE);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
- USART_InitStructure.USART_BaudRate=9600;
- USART_InitStructure.USART_WordLength=USART_WordLength_8b;
- USART_InitStructure.USART_StopBits=USART_StopBits_1;
- USART_InitStructure.USART_Parity=USART_Parity_No;
- USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
- USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
- USART_Init(USART2,&USART_InitStructure);
- USART_Cmd(USART2,ENABLE);
- NVIC_InitStructure.NVIC_IRQChannel=USART2_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
- NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
- intmain(void)
- {
- unsignedcharc;
- unsignedcharerr;
- USART1_Init();
- USART2_Init();
- COMBufferInit();
- USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
- USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
- UART_PutStrB(COM1,"HelloWorld!n");
- for(;;)
- {
- c=COMGetCharB(COM1,&err);
- if(err==COM_NO_ERR)
- {
- COMPutCharB(COM1,c);
- }
- }
- }
評論