I understand that he was pressed into offering the referendum to counter the perceived danger from UKIP who were expected to hit the tories badly because their primary objective was to offer a referendum. Cameron never believed the referendum would go to Leave and he thought he had all the bases covered. He could beat UKIP, beat the referendum, stay in the EU and continue to make his fortune and entertain his porcine friends. But then it all went wrong for him....
The referendum was UKIPs baby - Cameron stole the idea and ran with it as he had been assured it would fail.