I am programming AD5423 DAC IC with a atmega328p-AU microcontroller with SPI, using the MCU;s internal 8-Mhz crystal. The communication protocol between the two ICs is SPI and my code works as expected (initialization, feedback, output voltage).
Now, when I switch to using the atmega328p with its external crystal (16Mhz), the AD5423's SDO (MISO line) does not always respond (it stays either 5V or 0V) and it sometimes replies correctly (aka the data I expect to see). And I do not know how to debug this behavior. The SDI/MOSI line and data are correct, its only the SDO that behaves weird.
When I switch to the external crystal these are the things I change:
- Clock speed variable
#define F_CPU 8000000ULto
#define F_CPU 16000000UL
- my UART speed variable:
#define BRC 103to
#define BRC 207
- MCU LOW Fuse from
0xE2(Internal 8Mhz) to
0xFF(ext crystal 8Mhz+) or
0xF7(ext crystal Full swing) (I have tried both)
And I have checked the SPI Data lines with oscilloscope, I dont see anything weird in the slower speeds on either internal/external crystal used.
In fact, when using the 8Mhz internal clock if the MCU, I can use the fastest speed available for the SPI (clock div/2) without issue.
I use Mode 1 SPI transfer format. (From Atmega's datasheet):
To get an idea of the frequency of the SDO reply when I use the external crystal, I attach the uart/USB terminal screenshot, looks like 50% of the time the feedback/SDO works as expected:
I suspect maybe because on the external crystal I don't use the capacitors on the clock pins, my MCU loses some clock signals? I cant suspect of anything else, on the next PCB version I will add capacitors to GND there and check but I doubt that.
Any ideas to debug this behavior?