Mexico's peso weakened on Tuesday on doubts that stock markets will keep rising because of worries about the strength of a global economic recovery.

The peso MXN=MEX01 lost ground for the second straight session, weakening 0.54 percent to 13 per U.S. dollar.

The IPC stock index .MXX ended almost unchanged at 28,005.46 as a surge in home builders was offset by the second straight session of steep losses in some of the IPC's less-liquid shares after regulators gave pension fund managers greater freedom on stock selection.

The peso firmed as strong as 12.8395 per dollar early in the session as reports showed rising consumer confidence and housing prices in the United States, Mexico's top trading partner.

But the currency slipped back as other emerging market currencies like the Brazilian real BRBY sank and oil prices dropped.

We need another leg in the stock market and commodities rally to inject some optimism into the market, said Ramon Cordova, a trader at Base brokerage in Monterrey.

Mexican stocks have been unable to push much higher than 28,300 points since early August after gaining some 65 percent from their March bottom.

Mexico sends more than 80 percent of its exports to the United States and hopes that U.S. consumers will start spending again are key to Mexico's recovery from its deepest recession since the 1930s.

The peso firmed to a nine-month high earlier this month, helped by bets Mexico's close trading ties with the United States could help it benefit more from a U.S. recovery.

But further gains have been limited and some are expecting the peso will lose more ground in the coming session.

People are starting to be very cautious ahead of September and October, which are always really bad months, and given how much markets have moved since March, we are about to see some profit taking, said Francisco Diez, director of emerging market trading at RBC Capital Markets in Mexico City.

In stock trading, shares in home builder Geo (GEOB.MX) gained 6.91 percent to 30.93 pesos after Morgan Stanley upgraded the stock to overweight on new management and positive outlook for local builders.

Electronic appliance dealer Elektra (ELEKTRA.MX) shed 8.26 percent to 501.32 pesos, and Inbursa (GFINBURO.MX), the bank controlled by billionaire Carlos Slim, gave up 4.76 percent to 35.62 pesos. (Reporting by Michael O'Boyle; Editing by Leslie Adler)