cancel
Showing results for 
Search instead for 
Did you mean: 

To define macro to set and clear the pin

Lchal.1
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Ozone
Lead

Macros are not a good solution anyway.

Why not using inline functions ?

View solution in original post

7 REPLIES 7
KnarfB
Principal III

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

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

Thank you

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.

Mayank1
Associate II

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

Ozone
Lead

Macros are not a good solution anyway.

Why not using inline functions ?

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

Lchal.1
Associate II

Thank you