This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Problem in using bit-specific addressing in LM4F/TM4C

Hello,

I'm using the Tiva C series launchPad with TI TM4c123GXL MCU. I've a proble using bit-specific addressing.

I first define port E1 as:

#define PE1 (*((volatile unsigned long *)0x40024008))

Setting PE1 to '1' using

PE1 = 0x20; don't set such pin but using 

PE1 = 0x02 does the job, so where is the correct definitions for port pins??

Thanks & best regards,

Moataz Fouad

  • Hello Moataz,

    The GPIO Data registers use the address as a data mask to allow specific bits to be updated without affecting other bits. In this case PE1 is defined as 0x40024008 and if you take the offset of 0x008 and map it using ADDR[9:2] it would be 00.0000.10 meaning that a write to bit holding 1 will have an effect on the actual pin.

    In case you want to be able to modify all pins then the address mask would be 0x3FC and which would make the define as 0x400243FC

    Regards

    Amit

  • And - should time & effort conservation blip your radar - you may well consider vendor's detailed, simplified, "Peripheral Driver Library."   (PDL)

    The fact that - under Peripheral Driver Library - setting any GPIO bit to "1" (other than bit 0) does not drive that output "high" - takes some time to digest & accept.  That said - the 2nd parameter masking function (w/in gpio writes) proves quite useful.

    Technique poster Amit provided fits under, "bit-banding" - it's covered w/in the MCU manual, GPIO Section.  It is both powerful and complex - and usually is employed, "downstream" - when most users can far better profit from its extra capabilities...

    The exhaustive MCU manual will well guide you.  We find that both it and the PDL - open & ready on our desktops - aids greatly.

    To specifically address your, "Bit-specific Addressing" subject/title I provide this example:  (via PDL)

    GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1, GPIO_PIN_1);  // sets only your, "bit specific" (PE1 here)

    GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1, 0);  //  this clears only that, "bit specific" addressed bit

    2nd Parameter in function above, "GPIO_PIN_1" provides the specific "masking/addressing" you sought.  To my group's mind - so much simpler/easier than dealing w/"famed" 0x3FC.  (You may place "0xFF" to include all 8 bits)

    Note that GPIO_PIN_x follows normal/customary bit-position weighting scheme.  (bit 0 = 1, bit 1 = 2, bit 7 = 128 etc.)

    Adding to the fun - while this answers your specific request - further set-up/config of that MCU port is required.  Such detail reveals nicely w/in PDL and many vendor supplied programming examples...