初始化代码和发送,各位大神请指教
void UART_Transmit(uint16_t *pData, uint16_t Size)
{
uint16_t TxXferCount;
if((pData == NULL ) || (Size == 0))
{
return;
}
TxXferCount = Size;
while(TxXferCount > 0)
{
while (0 == (USART1->SR & USART_SR_TXE))
{
}
USART1->DR = ((*pData) & (uint16_t)0x01FF);
pData++;
TxXferCount--;
while (0 == (USART1->SR & USART_SR_TC))
{
}
}
}
void uart_init(void)
{
RCC->AHB1ENR |= 0x01;
GPIOA->MODER = (GPIOG->MODER & ~(GPIO_MODER_MODER9 | GPIO_MODER_MODER10)) | GPIO_MODER_MODER9_1 | GPIO_MODER_MODER10_1;
GPIOA->OTYPER = GPIOG->OTYPER & ~(GPIO_OTYPER_OT_9 | GPIO_OTYPER_OT_10);
GPIOA->AFR[1] = (GPIOA->AFR[0] & ~0xff0) | 0x770;
GPIOA->PUPDR |= 0x140000;
RCC->APB2ENR |= 0x10;//uart1
SystemCoreClockUpdate();
USART1->BRR = SystemCoreClock / 9600;
USART1->CR1 = 0;
USART1->CR1 = USART_CR1_RE | USART_CR1_TE | USART_CR1_RXNEIE;
USART1->CR1 |= USART_CR1_UE;
/*Enable Interrupt*/
NVIC_EnableIRQ(USART1_IRQn); /* (1) */
NVIC_SetPriority(USART1_IRQn, 3); /* (2) */
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>