CKP's will set P0335, P0336, P0385, P0386 most commonly. The P0340 is the CMP - CaMshaft Position sensor - on the front of the right cylinder head at 6 o'clock relative to the exhaust cam drive sprocket BUT the code is for the sensor circuit, not the sensor performance itself.
All these CKP and CMP codes - Do you have an SES light, misfire detected code(s), is the engine stalling during warmup and low speed coastdown - and are the codes Current or History ?
The P0340 code will not clear it is always current. I have not gotten a missfire code and have no real problems with how the car runs except a bit of a fluctuation at idle and the occasional no start on the first try and then it starts. It acted up bad enough to cause my wife to complain to me the other day and in addition to the P0340 I got one of the P038x codes but I do not remember which one.
I have ordered the crank position sensors and plan to replace them just for piece of mind. I just bought my caddy a couple of weeks ago and the ses light was on when I purchased it.
OK, the P038X also points to a CKP...... here you go. Car up on jackstands, pull the centers out of the plastic lower air deflector rivets and out they (13 ?) come. (You may want to remove the oil filter adapter for room to work). 10 mm wobble socket, two-stage electrical connectors (they have a lock tab).
The originals are one black, one tan, made by Siemens in Mexico (on the connector skirt). New models are black and gray, made by DENSO, Japan. Our post 2000 electrical and mechanical installation will only work one way - the CKP's and electrical connectors are different for that reason.