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.

What's the difference between SET/CLEAR registers and DATA registers for GPIO

We can set/clear GPIOs using

GpioDataRegs.GPADAT.all    =0xAAAAAAAA;

or

GpioDataRegs.GPASET.all    =0xAAAAAAAA;

I am curious to know the difference - I always use SET/CLEAR but one of my team members asked me the difference last night and I didn't have a good answer [:D]

When one will use one method over another?

  • Arefeen,

    For doing an "all" access like that they are pretty much the same.  If you do a read-modify-write access then you can have issues using DAT registers.

    • The DAT registers read the value on the pin itself - not the output latch (except on 281x devices where it reflects the latch and not the pin value)
    • SET/CLEAR registers always read back 0

    For the DAT register there is a lag between when the register is written to when the new pin value is reflected back in the register. This may pose a problem when this register is used in subsequent program statements to alter the state of GPIO pins. Section 6.1.2 of the application note Programming TMS320x28xx and 28xxx Peripherals in C/C++ describes this in more detail.  www.ti.com/lit/spraa85

    -Lori

     

     

  • Hello Lori - This clears the issue the engineer was experiencing with DAT but not with SET/CLEAR. Thanks for clarifying the topic.