stm32 串口在ucos系统下不能正常输出。如果发送单字节的话 只有在开机的时候会有2个0xff,不管我发送什么内容。如果是以字符串的方式发送,有些内容能发送比如{1,2,3,4,5}但是开始的头第一帧数据是不对的,而且在后面大概23帧左右,也会出现发送内容错误,但是再之后所有的内容都正确。如果发送的内容是{10,11,12,13,14}之类现象就跟发送单字节一样,只有开机发送0xff之后就无反应,板子没死机。- void Usart1_Configuration(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- USART_InitTypeDef USART_InitStructure;
- USART_ClockInitTypeDef USART_ClockStructure;
- NVIC_InitTypeDef NVIC_InitStructure;
-
- /* Enable USART1, GPIOA, GPIOx and AFIO clocks */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
- /* Configure the NVIC Preemption Priority Bits */
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
-
- /* Enable the USART1 Interrupt */
- NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- /* Configure USART1 Rx (PA.10) as input floating */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- /* Configure USART1 Tx (PA.09) as alternate function push-pull */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- 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_ClockStructure.USART_Clock = USART_Clock_Disable;
- USART_ClockStructure.USART_CPOL = USART_CPOL_Low;
- USART_ClockStructure.USART_CPHA = USART_CPHA_2Edge;
- USART_ClockStructure.USART_LastBit = USART_LastBit_Disable;
- /* Configure USART1 */
- USART_Init(USART1, &USART_InitStructure);
- USART_ClockInit(USART1,&USART_ClockStructure);
- /* Enable USART1 Receive and Transmit interrupts */
- USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
- //USART_ClearITPendingBit(USART1,USART_IT_TXE);
- //USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
-
- /* Enable the USART1 */
- USART_Cmd(USART1, ENABLE);
- // USART_ClearFlag(USART1,USART_FLAG_TC);
- }
- //这是串口配置函数
- void Usart1_Send_Char(unsigned char k)
- {
- USART_SendData(USART1,k);
- while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET){;}
- }
- void USART1_Send_Str(unsigned char *s)
- {
- int i;
- int len=strlen(s);
- //strcpy(Rx1Buffer,s);
- //USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
- for(i=0;i<len;i++)
- Usart1_Send_Char(s[i]);
- }
- //这是发送单字节和字符串函数
- 这些功能在裸机下都是正常的。望各位大虾不吝赐教,
|