This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

LPC23xx gpio code

Hello,
Can someone explain what it means??

#define IOPIN0 (*(volatile unsigned long *)(GPIO_BASE_ADDR + 0x00))

The controller using is LPC23xx/24xx.

BR Chethan

  • Standard C pointer cast, telling the address of a volatile 32-bit register at a specific address that should be used with the name IOPIN0.

    So the address - as an integer - is said to be a pointer to volatile 32-bit unsigned, and the macro then does a pointer indirection to "follow" the pointer to allow you to either read or write that register.

    So bring out a decent book about the C language - or even better the language standard - and have a look at type declarations and type casts.

  • "The controller using is LPC23xx/24xx"

    And since when was that a C166?

    It's all just standard 'C' syntax - not specific to Keil, C166, ARM, or anything else.

    So which bit, exactly, don't you understand?

  • Hi Westermark,

    Thanks for the reply.

    Based on your explanation what i understood is : that address is trying to making as a type of pointer (in this case 'volatile 32-bit integer pointer' and it can be dereferenced) is it correct???

    Chethan

  • Not only can it be dereferenced. It already is.

    The middle * is for the type cast from integer to pointer.
    The left-most * is the dereference being done.

    So you can use IOPIN0 as if it was a normal 32-bit volatile unsigned integer. You can read from it and you can write to it.

    So the construct is kind of placing a variable at an absolute address, but without involving any link-time symbol - the generated code will instead get the hard-coded address of that processor special function register.

  • Ya got it now!!

    In this case why we using volatile.....is their any special purpose??

    Chethan

  • Haven't you looked at the description of the volatile keyword?

    What is the difference between a normal memory variable and a register mapped to real hardware? When may a memory variable change content? When may a I/O register associated with processor pins change value? Would that matter to the compiler, when it generates the processor instructions?

  • Actually i know the concept.

    Volatile is used to modify the memory content is existing in different file.

    Is it correct ???

    For remaining questions i don't have much deep knowledge. Kindly explain me those things also it looks to be interesting :) :)

  • No. You really should read up about volatile.

    You seem to think about external declarations, which is something completely different.

    Didn't you consider the hints I left about the need for volatile because of the difference between a normal RAM variable and a special function register? Volatile is even part of non-technical English. Nitroglycerin is volatile, as is the situation in Ukraine.

  • (making allowances for English as a foreign language)

    Well, one common use of the 'volatile' qualifier is to indicate that memory content may bechanged by "another file".

    So think how a hardware SFR (special function register) might have similar issues...