Sex and miscarriage

Had a miscarriage 3 weeks ago and recently been getting spotting is it safe to have sex? Or should I wait til it completely stopped?