2009-12-01 04:07 AM
Standard library
2011-05-17 06:06 AM
Code:
BitStatus bitstatus = GPIO_ReadInputPin(GPIOD, GPIO_PIN_0);
This will return RESET or SET, which are HIGH and LOW values.Code:
GPIO_DeInit(GPIOD);
GPIO_Init(GPIOD, GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_FAST); GPIO_Write(GPIOD, (u8) !bitstatus);How do I write it back to the _SAME_ pin? I'm not sure what this is doing, but if I attach another LED to GPIOD pin 1, will that second LED have the same action as PIN 0? What is the correct way to write a variable to a _single_ pin? Thanks. (I'm with the discovery, btw)2011-05-17 06:06 AM
if I understand you need to toggle the GPIOD pin 1 so you can use directly
GPIO_WriteReverse(GPIOD, GPIO_PIN_0); instead of: BitStatus bitstatus = GPIO_ReadInputPin(GPIOD, GPIO_PIN_0); GPIO_Write(GPIOD, (u8) !bitstatus); when bitstatus is reset ==> !bitstatus = 0xFF so you write in all GPIOD pins You can use this function that give you the possibility to write only in the needed pins: void GPIO_WriteBit(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, BitAction GPIO_BitVal) { /* Check the parameters */ assert_param(IS_GPIO_PIN_OK(GPIO_Pin)); assert_param(IS_STATE_VALUE_OK(GPIO_BitVal)); if (GPIO_BitVal != RESET) { SetBit(GPIOx->ODR, GPIO_Pin); } else { ClrBit(GPIOx->ODR, GPIO_Pin); } } GPIO_WriteBit(GPIOD, GPIO_PIN_0, (u8)!bitstatus); Regards mozra2011-05-17 06:06 AM
2011-05-17 06:06 AM
Quote:
On 01-12-2009 at 15:58, Anonymous wrote: if I understand you need to toggle the GPIOD pin 1 so you can use directly GPIO_WriteReverse(GPIOD, GPIO_PIN_0); instead of: BitStatus bitstatus = GPIO_ReadInputPin(GPIOD, GPIO_PIN_0); GPIO_Write(GPIOD, (u8) !bitstatus); when bitstatus is reset ==> !bitstatus = 0xFF so you write in all GPIOD pins You can use this function that give you the possibility to write only in the needed pins: void GPIO_WriteBit(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, BitAction GPIO_BitVal) { /* Check the parameters */ assert_param(IS_GPIO_PIN_OK(GPIO_Pin)); assert_param(IS_STATE_VALUE_OK(GPIO_BitVal)); if (GPIO_BitVal != RESET) { SetBit(GPIOx->ODR, GPIO_Pin); } else { ClrBit(GPIOx->ODR, GPIO_Pin); } } GPIO_WriteBit(GPIOD, GPIO_PIN_0, (u8)!bitstatus); Regards mozra I have tried this code but I'm getting an error, ''Invalid parameter declaration''.Quote:
On 01-12-2009 at 17:32, Anonymous wrote: Hello, in case you don't use the libraries, the syntax is even more simple:Code:
<BR>volatile char PD_ODR @0x500f; /* Data Output Latch reg */ <BR>volatile _Bool PD1 @PD_ODR:1; <BR>void testDP1(void) <BR> { <BR> PD1 = 1; // set bit <BR> PD1 = 0; // reset bit <BR> if (PD1) // test for 1 <BR> PD1 = 0; <BR> if (!PD1) // test for 0 <BR> PD1 = 1; <BR> PD1 ^= 1; // complement <BR> } <BR> and the code generated probably more straighforward (but I haven't checked; maybe if someone posts the code generated for the library calls we can compare). Regards, Luca [ This message was edited by: _luca on 01-12-2009 17:33 ] Thanks.2011-05-17 06:06 AM
Hello,
in case you don't use the libraries, the syntax is even more simple:Code:
<BR>volatile char PD_ODR @0x500f; /* Data Output Latch reg */ <BR>volatile _Bool PD1 @PD_ODR:1; <BR>void testDP1(void) <BR> { <BR> PD1 = 1; // set bit <BR> PD1 = 0; // reset bit <BR> if (PD1) // test for 1 <BR> PD1 = 0; <BR> if (!PD1) // test for 0 <BR> PD1 = 1; <BR> PD1 ^= 1; // complement <BR> } <BR>
and the code generated probably more straighforward (but I haven't checked; maybe if someone posts the code generated for the library calls we can compare). Regards, Luca [ This message was edited by: _luca on 01-12-2009 17:33 ]