Slept weird, ended up with a strained muscle on my middle left side with spasms off and on

I had similar things happen before, the night times were crazy due to spasms keep waking me up. How do I get more sleep with this thing and what position is best to sleep on?