This is one of the misunderstandings among some Muslims caused by allegations on the Prophet (SAWA) created by his enemies. The Prophet Muhammad (SAWA) has achieved the maximum knowledge in the history of all human beings as he was taught by Allah, The Glorious who told him in Quran ( And Allah taught you everything which you did not know) (4 : 113).
The Prophet Muhammad (SAWA) was never illiterate but was from Umm Al-Qura which is one of the names of Makkah, that is why he was called as Ummi.
The Infallible Imams (AS) have clearly refuted this allegation in many occasions. Imam Muhammad Al-Baqir (AS) was asked: People claim that the Messenger of Allah ( SAWA) was not able to read or write. Imam (AS) said: They lied, curse of Allah be on them, how can it be possible when Allah The Glorious said: He who sent among the Ummeyeen ( People of Makkah) a Messenger from them, to recite on them His verses, He, and to purify them, and to teach them the Book and the Wisdom, while they were before that in obvious astray. How can he teach them the Book and Wisdom when he does not know reading or writing? He was asked: then why he was called as the Ummi prophet ? Imam (AS) said: because he was from Makkah, and Allah said in Quran : So that you warn Ummul Qura and what is surrounding it. Ummul Qura is Makkah, and that is why he was called Ummi. ( Elal al-Sharaaye').
There are Hadeeths that the Prophet Muhammad (SAWA) was taught by Allah reading and writing in 73 languages.