sir i am facing a problem to map my inputs and outputs in the if condition that is in read input data bit for multiple pins kindly help me the same.
#include "stm32f0xx.h" #include "stm32f0308_Discovery.h"
#define out0 GPIO_Pin_0 #define out1 GPIO_Pin_1 #define out2 GPIO_Pin_2 #define out3 GPIO_Pin_3 #define out4 GPIO_Pin_4 #define out_GPIO GPIOC
void TM_Delay_Init(void); void TM_DelayMillis(uint32_t millis); void TM_DelayMillis1(uint32_t millis); void TM_DelayMillis2(uint32_t millis);
GPIO_InitTypeDef GPIO_InitStructure ;
uint32_t multiplier;
int main(void) { SystemInit(); SystemCoreClockUpdate(); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOC, ENABLE); /* Configure PA in input mode */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); /*configure PC in output mode */ GPIOC->MODER |= ((GPIO_MODER_MODER0_0)|(GPIO_MODER_MODER1_0)|(GPIO_MODER_MODER2_0)|(GPIO_MODER_MODER3_0)|(GPIO_MODER_MODER4_0)|(GPIO_MODER_MODER5_0)) ; //GPIOC-> GPIO_MODER_MODER8_0 = 0x01; GPIOC->OTYPER &= ~((GPIO_OTYPER_OT_0)|(GPIO_OTYPER_OT_1)|(GPIO_OTYPER_OT_2)|(GPIO_OTYPER_OT_3)|(GPIO_OTYPER_OT_4)|(GPIO_OTYPER_OT_5)) ; //GPIOC->OTYPER = 0x00; GPIOC->OSPEEDR |= ((GPIO_OSPEEDER_OSPEEDR0)|(GPIO_OSPEEDER_OSPEEDR1)|(GPIO_OSPEEDER_OSPEEDR2)|(GPIO_OSPEEDER_OSPEEDR3)|(GPIO_OSPEEDER_OSPEEDR4)|(GPIO_OSPEEDER_OSPEEDR5)); //GPIOC->OSPEEDR = 0x00; GPIOC->PUPDR &= ~((GPIO_PUPDR_PUPDR0)|(GPIO_PUPDR_PUPDR1)|(GPIO_PUPDR_PUPDR2)|(GPIO_PUPDR_PUPDR3)|(GPIO_PUPDR_PUPDR4)|(GPIO_PUPDR_PUPDR5)); while(1) { if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)==1) { GPIO_SetBits(GPIOC,(out0)|(out1)|(out2)|(out3)|(out4)); TM_DelayMillis(7); GPIO_ResetBits(GPIOC,(out0)|(out1)|(out2)|(out3)|(out4)); while (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)==1) { GPIO_SetBits(GPIOC,(out0)|(out1)|(out2)|(out3)|(out4)); TM_DelayMillis1(3); GPIO_ResetBits(GPIOC,(out0)|(out1)|(out2)|(out3)|(out4)); TM_DelayMillis2(22); } } } }
void TM_DelayMillis(uint32_t millis) { /* Multiply millis with multipler */ /* Substract 10 */ millis = 100 * millis * multiplier - 10; /* 4 cycles for one loop */ while (millis--); }
void TM_DelayMillis1(uint32_t millis) { /* Multiply millis with multipler */ /* Substract 10 */ millis = 1 * millis * multiplier - 10; /* 4 cycles for one loop */ while (millis--); }
void TM_DelayMillis2(uint32_t millis) { /* Multiply millis with multipler */ /* Substract 10 */ millis = 1 * millis * multiplier - 10; /* 4 cycles for one loop */ while (millis--); }
void TM_Delay_Init(void) { RCC_ClocksTypeDef RCC_Clocks;
/* Get system clocks */ RCC_GetClocksFreq(&RCC_Clocks);
/* While loop takes 4 cycles */ /* For 1 us delay, we need to divide with 4M */ multiplier = RCC_Clocks.HCLK_Frequency / 4000000; }
Draw a diagram, your explanation and source really lacks any amount of clarity.
http://www.keil.com/forum/60329/
I think that the following condition:
GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)==1
will be false since it looks like you reset the output 0. If that is correct then GPIO_PIN_0 will be 0 and will stay zero in the while loop.
Sorry. I guess you are trying to control the while loop with a GPIO_A input pin
Perhaps you could extend your delays longer and add additional delay right before the second while.
thank you sir for responding in a good way sir i want to check the condition of my input pins in if condition and also in the while condition such that when i make high a single pin my output should be high but not the other pins kindly help me in this as i am not able to get it
You're certainly not able to explain it well. Is there more than one input, like your previous question, or is this something else?
I'll wait for the diagram. It should show the input pin(s), and the expected output states. Also the purpose and timing of any delays. May be you could express this as a table.
Perhaps you can present the question as it was originally presented to you as homework or a project? May be you work with someone who can better explain the requirements. Perhaps your teacher/manager can provide additional support?
You can read multiple pin states via the GPIOx->IDR register, and the outputs via GPIOx->ODR
This sounds like the identical problem one of your class mates asked not too long ago.
Why not cheat together with him/her to leave less traces of the cheating for the teacher to locate?
sir my application 1)i have to give 5 inputs and 5 outputs in which when i make high my 1 input pin my 1st output pin only should be high. like wise for all the other pins. 2)when i make high that pin my output pulse should work for 700ms and after that it should on for 3ms and off for 22ms and this 3ms and 22ms should be repeated continuously. 3)this is my application sir.vice versa for all other pins.
i think you can understand my application now clearly.kindly help me in this application.
Check your inbox. I've sent you an PM with the full solution.
sir i didnt get any mail from you sir kindly send me once again my mail id is adhi.itya@gmail.com
1)i have to give 5 inputs and 5 outputs in which when i make high my 1 input pin my 1st output pin only should be high. like wise for all the other pins.
What is the expected behaviour if more the ONE of the input pins is high?
sir if more the pins are high there is no problem but that is not my application i have to make one input pin and one output pin high.if i make high two inputs two outputs should be high i dont want all other pins to be high.
The way the code seems to be written it looks like your input pin is enabling the sequence of ones and zeros.
But when the input is low the sequence is supposed to stop.
A correct implementation needs to have a specification that considers what the output state should be for each individual output pin for each and every combination of states of the input pins.
If you don't have that information, then you do not have a complete specification. And without a complete specification you can't know what code to write.
let me tell you the application i have 5 input pins let take as switches and my 5 led's as my output when my first switch is "on" my first led should "on(set)" for 700msec and should be low(reset) after that it should be "high" for 3msec and should be "low" for 22msec this loop have to be repeated continuously until my switch is on.vice versa for all the pins.when i make high of any input pin my relevant output should be high not all the pins.
this is my application sir kindly help me in this.
If it was my project I would try the following. First I would need a oscilloscope to view the created signals.
Second, I would obtain a solderless breadboard and wires to wire up the header pins to the bread board.
I would wire up the following pins as input
Inputs P1.15 PA0 P1.16 PA1 P1.17 PA2 P1.18 PA3 P1.21 PA4 P1.22 PA5
Outputs P1.27 PB0 P1.28 PB1 P1.29 PB2 P2.11 PA3 P2.10 PA4 P2.9 PA5
and GROUND AND THREE VOLTS
P1.1 3 Volts P1.2 GND
All this information can be checked by looking at the schematic.
Then inputs can be set hi or low on the Breadboard as required.
then in a loop you can read the input pins as a 32 bit word.
I think you can take that word and write it to the outputs to set/reset the outputs as the inputs are configured (timed as needed).