I have multiple boards with an ATMEGA324P20AU that is programmed on-board via SPI. The cpus are all marked as "ATMEGA324P20AU 1038G".
When I tried to connect with avrdude there was no response, even with a low clock rate. After a lot of experimenting I found out that with an external 250kHz clock on XTAL1 avrdude works fine. When I read the fuse settings, I got E=0xFF, H=0x99, L=0xe1 as factory settings. According to the data sheet, that would be CKSEL=0001 / reserved !?? The cpu has **never** been touched/programmed before that. I thought that there might be a problem with just this cpu. I tried 10 different boards, and all of them showed the same fuse settings. With the external clock connection, I'm able to program the fuses so that a 12MHz crystal is used in full swing mode, and the cpu works as expected.
Some time ago, I have used the same boards from a different production run with ATMEGA324PA-AU, and I have never seen such a problem. I was always able to program the cpu with avrdude without using an external clock connection. Shouldn't the default (factory) fuse settings use the internal RC oscillator? Has anybody seen something like that?