Beethoven , who continued to work as he slowly went deaf , wrote the work in the years prior to his death in 1827 .