This is from OBD-Codes.com. It might help, but maybe not. At least you might get a better handle on the problem with more information. It looks like you are the right track with the Cam Pos Sensor but a problem could lie anywhere on that circuit.
========================================================================================================
This diagnostic trouble code (DTC) is a generic powertrain code. It is considered generic because it applies to all makes and models of vehicles (1996-newer), although specific repair steps may be slightly different depending on the model. So this engine code article applies to Nissan, Ford, Toyota, Chevrolet, Dodge, Honda, GMC, etc.
This P0340 code indicates that a problem was detected in the camshaft position sensor circuit.
Since it says circuit, that means the problem could lie in any part of the circuit - the sensor itself, the wiring, or the PCM. Don't just replace the CPS (camshaft position sensor) and think that will definitely fix it.
Symptoms
Symptoms can include:
Hard starting or no start
Rough running / misfiring
Loss of engine power
Causes
A code P0340 could mean one or more of the following has happened:
a wire or connector in the circuit could be grounded/shorted/broken
the camshaft position sensor may have failed
the PCM may have failed
there exists an open circuit
the crankshaft position sensor may have failed
Possible Solutions
With a P0340 OBD-II trouble code, diagnosis can be tricky at times. Here are some things to try:
Visually inspect all the wiring and connectors in the circuit
Check for continuity in the circuit wiring
Check the operation (voltage) of the camshaft position sensor
Replace the camshaft position sensor as required
Check the crankshaft position circuit as well
Replace circuit wiring and/or connectors as required
Diagnose/replace the PCM as required