初级会员

- 积分
- 153
- 金钱
- 153
- 注册时间
- 2014-9-8
- 在线时间
- 23 小时
|
5金钱
我在裸机上运行好好的程序移植到UCOS ii系统下,发现串口4能正常发送数据,但是上位机给串口4发送数据的时候 马上就死机了,发送几个字节都死机,折腾检查初始化还是不行,把其他功能都屏蔽了 就只剩下串口4收发数据功能 还是串口4接收数据就马上死机 代码如下 求指点 谢谢
//USART4
#define COM4 UART4
#define COM4_CLK RCC_APB1Periph_UART4
#define COM4_GPIO GPIOC
#define COM4_GPIO_CLK RCC_APB2Periph_GPIOC
#define COM4_PIN_CK GPIO_Pin_9
#define COM4_PIN_Tx GPIO_Pin_10
#define COM4_PIN_Rx GPIO_Pin_1
#define COM4_IRQn UART4_IRQn
void USART4_485_Init(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(COM4_GPIO_CLK | RCC_APB2Periph_AFIO, ENABLE);
RCC_APB1PeriphClockCmd(COM4_CLK, ENABLE);/*Only USART1, no need to remap*/
/* Configure the NVIC Preemption Priority Bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* Enable the USART4 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = COM4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/*Configure Of USART*/
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;
/* Configure USART Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = COM4_PIN_Tx;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(COM4_GPIO, &GPIO_InitStructure);
/* Configure USART Rx as input floating */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = COM4_PIN_Rx;
GPIO_Init(COM4_GPIO, &GPIO_InitStructure);
/* USART configuration */
USART_Init(COM4, &USART_InitStructure);
/* Enable USART */
USART_Cmd(COM4, ENABLE);
/***************Configure USART Contral for RS485 Mode to select ************/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = COM4_PIN_CK;
GPIO_Init(COM4_GPIO, &GPIO_InitStructure);
//ÏDê±′|óúêÕêy×′ì¬
GPIO_ResetBits(COM4_GPIO,COM4_PIN_CK);
USART_ITConfig(COM4, USART_IT_RXNE, ENABLE);
}
void USART4_IRQHandler(void)
{
uint8_t tmp;
OS_CPU_SR cpu_sr;
OS_ENTER_CRITICAL();
OSIntNesting++;
OS_EXIT_CRITICAL();
if (USART_GetITStatus(UART4, USART_IT_RXNE) != RESET)
{
tmp = USART_ReceiveData(UART4);
/* Clear the USART1 Receive interrupt */
USART_ClearITPendingBit(UART4, USART_IT_RXNE);
}
OSIntExit();
}
|
|