Short answer to this question is, yes it is possible, but there are a few things you need to know.
I will always start with emphasizing how important it is to do history research for the different areas our ancestors are from. While we all come from countries that were colonized by Spain the experience of our African ancestors could differ. There are the enslaved Ancestors that founded San Basilio de Palenque in Colombia and started one of the first recognized towns founded by former enslaved peoples that were able to obtain freedom before freedom was granted to all. Slavery was also not abolished collectively by the colonies of Spain even as they gained Independence. Please note that gaining Independence from Spain did not equate to the end of slavery in our countries. So all of that is to say, is do the history research to better understand what your African ancestors went through.
Here is a few things to know:
Spain did require for slaves to be converted into the Catholic religion and were baptized. So you can search for your enslaved ancestors in Church records if they are available.
Yes they were times that in certain countries or towns that when they were baptized/married/buried it may not have been recorded.
If recorded some countries kept separate books for Enslaved, Pardos & Blancos, Puerto Rico is a good example of this.
Was it possible to find sometimes former enslaved ancestors in either the Pardos or Blancos books? Yes it was. Due to the high rate of mixing of the races that occurred under Spain, sometimes you will find an Ancestor in the Pardos book and then in the Blancos book. Interpretation was left to the eye of the beholder.
If you find church records for enslaved they may have been recorded with just a first name and the god parents were sometimes their owners. But looking at the information closely and in getting to know the family unit you may be able to identify your Ancestor. (Remember we start from most current and up so when you get to a very early generation you should be pretty familiar with the family).
Did enslaved Ancestors always keep their masters last names? Often but not always.
Is it unusual to see former enslaved Ancestors to see them be free before emancipation? No it is not, slaves in the Spanish colonies sometimes were able to buy their freedom, sometimes they were freed by their master after their master's passing. Also in the case of Puerto Rico the people that were fighting to abolish slavery would wait outside of the churches when the babies were baptized and would pay for their freedom.
Is it possible to identify the Ancestor that came from Africa? Rare but it can happen. Even after 1808 when it became illegal to transport slaves out of Africa in to the colonies, there was still a big black market for it. One of the last known ships to have landed in Puerto Rico was in 1859.
Start with FamilySearch and see if there are Church Records available for your area of research. Make sure to go to the Card Catalog and the Wiki Pages. Don't forget the Affiliate Libraries (often your local Public Library) and Family History Centers.
Search online if there are special projects, genealogical societies, university libraries. Some of them may have online databases or genealogical books that you can purchase.