I am not sure if this helps you
But, recently, I had a similar problem with the baud rate on a different chip. I had the prototype working consistently and everytime on every board I built. But, all the other chips I managed to program did not work. I thought I had bad chips and tried to reconfigure and play with the settings. Everytime the result was just the same. The very first chip(proto) worked well irrespective of the code changes, the others wouldn't. Finally, I narrowed it down to the baud rate. The divider count was off by 1 count. Since you said that you changed the clock to 40MHz, perhaps you could check on the baud rate settings. Perhaps the 40MHz is off???
Jerson