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

STM32F03的GPIO_Mode_AF_OD功能

[复制链接]
changyuezh 提问时间:2013-12-23 17:52 /
         stm32做读卡程序,需要支持7816接口,USART1的TX 怎么设GPIO_Mode_AF_OD模式呢?
以前是这样完成的,在103上,但现在没有定义这个了,只GPIO_Mode_AF
/* Configure USART3 Tx (PB.10) as alternate function open-drain */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
收藏 评论8 发布时间:2013-12-23 17:52

举报

8个回答
勒布朗 回答时间:2013-12-24 20:45:25

RE:STM32F03的GPIO_Mode_AF_OD功能

把推免 上拉 复用都试一遍不就得了
Hiker天下 回答时间:2013-12-25 00:03:37

RE:STM32F03的GPIO_Mode_AF_OD功能

STM32F0XX的固件库写F2XX F4XX 是相同的。 与F10X不同。你可以查看库中的样例程序。
功能复用时是使用 GPIO_PinAFConfig函数 进行引脚映射。
    /* Connect PXx to USARTx_Tx*/
    GPIO_PinAFConfig(COM_TX_PORT[COM], COM_TX_AF_PIN[COM], COM_AF[COM]);
    /* Connect PXx to USARTx_Rx*/
    GPIO_PinAFConfig(COM_RX_PORT[COM], COM_RX_AF_PIN[COM], COM_AF[COM]);
fengye5340 回答时间:2013-12-25 11:37:40

回复:STM32F03的GPIO_Mode_AF_OD功能

 GPIO_InitTypeDef  GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;
               
        RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA, ENABLE);   // 使能GPIOB端口
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); // 使能串口1时钟
               
        GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_1);
        GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_1);       
/////////////////////////////////////////////////////////////////////////////////////       
        /*
        *  USART1_TX -> PA9 , USART1_RX ->        PA10
        */                               
        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(GPIOA, &GPIO_InitStructure);
/////////////////////////////////////////////////////////////////////////////////////
          
        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_ITConfig(USART1, USART_IT_RXNE,ENABLE);    //打开中断   
               
        USART_Cmd(USART1, ENABLE);//使能串口1
 
给你一个最全的,试试,F0的串口配置代码
feiante-155820 回答时间:2013-12-25 17:14:32

RE:STM32F03的GPIO_Mode_AF_OD功能

void usart1_init(unsigned int BaudRate)
{
        GPIO_InitTypeDef        GPIO_InitStructure;
        USART_InitTypeDef        USART_InitStructure;
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);    //打开GPIOA时钟
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); //打开usart时钟
       
        //GPIO_DeInit(GPIOA);
       
        GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);
     /* Configure pins as AF pushpull */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10 ;
        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_NOPULL;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
       
        //USART_DeInit(USART1);
        USART_InitStructure.USART_BaudRate = BaudRate;
        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);
        USART_ClearFlag(USART1, USART_FLAG_TC);  
}
这个配置可以用的,
具体可以看https://www.stmcu.org.cn/bbs/article_244_566828.html
changyuezh 回答时间:2013-12-25 17:47:19

RE:STM32F03的GPIO_Mode_AF_OD功能

谢谢大家的回复,因为我是要用它不是做串口,是做ISO7816的CK-PA8和IO-PA9,串口功能像大家那样设确实是可用的。在参看F103的程序时,发现要设GPIO_CRH寄存器:
/* Enable USART3 clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
                           
  /* Configure USART3 CK(PB.12) as alternate function push-pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  
  /* Configure USART3 Tx (PB.10) as alternate function open-drain */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
changyuezh 回答时间:2013-12-25 18:00:58

回复:STM32F03的GPIO_Mode_AF_OD功能

 也就通过GPIO_CRH设置成0xFB
即:10:复用功能推挽输出模式
       11:复用功能开漏输出模式
 
MODE:11:输出模式,最大速度50MHz
 
GPIO_TypeDef* 定义的寄存器变了,
程序如下:
RCC_APB1PeriphClockCmd(SC_USART_CLK, ENABLE);       
         /* Configure USART1 CK(PA8) as alternate function push-pull */
  GPIO_InitStructure.GPIO_Pin = SC_USART_PIN_CK;    //PA8
  GPIO_InitStructure.GPIO_Mode =  GPIO_Mode_AF;//GPIO_Mode_AF_PP;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_Init(SC_USART_GPIO, &GPIO_InitStructure);
  redata[1]=GPIOA->AFR[1];
  /* Configure USART1 Tx (PA9) as alternate function open-drain */
  GPIO_InitStructure.GPIO_Pin = SC_USART_PIN_TX;  //PA9
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //GPIO_Mode_AF_OD
        GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; 
 
  GPIO_Init(SC_USART_GPIO, &GPIO_InitStructure);
        //redata[1]=GPIOA->AFR[1];
  /* Connect PXx to USARTx_Tx */ 
       GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_1);  //¸´Óù¦ÄÜ
        GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1); 
但一直没收到数据。
如果有F0的寄存器的说明就好了。
 
 
 
有缘于你 回答时间:2013-12-25 18:36:39

RE:STM32F03的GPIO_Mode_AF_OD功能

GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
等于 GPIO_Mode_AF_OD
wkuang 回答时间:2013-12-27 22:21:25

RE:STM32F03的GPIO_Mode_AF_OD功能

1、使用STM的库的同时要关注库的实现,结合STM32寄存器手册来看。
STM32的库升级了,但是寄存器定义是没有变化的,所以只要具体看其实现就可以了。
一个IO有几个复用功能,可以通过寄存器的bit位来确定,只要看老版本的库怎么设置寄存器的,对应在新版本的库中使用此种设置即可
关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版