The reason you may only sometimes be getting a code is because the EGR will only activate under certain conditions. For example, engine must be warmed up to a certain temp, transmission may have to be in a certain gear, or cruise speed/engine rpm must be within a certain range. Basically, these conditions only get met when cruising at light throttle on the highway. Your truck is not seeing an issue with the EGR system until it commands it to operate, and is either not getting the proper reaction from the EGR valve/solenoid, or the PCM is not detecting the needed runability changes when the EGR activates properly.
Here is a great write up that should walk you right through troubleshooting your EGR system:
http://www.chevytalk.org/fusionbb/sh...php?tid/258416