初学STM8L 利用usart串口发送数据,但tx管脚一直都是低电平,不知道原因,希望能有大侠指点下,一下是我的程序
/* MAIN.C file
*
* Copyright (c) 2002-2005 STMicroelectronics
*/
#include "stm8l15x.h"
#include "stm8l15x_clk.h"
#include "stm8l15x_gpio.h"
#include "stm8l15x_usart.h"
#include "stm8l15x_syscfg.h"
unsigned char Tab_tx[]={0x15,0x00,0x05,0x00,0x12,0x00,0x00,0x00,0x02};
unsigned char Tab_rx[21]={0x00};
#define TX_PORT GPIOC
#define TX_PIN GPIO_Pin_5
#define RX_PORT GPIOC
#define RX_PIN GPIO_Pin_6
#define LED_PORT GPIOE
#define LED_PIN GPIO_Pin_7
void usart_init(void)
{
USART_DeInit(USART1);
USART_Init(USART1, (uint32_t)115200, USART_WordLength_8b
, USART_StopBits_1,USART_Parity_No,(USART_Mode_TypeDef)USART_Mode_Tx | USART_Mode_Rx);
USART_ClockInit( USART1,USART_Clock_Disable,USART_CPOL_Low,USART_CPHA_2Edge,USART_LastBit_Disable);
USART_ClearFlag(USART1,USART_FLAG_TC);
USART_Cmd(USART1, ENABLE);
}
void clk_config(void)
{
//CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);
CLK_PeripheralClockConfig(CLK_Peripheral_USART1, ENABLE);
}
void gpio_config(void)
{
GPIO_Init(TX_PORT,TX_PIN,GPIO_Mode_Out_PP_Low_Fast);
GPIO_Init(RX_PORT,RX_PIN,GPIO_Mode_In_FL_No_IT);
GPIO_Init(LED_PORT,LED_PIN,GPIO_Mode_Out_PP_Low_Fast);
}
void tx_data(void)
{ unsigned char i;
for(i=0;i<9;i++)
{
USART_SendData8(USART1,Tab_tx[i]);
}
}
void rx_data(void)
{ unsigned char i;
for(i=0;i<9;i++)
{
Tab_rx[21]=USART_ReceiveData8(USART1);
}
}
main()
{
usart_init();
clk_config();
SYSCFG_REMAPPinConfig(REMAP_Pin_USART1TxRxPortC,ENABLE);
gpio_config();
tx_data();
rx_data();
if(Tab_rx[0]==0x51)
GPIO_WriteBit(LED_PORT,LED_PIN,SET);
} |