Code P0340 - a problem with the electrical wiring of the circuit to the camshaft sensor. So, I would look at the electrical connector for the camshaft sensor, here is the location of the sensor so you can check it out. Also, you might want to try a bottle of Lucas oil treatment, we have good luck with it.
If the connection seems okay, I would replace the sensor. Check out the images (below). Let us know what happens and please upload pictures or videos of the problem.
Images (Click to enlarge)
Monday, November 14th, 2022 AT 9:40 AM