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.

changing pinmuxing during runtime

When pinmuxing is changed during runtime, does the previously selected bit need to be cleared before a new bit needs to be set?

So after you unlock the registers, if originally alternate function 2 was selected, but you want to change it to the default function, can you just OR a 1 in the correct bit position to the proper register?  Or do you need to clear the bit for function 2, and then set the bit for the default function?

Thanks,

Dave

  • As soon as both bits are set, the pin goes to the default function. Therefore just OR'ing in the bit for the default function is sufficient to change the input mux. However going the other way, you will need to clear the bit for the default function to switch to alternate function 2. Whenever you have an "invalid' selection, such as no function selected, or more than one function selected, the output changes to the default function. Personally, I would clear the alternate function 2 bit in the code just so not to confuse the next person who reviews the code. (Also prevents the very unlikely possibility of a register bit soft-error flipping the output back to alternate function 2.)