大学生
最后登录1970-1-1
在线时间 小时
注册时间2015-8-10
|
楼主 |
发表于 2016-1-7 08:37:02
|
显示全部楼层
本帖最后由 952699805 于 2016-1-7 08:58 编辑
USART3的配置和USART1有区别吗我现在用的是USART3来发送接收数据的,我用的是STM32F103C8T6的片子。void USART3_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* config USART1 clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB , ENABLE);
/* USART1 GPIO config */
/* Configure USART1 Tx (PB.10) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure USART1 Rx (PB.11) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* USART1 mode config */
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(USART3, &USART_InitStructure);
USART_Cmd(USART3, ENABLE);
}
void UARTPutChar (u16 Data)
{
while (!(USART3->SR & USART_FLAG_TXE));
USART3->DR = (Data & (uint16_t)0x01FF);
}
void UARTPutDec16(uint16_t decnum)
{
uint8_t c1=decnum%10;
uint8_t c2=(decnum/10)%10;
uint8_t c3=(decnum/100)%10;
uint8_t c4=(decnum/1000)%10;
uint8_t c5=(decnum/10000)%10;
UARTPutChar('0'+c5);
UARTPutChar('0'+c4);
UARTPutChar('0'+c3);
UARTPutChar('0'+c2);
UARTPutChar('0'+c1);
}
int main(void)
{
USART3_Config();
while(1)
{
UARTPutDec16(0x0B);
delay_ms(1000);
LED1_ON;
delay_ms(1000);
LED1_OFF;
}
}
|
|