You may need to contact local Ausländerbehörde
usually there is a procedure to request longer leave without losing your German residence permit, which shall only be required if you leave for more than 12 months. For that, you would need to apply in advance to the local Auslanderbehörde (ABH), they then shall issue you a paper stating your longer leave is granted.
For the Blue Card you may get asked whether your stay abroad is happening before you have it for 18 months or not.
However, in your case, your stay in Spain seems to be work travel, and I think it should be addressed as such. You'd need to process the standart documentation package as if you are leaving for a conference that is held outside Germany. Your travel costs should be reimbursed by your host institution, including any incurred visa fees, transport, accomodation and living costs. It is best to find a relevant HR person and direct your questions on how to formally address this there.
It is also well worth involving your International Office so they could check with the ABH officials for you on how to treat such business trip, and how to make sure you're not running into trouble with your Blue Card.