Hi and welcome to Healthcare magic.Thank you for the query.
It can be caused by ulcer but also some lung disorders as well. You should take antiacid medicines and do gastroscopy to evaluate your stomach condition. Also, you need chest xray to see is there any rib fracture
or lung inflammation.
Wish you good health. Regards