it's probably covered somewhere, but I just cant seem to find the right search phrases.
I need to switch a port from input to output (repeatedly) without generating any spikes. So my plan is to read the current value fromt the input and write it to the output latch while the port is still in input mode, then switch to output.
The code for this obviously looks like this:
// Switching to output mode
PTAD_PTAD0=PTAD_PTAD0; // Write current value to output latch
PTADD_PTADD0 = 1; // Switch port direction to output
The compiler will generate a warning "Result not used", which is ok, the first expression does of course seem pretty useless.
I did not check the generated assembly instructions yet, so I do not know if the compiler really wipes out the whole instruction (I guess it should not, since the registers should be declared volatile?)
So, my question is, what is best practice here?
Am I simply supposed to ignore the warning?
Is CW supposed to not generate a warning since it's a volatile declared thing?
Should I read the input value to a temporary variable before writing it back to the port?
Is there any suggested way to do it "right"?
Thank you very much,