If they have standing orders like "If you're shot at, shoot back" then there's still potential for trouble. I think that, in the recent incident, South Korea was holding military exercises in or around places that North Korea claims are part of its territory (claims which the rest of the world doesn't recognize), and the exercises included things like shooting at targets. So it doesn't seem that weird for some North Korean guy to go "OMG, they're shooting at us!" when the South Korea military is nearby and shooting.
My theory on why North Korea has stepped up its provocation of South Korea since their nuclear missle tests is that they see this as a tug-of-war.
Suppose that North Korea wants to keep its nuclear weapons program. If they hadn't sunk a ship and bombed a city, world leaders would currently be pressuring North Korea to stop making nuclear weapons. Instead, they're pressuring North Korea to stop doing something (make provocative attacks) that North Korea doesn't really want to do anyway. And when North Korea (temporarily) stops attacking South Korea, everybody can go home and say they "did something about North Korea". And North Korea can keep on making nukes.