5回答

0收藏

[求助] GD32 18b20求助

GD32 GD32 3143 人阅读 | 5 人回复 | 2015-08-03

18B20  1-wire总线的数据传输,遗憾的是在GD32中总是驱动不了,我知道以前用freecale KL25Z 与STM32F103 都很容易驱动成功,但是这GD32 花费了我一周多的时间还是不成功,求助于大家!~请大家指点指点一下
  1. class DigitalInOut {

  2. public:
  3.     /** Create a DigitalInOut connected to the specified pin
  4.      *
  5.      *  @param pin DigitalInOut pin to connect to
  6.      */
  7.     DigitalInOut(PinName pin){
  8.         GPIO_InitPara GPIO_InitStructure;
  9.                 GPIOx = (GPIO_TypeDef *)(AHB2PERIPH_BASE +(uint32_t)((pin&0xffff0000)>>16));
  10.                 GPIO_Pin = (uint16_t)(pin&0xffff);
  11.                
  12.     }

  13.     /** Set the output, specified as 0 or 1 (int)
  14.      *
  15.      *  @param value An integer specifying the pin output value,
  16.      *      0 for logical 0, 1 (or any other non-zero value) for logical 1
  17.      */
  18.     void write(int value) {
  19.                 if(value)
  20.                         GPIO_WriteBit(GPIOx,GPIO_Pin,Bit_SET);
  21.                 else
  22.                         GPIO_WriteBit(GPIOx,GPIO_Pin,Bit_RESET);
  23.     }

  24.     /** Return the output setting, represented as 0 or 1 (int)
  25.      *
  26.      *  @returns
  27.      *    an integer representing the output setting of the pin if it is an output,
  28.      *    or read the input if set as an input
  29.      */
  30.     int read() {
  31.         if(GPIO_ReadInputBit(GPIOx,GPIO_Pin))
  32.                         return 1;
  33.                 else
  34.                         return 0;
  35.     }

  36.     /** Set as an output
  37.      */
  38.     void output() {
  39.         //gpio_dir(&gpio, PIN_OUTPUT);
  40.         GPIO_InitPara GPIO_InitStructure;
  41.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin;
  42.         GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUT;
  43.         GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
  44.         GPIO_InitStructure.GPIO_OType = GPIO_OTYPE_PP;
  45.         GPIO_InitStructure.GPIO_PuPd = GPIO_PUPD_NOPULL;
  46.         GPIO_Init(GPIOx,&GPIO_InitStructure);
  47.     }

  48.     /** Set as an input
  49.      */
  50.     void input() {
  51.         //gpio_dir(&gpio, PIN_INPUT);
  52.         GPIO_InitPara GPIO_InitStructure;
  53.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin;
  54.         GPIO_InitStructure.GPIO_Mode = GPIO_MODE_IN;
  55.     GPIO_InitStructure.GPIO_PuPd = GPIO_PUPD_NOPULL;
  56.         GPIO_Init(GPIOx,&GPIO_InitStructure);
  57.     }

  58.     /** Set the input pin mode
  59.      *
  60.      *  @param mode PullUp, PullDown, PullNone, OpenDrain
  61.      */
  62.      /*
  63.     void mode(PinMode pull) {
  64.         //gpio_mode(&gpio, pull);
  65.     }*/

  66. protected:
  67.     GPIO_TypeDef* GPIOx;
  68.         uint16_t GPIO_Pin;
  69. };
复制代码

评分

参与人数 1与非币 +5 收起 理由
loveeeboard + 5 三周年铜板双倍!

查看全部评分

分享到:
回复

使用道具 举报

回答|共 5 个

倒序浏览

沙发

tjcfeng

发表于 2015-8-4 07:51:39 | 只看该作者

如果没有外部上拉,需要把内部的打开。
板凳

dvd1478

发表于 2015-8-4 10:40:08 | 只看该作者

tjcfeng 发表于 2015-8-4 07:51
如果没有外部上拉,需要把内部的打开。

外部有上拉
地板

党国特派员

发表于 2015-8-9 10:56:52 | 只看该作者

c++开发,楼主用的是什么软件?
喜欢在构思妙想,电子产品DIY是工作,也是一种爱好。
5#

dvd1478

发表于 2015-8-10 08:20:18 | 只看该作者

党国特派员 发表于 2015-8-9 10:56
c++开发,楼主用的是什么软件?

MDK :, 可惜到现在还是不能通信,调回原来的程序发现也是这样,怀疑是硬件出问题了
6#

党国特派员

发表于 2015-8-10 09:22:39 | 只看该作者

dvd1478 发表于 2015-8-10 08:20
MDK :, 可惜到现在还是不能通信,调回原来的程序发现也是这样,怀疑是硬件出问题了 ...

MDK好不支持C++吧。如果要做成C++那种,只有用STRUCT代替。
喜欢在构思妙想,电子产品DIY是工作,也是一种爱好。
您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /2 下一条