admin管理员组

文章数量:1558910

回复【3楼】正点原子:

---------------------------------

额,我菜鸟。

是这样的:

void Usart1_init(void)

{

NVIC_InitTypeDef NVIC_InitStructure;

USART_InitTypeDef USART_InitStructure;

GPIO_InitTypeDef  GPIO_InitStruct;

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;

GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;

GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;

GPIO_Init(GPIOA, &GPIO_InitStruct);

GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART1);

GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

USART_DeInit(USART1);

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(USART1,&USART_InitStructure);

USART_Cmd(USART1,ENABLE);

}

int main(void)

{

Usart1_init();

while (1)

{

USART_SendData(USART1,'1');

while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);

delay_ms(1000);

}

}

我是想在串口调试助手上看到发送的数据。有空的话帮忙看下。自己一个人学,很多不懂。谢谢!!!

本文标签: 串口助手通信Linux