Skip to main content
Lchal.1
Associate III
Feb 2, 2021 11:49 AM UTC
Solved

To define macro to set and clear the pin

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.
Ozone
OzoneBest answer
Principal
Feb 3, 2021 6:22 AM UTC

Macros are not a good solution anyway.

Why not using inline functions ?

7 replies

KnarfB
Super User
Feb 2, 2021 12:56 PM UTC

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

Lchal.1
Lchal.1Author
Associate III
Feb 3, 2021 3:42 AM UTC

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

Thank you

KnarfB
Super User
Feb 3, 2021 5:46 AM UTC

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
Feb 3, 2021 6:04 AM UTC

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
OzoneBest answer
Principal
Feb 3, 2021 6:22 AM UTC

Macros are not a good solution anyway.

Why not using inline functions ?

Mayank1
Associate II
Feb 3, 2021 6:26 AM UTC

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

Lchal.1
Lchal.1Author
Associate III
Feb 6, 2021 4:24 AM UTC

Thank you