2008-03-16 10:39 PM
2011-05-17 12:50 AM
Hi,
i am just getting started on the STR912FW44x, and have a big problem. I just want to read the state of GPIO pins 7.4-7.7 (which have pushbuttons connected to them, pressed = grounding). I believe I have initialized everything correctly, but (in the unpressed state) the pins still read as low even though they are high (I have double-checked with a multimeter). If I check the GPIO DATA registers using my debugger, they too show that GPIO7 has all pins low. Can somebody give me any hints as to what is going on here? I have the STR912F Eval board from Hitex, see: http://www.hitex.com/products.html?con_arm_evaluation_board_str912.html~content Plus the debugger and everything listed here: http://www.hitex.com/con_arm_starter_kit_str9.html My toolchain is the Hitop IDE + GCC. my main.c: #include ''91x_lib.h'' GPIO_InitTypeDef GPIO_InitStructure; int main() { int foo; /* GPIO Configuration -----*/ //GPIO 8 controls the LED segment display GPIO_StructInit(&GPIO_InitStructure); GPIO_DeInit(GPIO8); GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All ;//0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3; GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; GPIO_Init (GPIO8, &GPIO_InitStructure); //GPIO9 controls a transistor for activating the entire led display. write 0 to activate. GPIO_StructInit(&GPIO_InitStructure); GPIO_DeInit(GPIO9); GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All ;//0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3; GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; GPIO_Init (GPIO9, &GPIO_InitStructure); GPIO_WriteBit(GPIO9, GPIO_Pin_0, Bit_RESET); GPIO_WriteBit(GPIO9, GPIO_Pin_1, Bit_RESET); //GPIO7 has pushbuttons connected to 7.4-7.7. button pressed = pin low. otherwise // high thanks to a pull-up resistor. GPIO_StructInit(&GPIO_InitStructure); GPIO_DeInit(GPIO7); GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; GPIO_Init (GPIO7, &GPIO_InitStructure); GPIO_WriteBit(GPIO8, GPIO_Pin_All, Bit_SET); //all led segments OFF foo = 1; //default state is button not pressed (GPIO HIGH) while(1) { //foo = (((GPIO7->DR[GPIO_Pin_5< foo = GPIO_ReadBit(GPIO7, GPIO_Pin_5); //read pin GPIO_WriteBit(GPIO8, GPIO_Pin_2, foo); //if pin low (button pressed), a LED segment will lit up } } I would be extremely thankful for any help I can get. I have been trying to solve this problem for several days now I I just can't find the problem! [ This message was edited by: pontus.froessander on 08-05-2008 11:16 ]2011-05-17 12:50 AM
The input pins need to be configured for open drain instead of push-pull.
2011-05-17 12:50 AM
You will also need to write a '1' to the port pin before reading it back. In open drain mode there is an internal FET switch to pull the pin low. The '1' turns off that FET.
In push-pull there's an additional FET to pull the pin hi, most likely why you see a bad reading. Don't leave the pin in P-P mode as you have an output driver driving a ground when the switch is closed to ground. Lots of wasted current that way.2011-05-17 12:50 AM
Thanks for your reply. I tried the following code:
//GPIO7 has pushbuttons connected to 7.4-7.7. button pressed = pin low. otherwise // high thanks to a pull-up resistor. GPIO_StructInit(&GPIO_InitStructure); GPIO_DeInit(GPIO7); GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Type = GPIO_Type_OpenCollector ; GPIO_Init (GPIO7, &GPIO_InitStructure); GPIO_Write(GPIO7, 0xFF); But it still doesn't work! I also tried writing a 1 to the port but in push-pull mode. Oh and I also tried doing it both before and after initializing the port. Argh - I am slowly going crazy :). More tips :)?