zoukankan      html  css  js  c++  java
  • 软件模拟I2C时输入与输出切换

    一 为达到类似C51的操作需要添加以下位带操作:#include "stm32f10x_gpio.h"
    #include "stm32f10x_conf.h"

    /* IO地址映射*/
    #define GPIOA_ODR_Addr    (GPIOA_BASE+12) //0x4001080C
    #define GPIOB_ODR_Addr    (GPIOB_BASE+12) //0x40010C0C
    #define GPIOC_ODR_Addr    (GPIOC_BASE+12) //0x4001100C
    #define GPIOD_ODR_Addr    (GPIOD_BASE+12) //0x4001140C
    #define GPIOE_ODR_Addr    (GPIOE_BASE+12) //0x4001180C
    #define GPIOF_ODR_Addr    (GPIOF_BASE+12) //0x40011A0C    
    #define GPIOG_ODR_Addr    (GPIOG_BASE+12) //0x40011E0C    

    #define GPIOA_IDR_Addr    (GPIOA_BASE+8) //0x40010808
    #define GPIOB_IDR_Addr    (GPIOB_BASE+8) //0x40010C08
    #define GPIOC_IDR_Addr    (GPIOC_BASE+8) //0x40011008
    #define GPIOD_IDR_Addr    (GPIOD_BASE+8) //0x40011408
    #define GPIOE_IDR_Addr    (GPIOE_BASE+8) //0x40011808
    #define GPIOF_IDR_Addr    (GPIOF_BASE+8) //0x40011A08
    #define GPIOG_IDR_Addr    (GPIOG_BASE+8) //0x40011E08

    /* 输入 */
    #define PAin(n)        *((volatile unsigned long *)(0x42000000+((GPIOA_IDR_Addr-0x40000000)<<5)+(n<<2)))
    #define PBin(n)        *((volatile unsigned long *)(0x42000000+((GPIOB_IDR_Addr-0x40000000)<<5)+(n<<2)))
    #define PCin(n)        *((volatile unsigned long *)(0x42000000+((GPIOC_IDR_Addr-0x40000000)<<5)+(n<<2)))
    #define PDin(n)        *((volatile unsigned long *)(0x42000000+((GPIOD_IDR_Addr-0x40000000)<<5)+(n<<2)))
    #define PEin(n)        *((volatile unsigned long *)(0x42000000+((GPIOE_IDR_Addr-0x40000000)<<5)+(n<<2)))
    #define PFin(n)        *((volatile unsigned long *)(0x42000000+((GPIOF_IDR_Addr-0x40000000)<<5)+(n<<2)))

    /* 输出 */
    #define PAout(n)    *((volatile unsigned long *)(0x42000000+((GPIOA_ODR_Addr-0x40000000)<<5)+(n<<2)))
    #define PBout(n)    *((volatile unsigned long *)(0x42000000+((GPIOB_ODR_Addr-0x40000000)<<5)+(n<<2)))
    #define PCout(n)    *((volatile unsigned long *)(0x42000000+((GPIOC_ODR_Addr-0x40000000)<<5)+(n<<2)))
    #define PDout(n)    *((volatile unsigned long *)(0x42000000+((GPIOD_ODR_Addr-0x40000000)<<5)+(n<<2)))
    #define PEout(n)    *((volatile unsigned long *)(0x42000000+((GPIOE_ODR_Addr-0x40000000)<<5)+(n<<2)))

    二 假设SDA=PB0,SCL=PB1:

    #define SDA_IN()  {GPIOB->CRL&=0XFFFFFFF0;GPIOB->CRL|=8<<0;} /*也就是对应的GPIO输入输出配置寄存器进行操作:PB0的输入上拉*/
    #define SDA_OUT() {GPIOB->CRL&=0XFFFFFFF0;GPIOB->CRL|=3<<0;}/*PB0的上拉,输出速度50MHZ*/
    #define IIC_SCL    PBout(1) /*相当于操作函数GPIO_WriteBit*/
    #define IIC_SDA    PBout(0)         
    #define READ_SDA   PBin(0)  /*相当于操作函数GPIO_ReadInputDataBit*/

  • 相关阅读:
    centos 6.8 配置 Redis3.2.5
    php将字符串转为二进制数据串
    php密码对称encrypt加密
    mysql 新建用户并赋予远程访问权限
    centos6.8 搭建postfix/dovecot邮件服务器
    centos 6.8 设置svn钩子同步至web目录
    百分百解决Job for network.service failed. See 'system的问题
    java锁机制详解
    解决网页打不开简书的问题
    SpringBoot读取不到application.yml
  • 原文地址:https://www.cnblogs.com/jieruishu/p/9258672.html
Copyright © 2011-2022 走看看