2010-12-29 03:13 PM
Hello,
I want to write a program to make his test on the value of a vector.
is that there is another simpler solution??
GPIO_DeInit(GPIOB);
GPIO_Init(GPIOB, GPIO_PIN_0, GPIO_MODE_IN_PU_NO_IT);
GPIO_Init(GPIOB, GPIO_PIN_1, GPIO_MODE_IN_PU_NO_IT);
GPIO_Init(GPIOB, GPIO_PIN_2, GPIO_MODE_IN_PU_NO_IT);
if (((GPIO_ReadInputData(GPIOB) & GPIO_PIN_0)== 0)) &(((GPIO_ReadInputData(GPIOB) & GPIO_PIN_1)== 0))&
(((GPIO_ReadInputData(GPIOB) & GPIO_PIN_2)== 1))
{
//do operation 1;
}
else
if (((GPIO_ReadInputData(GPIOB) & GPIO_PIN_1)== 0)) &(((GPIO_ReadInputData(GPIOB) & GPIO_PIN_1)== 0))&
(((GPIO_ReadInputData(GPIOB) & GPIO_PIN_2)== 1))
{
// do operation 2;
}
........
........
........
........
else
operation n;
2009-12-31 07:02 PM
That's the kind of thing - but don't you think that a switch statement might be more approrpriate...?
2010-12-29 05:06 PM
You can read the entire port as an 8-bit value...
2010-12-30 03:58 AM
thank you for your answer.
did you mean:
if (((GPIO_ReadInputData(GPIOB) ==0x00 ))
{
Operation 1
}
else if (((GPIO_ReadInputData(GPIOB) ==0x01 ))
{
Operation 2
}
else if (((GPIO_ReadInputData(GPIOB) ==0x10 ))
else
{
Operation n
}
2011-01-03 01:11 AM
yes, it's just I have a few problems on the levels of reading data and syntax specific STM8S.
Thank you
2011-01-04 06:23 AM
There is no syntax here specific to th STM8!
As far as syntax is concerned, you are just calling a function that returns an integral value!2011-01-04 03:40 PM
yes you are right, it's a function call already defined.
Another question I tried with the other method but it does not work.
how to read the value of a port initialized as inpout.
Thank you
2011-01-05 01:45 AM
''I tried with the other method''
What other method? ''but it does not work''
Saying, ''it does not work'' is never useful. You need to state precisely what you did, what you expected to happen, what actually happened, and what steps you have taken to explain the difference.
''how to read the value of a port''
Isn't that exactly what GPIO_ReadInputData does?!
2011-01-05 04:52 AM
I meant: I connected a sensor to port B which gives a value of 5 bit. with
this value I will make the selection of outputs.
for(;;)
{
switch(GPIO_ReadInputData(GPIOB) )
{
case 0: instruction 0; break;
case 1: instruction 1; break;
..
..
..
..
case 31:instruction n; break
default: instruction; brek
}
}
no problems with the compilation and debug.
but every change of value of port B: I find no valid output
2011-01-08 09:11 AM
What debugging have you actually done?
It would be a lot easier to debug if you read the value into an intermediate variable:
port_b_value = GPIO_ReadInputData(GPIOB);
switch( port_b_value ) ''but every change of value of port B: I find no valid output''Pardon? Note that you are constantly reading the value of port B, and running the switch() on it; Wouldn't it be better to just run the switch() when the value has changed...?