就是我打算用串口调试助手往板子里输入一个数据然后板子返回一个数据,但是接收不了,求大侠帮忙,下面是代码。
main.c文件:
#include "stm8l15x.h"
#include "stm8l15x_clk.h"
#include "stm8l15x_gpio.h"
#include "stm8l15x_usart.h"
void CLK_config()
{
CLK_DeInit();
CLK_HSICmd(ENABLE);//使能内部高频RC
CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_8);
}
void USART_config()
{
USART_ClockInit( USART1,USART_Clock_Enable,USART_CPOL_Low,USART_CPHA_2Edge,USART_LastBit_Disable);
CLK_PeripheralClockConfig(CLK_Peripheral_USART1, ENABLE);
USART_DeInit(USART1);
USART_Init(USART1,9600,USART_WordLength_8b,USART_StopBits_1,USART_Parity_No, USART_Mode_Rx| USART_Mode_Tx);
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
USART_HalfDuplexCmd(USART1,ENABLE);
USART_Cmd(USART1,ENABLE);
//enableInterrupts();
}
void GPIO_config()
{GPIO_Init(GPIOC,GPIO_Pin_3,GPIO_Mode_In_FL_No_IT); //RXD PC3 led3 接收到数据 led3会亮
GPIO_Init(GPIOC,GPIO_Pin_2,GPIO_Mode_Out_PP_High_Fast ); //TXD PC2 led4 发送数据 led4会亮
}
main()
{
GPIO_config();
CLK_config();
USART_config();
whlile(1)
{
};
}
stm8l15x_it.c文件:
#include "stm8l15x_it.h"
#include "stm8l15x_usart.h"
unsigned char GetData;
INTERRUPT_HANDLER(USART1_RX_IRQHandler, 28)
{u8 GetData ;
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
GetData=USART_ReceiveData8(USART1);
while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);
USART_SendData8(USART1,GetData);
}
|