The Spanish government has indicated that it plans to push negotiations to join NATO next year, a move raised the controversial issue one week before President Carter's scheduled visit here.

The sudden government drive to join the Atlantic Alliance produced angry opposition protests and charges that Carter's visit was designed to produce pressure for Spain's NATO membership.

American officials here have sought to avoid any public comments on the issue which, they contend, is something for Spaniards alone to decide. But the timing of the government's NATO campaign could make Carter's June 25 visit here unexpectedly controversial.

Foreign Minister Marcelino Oreja, in a weekend briefing for journalists, linked the government's drive to join NATO to recent efforts by French President Valery Giscard d'Estaing to delay a parallel Spanish drive to join the European Common Market.

Giscard infuriated Spanish public opinion Earlier this month when he urged that the European Community not be enlarged before current difficulties among its nine members are resolved. Spain and Portugal are currently negotiating with the Common Market and were expected to sign the treaty of accession in January 1983.

Oreja said that Giscard's rebuff could only play into the hands of those who want Spain to pursue a nonaligned foreign policy, a course advocated by socialist and leftist groups here. The socialist opposition accepts the necessity of a bilateral U.S.-Spanish defense accord, but is strongly opposed to NATO membership.

Oreja said in an interview published yesterday that the government would probably initiate talks aimed at NATO entry in 1981, when the U.S.-Spanish Defense Treaty is scheduled to expire. The expiration of the five-year treaty has long been considered here as the starting point for Spain's application to join NATO.

While Oreja and other officials contend that a parliamentay vote is sufficient to bind Spain to the alliance, opposition voices here are calling for a nationwide referendum on the issue.

"Entry into the alliance," the influential newspaper El Pais said in an editorial, "if it should come about, must by preceded by a broad backing both in parliament and by public opinion. Anything else would be a grave offense to the pacifist sentiments of millions of Spaniards." w

An added difficulty on the issue is Gibraltar, the British colony on the southern trip of Spain. Spain, which seeks to regain sovereignty over the area, is reported to have had difficulties in talks with Britain aimed at resolving the Gibraltar question.

Oreja said that "unless the Gibraltar question is in the process of being solved, I cannot carry senior members of the [Spanish] armed forces on the NATO issue."

American diplomats here privately say that it is "unfortunate" that the debate on Spanish entry into NATO started in earnest shortly before Carter's visit. His one-day visit had not been expected to produce any controversy.

The sharp divisions on NATO entry were recently revealed and a poll conducted by the magazine Defensa, which specializes in military affairs. While senior Spanish officers were overwhelming in favor of NATO membership, the poll showed that officers from the rank of major downward were against it by a narrow margin.

Polling more than 8,000 readers, of which more then a third were members of the armed forces, the magazine said that NATO entry was favored by a 52-to-43 percent margin. The closeness of the outcome was considered a setback for NATO supporters since the Defensa readership is considered sympathetic to Western defense systems.