Skip to main content
Visitor II
December 1, 2009
Question

Standard library

  • December 1, 2009
  • 5 replies
  • 1307 views
Posted on December 01, 2009 at 13:07

Standard library

    This topic has been closed for replies.

    5 replies

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:06

    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)

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:06

    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

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:06

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:06

    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.

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:06

    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 ]