5874 views|9 replies

24

Posts

0

Resources
The OP
 

Flip IO port output square wave [Copy link]

void IO_Toggle(GPIO_TypeDef* GPIOx,u16 GPIO_Pin)
{               
  GPIO_WriteBit(GPIOx, GPIO_Pin, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOx, GPIO_Pin))));  
}


int main(void)
{GPIO_WriteBit(GPIOD,GPIO_Pin_0,Bit_RESET);
GPIO_WriteBit(GPIOD,GPIO_Pin_1,Bit_SET);
GPIO_WriteBit(GPIOD,GPIO_Pin_2,Bit_SET);
GPIO_WriteBit(GPIOD,GPIO_Pin_3,Bit_SET);

while(1)
        {
               
                 if(flag==1)
                 {
                        Toggle_Num++;
        switch(Toggle_Num)
        {
            case 1:  case 3:  case 5:  case 7:  case 9:  case 11:  case 13:  case 15:
                break;
            case 2:
            case 6:
            case 10:
            case 14:
                IO_Toggle(GPIOD,GPIO_Pin_0|GPIO_Pin_1);
                break;
            case 4:
            case 12:
                      IO_Toggle(GPIOD,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2);
                break;
            case 8:
            case 16:
                      IO_Toggle(GPIOD,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3);
                Toggle_Num  =0;
                break;
        }

    flag=0;
}
}

IO初始化

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  //éèa£aêè£êéóóú£aμ1μêè
        GPIO_Init(GPIOD, &GPIO_InitStructure);
        
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  //éèa£aêè£êéóóú£aμ1μêè
        GPIO_Init(GPIOD, &GPIO_InitStructure);               

我这样设定不应该是PD0和PD1为互补方波且频率相同,PD2和PD3分别为PD1频率的1/2和1/4吗?然而我用示波器测试,情况并不是这样,PD0和PD1完全一样,PD2和PD3变成了一条电平,哪位大佬能看看是我哪里设置的有问题吗?226)]                      IO_Toggle(GPIOD,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3);
                Toggle_Num  =0;
                break;
        }

    flag=0;
}
}

IO初始化

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  //éèa£aêè£êéóóú£aμ1μêè
        GPIO_Init(GPIOD, &GPIO_InitStructure);
        
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  //éèa£aêè£êéóóú£aμ1μêè
        GPIO_Init(GPIOD, &GPIO_InitStructure);               

我这样设定不应该是PD0和PD1为互补方波且频率相同,PD2和PD3分别为PD1频率的1/2和1/4吗?然而我用示波器测试,情况并不是这样,PD0和PD1完全一样,PD2和PD3变成了一条电平,哪位大佬能看看是我哪里设置的有问题吗?226)]                      IO_Toggle(GPIOD,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3);
                Toggle_Num  =0;
                break;
        }

    flag=0;
}
}

IO初始化

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  //éèa£aêè£êéóóú£aμ1μêè
        GPIO_Init(GPIOD, &GPIO_InitStructure);
        
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  //éèa£aêè£êéóóú£aμ1μêè
        GPIO_Init(GPIOD, &GPIO_InitStructure);               

我这样设定不应该是PD0和PD1为互补方波且频率相同,PD2和PD3分别为PD1频率的1/2和1/4吗?然而我用示波器测试,情况并不是这样,PD0和PD1完全一样,PD2和PD3变成了一条电平,哪位大佬能看看是我哪里设置的有问题吗?GPIO_Mode = GPIO_Mode_Out_PP; //éèa£aêè£ê éóóú£aμ1μêè GPIO_Init(GPIOD, &GPIO_InitStructure);[ /backcolor] GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //éèa£aêè£ê GPIO_Init(GPIOD, &GPIO_InitStructure); /backcolor] I should set PD0 and PD1 as complementary square waves with the same frequency, and PD2 and Are the frequencies of PD0 and PD1 the same, and PD2 and PD3 the same, respectively? I tested it with an oscilloscope, but it was not the case. PD0 and PD1 were exactly the same, and PD2 and PD3 became one level. Can anyone tell me what is going on? Is there something wrong with my settings?GPIO_Mode = GPIO_Mode_Out_PP; //éèa£aêè£ê éóóú£aμ1μêè GPIO_Init(GPIOD, &GPIO_InitStructure);[ /backcolor] [backcolor =rgb(209, 217, 226)] GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //éèa£aêè£ê GPIO_Init(GPIOD, &GPIO_InitStructure); /backcolor] I should set PD0 and PD1 as complementary square waves with the same frequency, and PD2 and Are the frequencies of PD0 and PD1 the same, and PD2 and PD3 the same, respectively? I tested it with an oscilloscope, but it was not the case. PD0 and PD1 were exactly the same, and PD2 and PD3 became one level. Can anyone tell me what is going on? Is there something wrong with my settings?

This post is from stm32/stm8

Latest reply

Good post. Like! Like! Like! Like! Like! Like! Like! Like! Like! Like! Like!  Details Published on 2018-8-17 17:49
 

24

Posts

0

Resources
2
 
I thought about it for a long time and really didn't know what the problem was. I shielded the switching state in the while loop, PD0 was low and PD1 was high, but the switching state in the while loop was wrong, the two were exactly the same.
This post is from stm32/stm8
 
 

24

Posts

0

Resources
3
 
Oscilloscope picture

PD0_and_PD1.PNG (707.6 KB, downloads: 0)

PD0_and_PD1.PNG

PD0_and_PD2.PNG (719.26 KB, downloads: 0)

PD0_and_PD2.PNG
This post is from stm32/stm8
 
 

64

Posts

0

Resources
4
 
I didn't understand the whole thing in English, so I gave it all back to the teacher,
This post is from stm32/stm8
 
 
 

24

Posts

0

Resources
5
 
I cannot flip multiple IO ports at the same time. I can flip IO ports one by one. Maybe the flip function I set cannot flip multiple ports at a time. I don't know why.
This post is from stm32/stm8
 
 
 

4005

Posts

0

Resources
6
 
(BitAction)((1-GPIO_ReadOutputDataBit(GPIOx, GPIO_Pin)))); Why is it 1- here? I don't understand. Can you debug it and see what's going on?
This post is from stm32/stm8
 
 
 

4005

Posts

0

Resources
7
 
This post was last edited by huo_hu on 2018-8-9 13:11 I see, it's the 1- that's causing the trouble, 1-1=0 1-0=1 Other situations don't hold, think about it again
This post is from stm32/stm8
 
 
 

4005

Posts

0

Resources
8
 
You can just invert the register GPIOD->ODR ^= 3;
This post is from stm32/stm8

Comments

My negation function is wrong. It can only operate a single IO port. Just use the register to negate it.  Details Published on 2018-8-11 21:13
 
 
 

24

Posts

0

Resources
9
 
huo_hu posted on 2018-8-9 13:07 You can just invert the register GPIOD->ODR ^= 3;
My inversion function is wrong, it can only operate a single IO port, just invert the register
This post is from stm32/stm8
 
 
 

12

Posts

0

Resources
10
 
Good post. Like! Like! Like! Like! Like! Like! Like! Like! Like! Like! Like!
This post is from stm32/stm8
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list