wuhaiduo 发表于 2015-8-23 12:19:25

stm32f030k6t6 串口1配置

stm32f030k6t6 串口1配置
PB6 PB7配置成串口1   怎么都不成


       RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);   
      RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);
      


       GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
      GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
      GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
      //GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
      GPIO_Init(GPIOB, &GPIO_InitStructure);
      
      
      GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_0);
      GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_0);



alisa123 发表于 2015-8-24 12:37:47

你试试GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_1);
      GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_1);看看行不行。

wuhaiduo 发表于 2015-8-24 14:18:59

还是不行的呜呜

wuhaiduo 发表于 2015-8-24 14:21:25

       RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB|RCC_AHBPeriph_GPIOA, ENABLE);
        RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);//
       
       
        GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_1);
        GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_1);
       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
        //GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
       
       
        USART_InitStructure.USART_BaudRate = DMX512_RATE;            
        USART_InitStructure.USART_WordLength = USART_WordLength_8b;
        USART_InitStructure.USART_StopBits = USART_StopBits_2;
        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_ITConfig(USART1,USART_IT_ERR,ENABLE);         
        USART_ClearITPendingBit(USART1, USART_IT_TC);
        USART_Cmd(USART1, ENABLE);                           
       
       
        NVIC_InitStruct.NVIC_IRQChannel = USART1_IRQn;
        NVIC_InitStruct.NVIC_IRQChannelPriority = 0x00;
        NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStruct);

芯片 STM32F030K6T6   
设置的宏USE_STDPERIPH_DRIVER,STM32F030X6,

wuhaiduo 发表于 2015-8-24 14:21:54

串口设置在PB6 PB7上

wuhaiduo 发表于 2015-8-24 14:25:23


wuhaiduo 发表于 2015-8-24 19:57:55

alisa123 发表于 2015-8-24 12:37
你试试GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_1);
      GPIO_PinAFConfig(GPIOB, GPIO_Pi ...

还是不可以   看到别的问题了吗

alisa123 发表于 2015-8-25 09:52:24

wuhaiduo 发表于 2015-8-24 14:21
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB|RCC_AHBPeriph_GPIOA, ENABLE);
        RCC_APB2PeriphRese ...

你的串口1的时钟开的不对吧,你的代码中是RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);//
这个是复位的,不是使能。

wuhaiduo 发表于 2015-8-25 10:38:15

是呀   我改过来看看太马虎了

wuhaiduo 发表于 2015-8-25 10:38:50

alisa123 发表于 2015-8-25 09:52
你的串口1的时钟开的不对吧,你的代码中是RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);//
这 ...

很感谢你我改过来看看
页: [1] 2
查看完整版本: stm32f030k6t6 串口1配置