Reference for Berakhot 27:2
תניא נמי הכי הקורא את שמע ופגע בו רבו או גדול הימנו בפרקים שואל מפני הכבוד וא"צ לומר שהוא משיב ובאמצע שואל מפני היראה ואצ"ל שהוא משיב דברי ר' מאיר ר' יהודה אומר באמצע שואל מפני היראה ומשיב מפני הכבוד ובפרקים שואל מפני הכבוד ומשיב שלום לכל אדם
There is a teaching to the same effect : If one is reading the Shema', and his teacher or one greater than himself meet him, between the sections he may greet him out of respect, and there is no need to state that he may return a salutation; and in the middle [of the sections], he may greet one because of fear, and there is no need to state that he may return a salutation. These are the words of R. Meir. R. Judah says : In the middle, he may greet because of fear and return a salutation out of respect ; and between the sections, he may greet out of respect and return the salutation of any person.