TA的每日心情 | 奋斗 2023-7-8 16:17 |
---|
签到天数: 971 天 连续签到: 1 天 [LV.10]以坛为家III
|
18B20 1-wire总线的数据传输,遗憾的是在GD32中总是驱动不了,我知道以前用freecale KL25Z 与STM32F103 都很容易驱动成功,但是这GD32 花费了我一周多的时间还是不成功,求助于大家!~请大家指点指点一下- class DigitalInOut {
- public:
- /** Create a DigitalInOut connected to the specified pin
- *
- * @param pin DigitalInOut pin to connect to
- */
- DigitalInOut(PinName pin){
- GPIO_InitPara GPIO_InitStructure;
- GPIOx = (GPIO_TypeDef *)(AHB2PERIPH_BASE +(uint32_t)((pin&0xffff0000)>>16));
- GPIO_Pin = (uint16_t)(pin&0xffff);
-
- }
- /** Set the output, specified as 0 or 1 (int)
- *
- * @param value An integer specifying the pin output value,
- * 0 for logical 0, 1 (or any other non-zero value) for logical 1
- */
- void write(int value) {
- if(value)
- GPIO_WriteBit(GPIOx,GPIO_Pin,Bit_SET);
- else
- GPIO_WriteBit(GPIOx,GPIO_Pin,Bit_RESET);
- }
- /** Return the output setting, represented as 0 or 1 (int)
- *
- * @returns
- * an integer representing the output setting of the pin if it is an output,
- * or read the input if set as an input
- */
- int read() {
- if(GPIO_ReadInputBit(GPIOx,GPIO_Pin))
- return 1;
- else
- return 0;
- }
- /** Set as an output
- */
- void output() {
- //gpio_dir(&gpio, PIN_OUTPUT);
- GPIO_InitPara GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin;
- GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUT;
- GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
- GPIO_InitStructure.GPIO_OType = GPIO_OTYPE_PP;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PUPD_NOPULL;
- GPIO_Init(GPIOx,&GPIO_InitStructure);
- }
- /** Set as an input
- */
- void input() {
- //gpio_dir(&gpio, PIN_INPUT);
- GPIO_InitPara GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin;
- GPIO_InitStructure.GPIO_Mode = GPIO_MODE_IN;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PUPD_NOPULL;
- GPIO_Init(GPIOx,&GPIO_InitStructure);
- }
- /** Set the input pin mode
- *
- * @param mode PullUp, PullDown, PullNone, OpenDrain
- */
- /*
- void mode(PinMode pull) {
- //gpio_mode(&gpio, pull);
- }*/
- protected:
- GPIO_TypeDef* GPIOx;
- uint16_t GPIO_Pin;
- };
复制代码 |
评分
-
查看全部评分
|