The Torah tells us that the Jews travelled from their encampment at Rephidim and they camped in the desert. "Va'Yichan Sham Yisrael neged ha'har" - and he [Yisrael] camped there opposite the mountain.
Rashi tells us they camped as one person - k'ish echad b'lev echad. All were united s one person. this was a pre-requisite (according to some) to receiving the Torah (and to others at least an important lesson about achdus).
What happened that all of the sudden they are praised for being together as one? We just read numerous times how there was fighting and complaining and murmurring and non-stop kvetching. What happened that all of the sudden they are one?
To figure this out, we must analyze what they did last. It says they left Rephidim and then they camped as one. Something must have happened at Rephidim to cause them to be one. If we look back to Parshat B'Shelech, what happened in Rephidim was the battle with Amalek.
Amalek had the guts to attack the jews, despite everything that had happened pretty much attesting to the fact that the jews were untouchable. But an interesting thing happened during the battle. The Jews did not automatically come out victorious, decimating the Amalekites. It seems that the Amalekites fought ferociously and even won some of (many of?) the various skirmishes and battles. The Torah tells us that when Moshe would raise his hands the Jews would look up and remember Hashem and they would then win, but when Moshe's hands were down they would loose (seemingly because they forgot Hashem and would think they were waging their own war). The war was a real fight, not like what happened with the Egyptians.
We see even in modern day times that when there is a common enemy to rally against, it does wonders for solving internal strife. The troubles presented to the Jews by Amalek, allowed the Jews a chance to ignore the various problems and issues and differences between them and work as one towards the common goal.
That was the prerequisite to Kabbalas Ha'Torah - being able to overlook everyone else's differences, which they had not been able to do up until then. Amalek is what allowed us to do that.