Skip to main content
Visitor II
February 2, 2021
Solved

To define macro to set and clear the pin

  • February 2, 2021
  • 4 replies
  • 3143 views

HI, I am using Macro to set and clear my pin using stm32f103. This is the macro i defined

#define SET(PIN,N) (PIN |= (1<<N))

#define CLR(PIN,N) (PIN &= ~(1<<N))

where ,

  • PIN is the value whose bit to set or/and clear
  • N is the bit number to set or/and clear

i have done the code like,

if(Drive _Enabled==1)

{

Status _Register[2] = SET(1,0);

}

//Status _Register[2] = CLR(1,0);

 if(drive_ motion _complete==1)  //to read whether motion is complete or not

    {

     Status _Register[2] = SET(1,1);

    }

but i am getting error can anyone help me how to solve this error and what i need to add to my code please.

i have attached the picture showing the error below.

    This topic has been closed for replies.
    Best answer by Ozone

    Macros are not a good solution anyway.

    Why not using inline functions ?

    4 replies

    Super User
    February 2, 2021

    Always start inspection with the first error, which is not visible...

    Lchal.1Author
    Visitor II
    February 3, 2021

    sorry , but i did not understood what you said . Please can you explain it to me .

    Thank you

    Super User
    February 3, 2021

    Scroll up the Console View such that the first lines are visible and make a new screen shot if you cannot decipher the first error message yourself.

    Visitor II
    February 3, 2021

    please define your macros like this :

    #define SET(PIN, N, OUT) (OUT = PIN | (1<<N))

    #define CLR(PIN, N, OUT) (OUT = PIN & ~(1<<N))

    You need an extra parameter (OUT) to store the rValue calculated by the macro function.

    store OUT in your status register

    OzoneAnswer
    Explorer
    February 3, 2021

    Macros are not a good solution anyway.

    Why not using inline functions ?

    Visitor II
    February 3, 2021

    @Ozone​ I completely agree with you. Inline functions are always good to have rather than macros.

    Lchal.1Author
    Visitor II
    February 6, 2021

    Thank you