高级会员

- 积分
- 608
- 金钱
- 608
- 注册时间
- 2020-4-17
- 在线时间
- 111 小时
|

楼主 |
发表于 2021-5-14 10:58:22
|
显示全部楼层
void USART2_Init(u32 BaudRate)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/*开通UART2 时钟*/
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
/*TX pin*/
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);
/*RX pin*/
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;//浮空输入模式
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStructure);
/*UART2 mode config*/
USART_InitStructure.USART_BaudRate=BaudRate;
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);//串口使能
}
unsigned char st[6] ={0x11,0x22,0x33,0x44,0x55,0x66};
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置系统中断优先级分组2
/*延时函数初始化*/
delay_init(108);
USART2_Init(9600);
while(1)
{
RFTRWriteData(st,6);
delay_ms(500);
delay_ms(500);
delay_ms(500);
}
}
串口不能发送数据
|
|