Hello! I have a 2000 Nissan Frontier, 3.3L, 145000 AT. It rough idles and it stalls. After the third time it will stay on while shaking and as it warms up it works but it misfires and shakes. I got code P0340. I changed the crank shot sensor with after market ones 2 times but it is still the same. Then I checked the new sensors and the old one for resistance.Motor Rad sensor showed 721; Beck Arnley 660; the original one 555, although this one has a slight bump on the bottom of the metal part of the sensor. I checked the connector for continuity and it shows 1 and no beep. Is the ground bad? how do I fix that? What else could it be? Thank you!
That's a camshaft position sensor code and even though it could be set by a faulty crankshaft position sensor, in your case it wasn't.
On yours the camshaft position sensor is inside the distributor.

Check the wiring connection on the distributor for corrosion. If it looks good then you'll have to replace the distributor. You can find them online for under $100.
Also, put the original crankshaft position sensor back in.

Thank you for your answer. I did replace the distributor with a new one, a couple a weeks ago and I am still getting the code.