用的开发板例程将串口1、2定义成了COM2和COM1了………………
int main()
{
// 配置串口参数
/* USARTx 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 = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_2;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* 完成串口时钟配置、GPIO配置、根据上述参数初始化并使能串口 */
STM_COMInit(COM2, &USART_InitStructure); //初始化USART1,用于发送到电脑
STM_COMInit(COM1, &USART_InitStructure);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//接收短信
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
// if(temp_trx[1]==0x2b && temp_trx[1]==0x43 && temp_trx[1]==0x4d && temp_trx[1]==0x54 )
// {
// num=temp_trx[1];
// }
while(1)
{
printf(" welcome! \n\r");
// printf(" temperature: \n\r");
// printf("voltage: \n\r");
// printf("%c",num);
delay(200000);
delay(200000);
delay(200000);
delay(200000);
}
}
int main()
{
// 配置串口参数
/* USARTx 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 = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_2;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* 完成串口时钟配置、GPIO配置、根据上述参数初始化并使能串口 */
STM_COMInit(COM2, &USART_InitStructure); //初始化USART1,用于发送到电脑
STM_COMInit(COM1, &USART_InitStructure);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//接收短信
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
// if(temp_trx[1]==0x2b && temp_trx[1]==0x43 && temp_trx[1]==0x4d && temp_trx[1]==0x54 )
// {
// num=temp_trx[1];
// }
while(1)
{
printf(" welcome! \n\r");
// printf(" temperature: \n\r");
// printf("voltage: \n\r");
// printf("%c",num);
delay(200000);
delay(200000);
delay(200000);
delay(200000);
}
}