本帖最后由 shipeng 于 2018-4-16 09:23 编辑
我在main函数中int main(void)
{
RCC_Configuration();
BKP_Init();
delay_init();
NVIC_Configuration();
uart_init(115200);
USART_SendData(USART1,0xFF);//
这条可以成功发出。
delay_ms(1000);
USART_SendData(USART1,0xFF);//
1秒延时之后紧跟着发的这条0xFF发不出来!!!
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);
USART_SendData(USART1,0xFF);//
这条可以成功发出。
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);
while(1)
{
IWDG_ReloadCounter();
}
}
以下是相关函数的详细信息:
void delay_init()
{
#ifdef OS_CRITICAL_METHOD
u32 reload;
#endif
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); //HCLK/8
fac_us=SystemCoreClock/8000000; //1/8
#ifdef OS_CRITICAL_METHOD
reload=SystemCoreClock/8000000;
reload*=1000000/OS_TICKS_PER_SEC;
//reload
fac_ms=1000/OS_TICKS_PER_SEC;
SysTick->CTRL|=SysTick_CTRL_TICKINT_Msk;
SysTick->LOAD=reload;
SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk; //SYSTICK
#else
fac_ms=(u16)fac_us*1000;
#endif
}
void delay_ms(u16 nms)
{
u32 temp;
SysTick->LOAD=(u32)nms*fac_ms;
SysTick->VAL =0x00;
SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ;
do
{
temp=SysTick->CTRL;
}
while(temp&0x01&&!(temp&(1<<16)));
SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;
SysTick->VAL =0X00;
}
void uart_init(u32 bound){
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE);
USART_DeInit(USART1);
//USART1_TX PA.9
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA.9
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART1_RX PA.10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART 3õê¼»ˉéèÖÃ
USART_InitStructure.USART_BaudRate = bound;
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_Init(USART1, &USART_InitStructure);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_Cmd(USART1, ENABLE);
}
请教大家为何会有一个字节发不出来?
此帖出自
小平头技术问答
一周热门 更多>