程序主要内容如下: int main(void) { #ifdef DEBUG debug(); #endif int Tx_Data,Led_Seq; int i; /* System Clocks Configuration */ RCC_Configuration(); /* NVIC configuration */ NVIC_Configuration(); /* Configure the GPIO ports */ GPIO_Configuration(); /* Enable USART1 */ USART_Cmd(USART1, ENABLE); /* Enable USART2 */ USART_Cmd(USART2, ENABLE); /* USART1 configuration ------------------------------------------------------*/ 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_InitStructure.USART_Clock = USART_Clock_Disable; USART_InitStructure.USART_CPOL = USART_CPOL_Low; USART_InitStructure.USART_CPHA = USART_CPHA_2Edge; USART_InitStructure.USART_LastBit = USART_LastBit_Disable; /* Configure the USART1 */ USART_Init(USART1, &USART_InitStructure); /* Configure the USART2 */ USART_Init(USART2, &USART_InitStructure); /* Enable the USART Transmoit interrupt: this interrupt is generated when the USART1 transmit data register is empty */ //USART_ITConfig(USART1, USART_IT_RXNE, DISABLE); /* Enable the USART Receive interrupt: this interrupt is generated when the USART1 receive data register is not empty */ USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); /* Enable the USART Receive interrupt: this interrupt is generated when the USART1 receive data register is not empty */ USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); /* Enable USART1 */ // USART_Cmd(USART1, ENABLE); Tx_Data=0x30; while(1) { RxBuffer2[5] = 0xFF; USART_SendData(USART1, Tx_Data); //while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); RxBuffer2[5] = USART_ReceiveData(USART1); } } void USART_SendData(USART_TypeDef* USARTx, u16 Data) { /* Check the parameters */ assert(IS_USART_DATA(Data)); USART_ITConfig(USART1, USART_IT_TXE, ENABLE); USART_Cmd(USART1, ENABLE); /* Transmit Data */ USARTx->DR = (Data & (u16)0x01FF); Data ++; } 编译后执行到“USART_SendData(USART1, Tx_Data);” 发生异常错误,程序跳转到程序最后。 请大家帮我看看是什么问题 |
RE:紧急求助:请帮忙解决STM32usart通信问题
RE:紧急求助:请帮忙解决STM32usart通信问题
RE:紧急求助:请帮忙解决STM32usart通信问题
{
/* Check the parameters */
assert(IS_USART_DATA(Data));
//USART_ITConfig(USART1, USART_IT_TXE, ENABLE); 已经开启了中断,这里可以不用处理
//USART_Cmd(USART1, ENABLE);前面已经开启了,这个也可以不处理
/* Transmit Data */
USARTx->DR = (Data & (u16)0x01FF);
Data ++;
}
RE:紧急求助:请帮忙解决STM32usart通信问题
单步执行到USART_SendData(USART1, Tx_Data);时程序跳到0xfffffffe