STM8 USART串口通信搞不懂啊。。。
main.c文件:#include"stm8l15x.h"#include"stm8l15x_clk.h"#include"stm8l15x_gpio.h"#includ...
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);
} 展开
#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);
} 展开
4个回答
展开全部
这个啊,搞不懂
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
程序没问题了,这有什么不懂的啊?
哪一句看不懂啊?
哪一句看不懂啊?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询