Uart_Init(); CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART1, ENABLE); __enable_interrupt(); printf("
硬件平台为:%s
","iCreate STM8 开发板"); UART1_SendString("Serial Communication ---STM8 Development Board of FengChi Electron ", sizeof("Serial Communication ---STM8 Development Board of FengChi Electron"));
Delay(0xffff); UART1_SendByte('
'); Delay(0xffff); while (1) {
printf("
硬件平台为:%s
","iCreate STM8 开发板"); if(UART_RX_NUM&0x80) { len=UART_RX_NUM&0x3f;/*得到此次接收到的数据长度*/ UART1_SendString("You sent the messages is:",sizeof("You sent the messages is")); UART1_SendString(RxBuffer,len); UART1_SendByte('
'); UART_RX_NUM=0; } }
---------------------------------
建议你看下管脚复用配置 ,有可能你用的串口是 备用串口呢。。option byte
---------------------------------
int main(void)
{
u8 len ;
/* Infinite loop */
/*设置内部时钟16M为主时钟*/
CLK_HSICmd(ENABLE);
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
/*!<Set High speed internal clock */
ADC1_DeInit();
ADC1_Cmd(DISABLE);
ADC1_SchmittTriggerConfig(ADC1_SCHMITTTRIG_CHANNEL6, ENABLE);
ADC1_SchmittTriggerConfig(ADC1_SCHMITTTRIG_CHANNEL5, ENABLE);
GPIO_Init(GPIOD, GPIO_PIN_6, GPIO_MODE_IN_FL_NO_IT);
GPIO_Init(GPIOD, GPIO_PIN_5, GPIO_MODE_OUT_PP_HIGH_FAST);
Uart_Init();
CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART1, ENABLE);
__enable_interrupt();
printf(" 硬件平台为:%s ","iCreate STM8 开发板");
UART1_SendString("Serial Communication ---STM8 Development Board of FengChi Electron ",
sizeof("Serial Communication ---STM8 Development Board of FengChi Electron"));
Delay(0xffff);
UART1_SendByte(' ');
Delay(0xffff);
while (1)
{
printf(" 硬件平台为:%s ","iCreate STM8 开发板");
if(UART_RX_NUM&0x80)
{
len=UART_RX_NUM&0x3f;/*得到此次接收到的数据长度*/
UART1_SendString("You sent the messages is:",sizeof("You sent the messages is"));
UART1_SendString(RxBuffer,len);
UART1_SendByte(' ');
UART_RX_NUM=0;
}
}
}
串口就是这样配置的,不知道哪里有问题,不能发送也不能接受,硬件连接没问题啊,>
---------------------------------
恩谢谢已经解决
---------------------------------
刚开始使用库函数做的,总是出问题,后来改用寄存器了,就没问题了。。。。
一周热门 更多>