Sex can be painful during pregnancy for a number of reasons, and most of these will disappear when you are no longer pregnant. Vaginal dryness is probably the most common reason, and this is due to hormonal imbalances during pregnancy. The best way to alleviate this is to use an artificial lubricant such as KY jelly. I assume you have had a high vaginal swab taken to eliminate an infection as the cause, because this is the second most common reason for dyspareunia (painful sex). Other causes are less common and would need referral to a gynaecologist. I would suggest that if this problem doesn’t resolve after your baby is born that you mention it at your six-week postnatal check.
Although you’ve obviously managed this far into your pregnancy, I hope that you have an understanding and patient partner, if sex becomes too unbearable. Thankfully there are plenty of other ways to enjoy sex without penetration! I wish you well.