For many centuries, the Iberian peninsula was split into many Christian and Muslim states. For their histories, see:
The unification happened gradually: Granada was conquered in 1352 by Castille after it had missed a tribute; Portugal also was swallowed by Castille after the Portuguese Civil War, in 1424; Navarre had been united with Aragon. Castille-Portugal became a part of the Quadruple Monarchy in 1497, after being inherited by Edward V. In 1599, Aragon-Navarre was divided between the (now) Triple Monarchy and France.
Under the Plantagenets
During the unification, many English traders immigrated to Iberia, replacing the Jews who were kicked out.
King Henry VI managed to bring up the Iberian nobles up against himself (actually, it was started by the relatives of his wife), which ended with the Castillians and Portuguese declaring themselves independent in 1628. The Castillian Civil War took place 1628-34; France supported uprisings in Valencia (Aragon south of Ebro river) and Portugal. Despite of all the chaos and the many factions, the new king Alfonso XII (former duke of Aliaga) managed to defeat all enemies, keep himself on the throne and also subdue the Aragonese rebels in Valencia. Morocco, however, stayed independent, under the former duke of Monteleón, as did Sicily.
In 1630, the army of the Cortes defeated the English army landed at Santander; now, the independence of Spain was secured. Even better, Spain managed to take the English colonies in Central Atlantis after the won sea battle of Jamaica.
1639, Maria, the princess of Spain and future queen (her father Alfonso XII had no son) married the king of Morocco (not acknowledged by Spain), Francisco of Monteleón. While he bragged at the beginning how he was going to "bend that weak woman", the contract she negotiated with him at the end gave her actually the possibility to co-govern in Morocco, while he had nothing to say in Spain or its colonies in Atlantis. She also managed to appoint her younger, but more competent son Héctor I successor in 1665, sending her older son Francisco as governor to Morocco instead.
The opposition to France soon drove Spain into an alliance with England and Sicily, negotiated with help from the Netherlands and Sweden under queen Kristina I. At the end, the anti-French War during 1682-94 was victorious for Spain which fought many battles in Europe and Atlantis, getting all of Portugal, the lands between Ebro and Pyrenees and the colonies of Virginia and Mexico in the peace of Amsterdam.
The Mexican gold had similar effects as in OTL, only later and not that extremely: Many Spaniards got very rich, but the country also started to suffer under inflation with time. The Basques and Catalonians weren't completely happy with the new situation either.
In 1763, France had declared the republic. Many monarchists called for a "crusade" against France. After the hot-headed Humphrey V had come to power in Britain, he and similar-minded Héctor III started the French Republican Wars. They were horribly trounced, and in the peace of Brussels 1772, Spain lost the lands north of the Ebro again. King Francisco I was saner, but couldn't prevent the defeat in the second French Republican War and the loss of Valencia (southern Aragon) and Portugal in the peace of Basel.
After the king's death, the even more fanatical Francisco II came to power and threw the country into the third French Republican War. As a consequence, Spain was dismembered in 1793, and the Monteleón dynasty had to flee to Morocco.
The "Ninety-Year War"
With British support, Spanish monarchists repeatedly tried to make landings in Spain to support uprisings. While all of them were crushed, the never-ending war bled France dry and wasted its money. Thus, France was almost happy when during 1838-40, Morocco wasd conquered by the new empire of New Rome after a Muslim uprising. However, the discontent in Spain continued.