007 |
#include "Board_Driver.h" |
016 |
void USART1_Init( void ) |
018 |
GPIO_InitTypeDef USART1_GPIO; |
019 |
USART_InitTypeDef USART_InitStructure; |
020 |
NVIC_InitTypeDef NVIC_InitStructure; |
022 |
memset ( ( void *)&gCommCtrl, 0, sizeof (COMM_CTRL) ); |
024 |
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA |
025 |
|RCC_APB2Periph_AFIO ,ENABLE); |
029 |
USART1_GPIO.GPIO_Pin=(GPIO_Pin_9); |
030 |
USART1_GPIO.GPIO_Speed=GPIO_Speed_50MHz; |
031 |
USART1_GPIO.GPIO_Mode=GPIO_Mode_AF_PP; |
032 |
GPIO_Init(GPIOA, &USART1_GPIO); |
034 |
USART1_GPIO.GPIO_Pin=(GPIO_Pin_10); |
035 |
USART1_GPIO.GPIO_Mode=GPIO_Mode_IN_FLOATING; |
036 |
GPIO_Init(GPIOA, &USART1_GPIO); |
040 |
USART_InitStructure.USART_BaudRate = 115200; |
041 |
USART_InitStructure.USART_WordLength = USART_WordLength_8b; |
042 |
USART_InitStructure.USART_StopBits = USART_StopBits_1; |
043 |
USART_InitStructure.USART_Parity = USART_Parity_No; |
044 |
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; |
046 |
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; |
048 |
USART_Init(USART1, &USART_InitStructure); |
050 |
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); |
051 |
USART_Cmd(USART1, ENABLE); |
053 |
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); |
056 |
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; |
057 |
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; |
058 |
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; |
059 |
NVIC_Init(&NVIC_InitStructure); |
071 |
void USART1_IRQHandler( void ) |
076 |
if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) |
078 |
tmpChar= USART_ReceiveData(USART1); |
079 |
tmpIdx = gCommCtrl.rxHead; |
080 |
CommRxBuff[ tmpIdx ] = tmpChar; |
081 |
tmpIdx = (tmpIdx + 1) % COMM_RXBUFF_LEN; |
082 |
if ( gCommCtrl.rxTail != tmpIdx ) gCommCtrl.rxHead = tmpIdx; |
087 |
if (USART_GetITStatus(USART1, USART_IT_TXE) != RESET) |
089 |
tmpIdx = gCommCtrl.txTail; |
090 |
if ( tmpIdx == gCommCtrl.txHead ) |
092 |
USART_ITConfig(USART1, USART_IT_TXE, DISABLE); |
097 |
USART_SendData(USART1, CommTxBuff[ tmpIdx ]); |
098 |
gCommCtrl.txTail = (tmpIdx + 1) % COMM_TXBUFF_LEN; |
115 |
u8 CommPutch( u8 txChar ) |
119 |
tmpHead = (gCommCtrl.txHead + 1) % COMM_TXBUFF_LEN; |
120 |
if ( tmpHead == gCommCtrl.txTail ) return 0; |
121 |
CommTxBuff[ gCommCtrl.txHead ] = txChar; |
122 |
gCommCtrl.txHead = tmpHead; |
124 |
USART_ITConfig(USART1, USART_IT_TXE, ENABLE); |
140 |
if ( gCommCtrl.rxHead != gCommCtrl.rxTail ) return 1; |
160 |
rtnChar = CommRxBuff[ gCommCtrl.rxTail ]; |
161 |
gCommCtrl.rxTail = (gCommCtrl.rxTail + 1) % COMM_RXBUFF_LEN; |
175 |
void commSendStr( u8* pStr ) |
182 |
if ( txChar == 0 ) break ; |
183 |
while ( 0 == CommPutch( txChar ) ); |
|