1. He called me when I was in bed.

2. He called me while I was in bed.
(Are both grammatical? Then what is the slight difference in meaning between the two sentences?)

Both are correct. I see no difference in meaning between the two.