Roughly speaking, いつ is used as an interrogative or for interrogative clauses, whereas とき is for adverbial clauses.
When did you come to Japan?
いつ日本に来たんですか?
I don't know when he came to Japan.
彼がいつ日本に来たのか知りません。
When he came to my house, I wasn't there.
彼がうちに来たとき、僕はいませんでした。