I would say that if you think you have had to replace both camshaft sensors and didn't resolve that 340 code, you may be just tossing parts at your engine playing a guessing game costing you money. OBD codes come up with just general information sometimes not even giving you the right clues. I would be looking at electrical connections including the crankshaft position sensor. There is a possibility that the crankshaft position sensor is not functioning or its electrical connection isn't making good contact. The crank and camshaft sensors work together as a set when information is fed into the ECM.
This is a general explanation of how the system works:
The Camshaft Position Sensor is an electronic device used in an engine to record the rate at which the camshaft is spinning. This information is used by the Engine Control Module(ECM) to control ignition and fuel injection. The camshaft position sensor senses the retraction of camshaft (intake) to identify a particular cylinder. The camshaft position sensor senses the piston position. The sensor system consists of a rotating part, typically a disc, as well as a static part, the actual sensor. When the engine is running, the high and low parts of the teeth cause the gap with the sensor to change. The changing gap causes the magnetic field near the sensor to change. The change in the magnetic field cause the voltage from the sensor to change. When the crankshaft position sensor (POS) system becomes inoperative, the camshaft position sensor provides various controls of engine parts instead, utilizing timing of cylinder identification signals.