你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

求教 STM32F05 串口通信收发不一致

[复制链接]
枫叶20101112 提问时间:2014-5-30 11:21 /
下面是我的配置代码:
static void GPIO_USART1_Configuration(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
       
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
       
        GPIO_PinAFConfig(GPIOUSART1, GPIO_PinSource9,  GPIO_AF_1);
        GPIO_PinAFConfig(GPIOUSART1, GPIO_PinSource10, GPIO_AF_1);
       
        /* GPIO_PIN9 -> USART1-TX  GPIO_PIN10 -> USART1-RX */
       GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_9 |  GPIO_Pin_10 ;                 
        GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; 
        GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
       
        GPIO_Init(GPIOUSART1, &GPIO_InitStructure);
}
 
void USART1_Configuration(void)
{
        USART_InitTypeDef USART_InitStructure;
       
        GPIO_USART1_Configuration();
       
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
       
        USART_InitStructure.USART_BaudRate                      = 9600;      
        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_Cmd(USART1, ENABLE);//ʹÄÜ´®¿Ú1
}
 
void UART1_send_byte(uint8_t byte)
{
        while(!((USART1->ISR)&(1ISR)&(1ISR & (1CR |= (uint32_t)0x00000001;
 
  /* Reset SW[1:0], HPRE[3:0], PPRE[2:0], ADCPRE and MCOSEL[2:0] bits */
  RCC->CFGR &= (uint32_t)0xF8FFB80C;
  
  /* Reset HSEON, CSSON and PLLON bits */
  RCC->CR &= (uint32_t)0xFEF6FFFF;
 
  /* Reset HSEBYP bit */
  RCC->CR &= (uint32_t)0xFFFBFFFF;
 
  /* Reset PLLSRC, PLLXTPRE and PLLMUL[3:0] bits */
  RCC->CFGR &= (uint32_t)0xFFC0FFFF;
 
  /* Reset PREDIV1[3:0] bits */
  RCC->CFGR2 &= (uint32_t)0xFFFFFFF0;
 
  /* Reset USARTSW[1:0], I2CSW, CECSW and ADCSW bits */
  RCC->CFGR3 &= (uint32_t)0xFFFFFEAC;
  
  /* Reset HSI14 bit */
  RCC->CR2 &= (uint32_t)0xFFFFFFFE;
 
  /* Disable all interrupts */
  RCC->CIR = 0x00000000;
  
/* Configure the System clock frequency, AHB/APBx prescalers and Flash settings */
  SetSysClock();
}
 
static void SetSysClock(void)
{
  __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
  
  /* SYSCLK, HCLK, PCLK configuration ----------------------------------------*/
  /* Enable HSE */  
  RCC->CR |= ((uint32_t)RCC_CR_HSEON);
 
  /* Wait till HSE is ready and if Time out is reached exit */
  do
  {
    HSEStatus = RCC->CR & RCC_CR_HSERDY;
    StartUpCounter++;  
  } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
 
  if ((RCC->CR & RCC_CR_HSERDY) != RESET)
  {
    HSEStatus = (uint32_t)0x01;
  }
  else
  {
    HSEStatus = (uint32_t)0x00;
  }  
 
  if (HSEStatus == (uint32_t)0x01)
  {
    /* Enable Prefetch Buffer */
    FLASH->ACR |= FLASH_ACR_PRFTBE;
    FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY;
 
    /* HCLK = SYSCLK */
    RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
      
    /* PCLK = HCLK */
    RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE_DIV1;
 
    /*  PLL configuration:  = HSE *  4 = 40 MHz */
    RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));
    RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLMULL4);
            
    /* Enable PLL */
    RCC->CR |= RCC_CR_PLLON;
 
    /* Wait till PLL is ready */
    while((RCC->CR & RCC_CR_PLLRDY) == 0)
    {
    }
 
    /* Select PLL as system clock source */
    RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
    RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;    
 
    /* Wait till PLL is used as system clock source */
    while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)
    {
    }
  }
  else
  { /* If HSE fails to start-up, the application will have wrong clock 
         configuration. User can add here some code to deal with this error */
  }  
}
 
调了两天了,一直找不到问题,

 
收藏 评论1 发布时间:2014-5-30 11:21

举报

1个回答
枫叶20101112 回答时间:2014-5-30 11:23:29

回复:求教 STM32F05 串口通信收发不一致

PC机的串口设置没错的,也不是USB转串口线的问题,我换了一条也是一样的
关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版