可以进啊,你再看看吧,这部分好像没问题吧。我这有个例程给你做参考。
int main(void)
{
/* System Clocks Configuration */
RCC_Configuration();
/* NVIC configuration */
NVIC_Configuration();
/* Configure the GPIO ports */
GPIO_Configuration();
/* USARTy and USARTz configuration ------------------------------------------------------*/
/* USARTy and USARTz configured as follow:
- BaudRate = 9600 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 115200;
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;
/* Configure USARTy */
USART_Init(USARTy, &USART_InitStructure);
/* Configure USARTz */
USART_Init(USARTz, &USART_InitStructure);
/* Enable USARTy Receive and Transmit interrupts */
USART_ITConfig(USARTy, USART_IT_RXNE, ENABLE);
USART_ITConfig(USARTy, USART_IT_TXE, ENABLE);
/* Enable USARTz Receive and Transmit interrupts */
USART_ITConfig(USARTz, USART_IT_RXNE, ENABLE);
USART_ITConfig(USARTz, USART_IT_TXE, ENABLE);
/* Enable the USARTy */
USART_Cmd(USARTy, ENABLE);
/* Enable the USARTz */
USART_Cmd(USARTz, ENABLE);
/* Wait until end of transmission from USARTy to USARTz */
while(RxCounter2 < RxBufferSize2)
{
}
/* Wait until end of transmission from USARTz to USARTy */
while(RxCounter1 < RxBufferSize1)
{
}
/* Check the received data with the send ones */
TransferStatus1 = Buffercmp(TxBuffer2, RxBuffer1, RxBufferSize1);
/* TransferStatus1 = PASSED, if the data transmitted from USARTz and
received by USARTy are the same */
/* TransferStatus1 = FAILED, if the data transmitted from USARTz and
received by USARTy are different */
TransferStatus2 = Buffercmp(TxBuffer1, RxBuffer2, RxBufferSize2);
/* TransferStatus2 = PASSED, if the data transmitted from USARTy and
received by USARTz are the same */
/* TransferStatus2 = FAILED, if the data transmitted from USARTy and
received by USARTz are different */
while (1)
{
}
}
/**
* @brief Configures the different system clocks.
* @param None
* @retval None
*/
void RCC_Configuration(void)
{
/* Setup the microcontroller system. Initialize the Embedded Flash Interface,
initialize the PLL and update the SystemFrequency variable. */
SystemInit();
/* Enable GPIO clock */
RCC_APB2PeriphClockCmd(USARTy_GPIO_CLK | USARTz_GPIO_CLK | RCC_APB2Periph_AFIO, ENABLE);
#ifndef USE_STM3210C_EVAL
/* Enable USARTy Clock */
RCC_APB2PeriphClockCmd(USARTy_CLK, ENABLE);
#else
/* Enable USARTy Clock */
RCC_APB1PeriphClockCmd(USARTy_CLK, ENABLE);
#endif
/* Enable USARTz Clock */
RCC_APB1PeriphClockCmd(USARTz_CLK, ENABLE);
}
/**
* @brief Configures the different GPIO ports.
* @param None
* @retval None
*/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
#ifdef USE_STM3210C_EVAL
/* Enable the USART3 Pins Software Remapping */
GPIO_PinRemapConfig(GPIO_PartialRemap_USART3, ENABLE);
/* Enable the USART2 Pins Software Remapping */
GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
#elif defined USE_STM3210B_EVAL
/* Enable the USART2 Pins Software Remapping */
GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
#endif
/* Configure USARTy Rx as input floating */
GPIO_InitStructure.GPIO_Pin = USARTy_RxPin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(USARTy_GPIO, &GPIO_InitStructure);
/* Configure USARTz Rx as input floating */
GPIO_InitStructure.GPIO_Pin = USARTz_RxPin;
GPIO_Init(USARTz_GPIO, &GPIO_InitStructure);
/* Configure USARTy Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = USARTy_TxPin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(USARTy_GPIO, &GPIO_InitStructure);
/* Configure USARTz Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = USARTz_TxPin;
GPIO_Init(USARTz_GPIO, &GPIO_InitStructure);
}
/**
* @brief Configures the nested vectored interrupt controller.
* @param None
* @retval None
*/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the NVIC Preemption Priority Bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
/* Enable the USARTy Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USARTy_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable the USARTz Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USARTz_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
} |