Hi everyone,
I'm currently trying to read samples from an SD card to send them to an external DAC using the Arduino Due. The problems are:
- The built in SPI doesn't work with both the SD card and DAC, I've tried lots of different circuit configurations and software solutions nothing helped!
- So I tried using the USART SPI example, made by D. Lloyd, but my code is soooo slowww! It takes more than 5 ms to write to one of the DACs, I'm currently using an MCP4922 IC. The main culprits are the 2 loops I use between each byte, and before setting the CS high. This DAC needs a 2 byte word before CS goes high.
I can't find what is wrong with my code and I need a sampling rate of at least about 44 kHz, I'm setting the SPI CLK to 10.5 MHz, but that does nothing.
Regards,
Danny
Due_USART0_SPI_Master_High_Freq.ino (6.19 KB)
An example of read/write SD card via SPI, this thread reply #4:
https://forum.arduino.cc/index.php?topic=537799.0
and this with SDFat:
For an example of external DAC monitoring, Google DUE DAC SPI and you will find a .pdf tutorial
Why don't you use your buitlin DACs ?
Hi,
The SD card works with the internal DACs, if I don't use the external SPI DAC.
And the external SPI DAC (MCP4922) works without the SD card, I'm able to generate a sinewave for example.
I can't use an external DAC at the same time as the SD card I've tried it several ways , and I think it will never work, because there is interference at the SPI interface, and the SD stops reading and I get only noise on the DACs.
I'm currently using those 12 bit DACs but I will upgrade them to 16 bit DACs. I need an alternative to the SPI bus that allow a bitrate higher than 4 Mbit/s. I don't understand why I'm setting the Baud Rate Generator Register to 10.5 MHz (MCK/8) and I have to wait more than 3 ms? The problem is I need to send 2 bytes to the DAC and not one. Do you have any idea of what is causing that? And what I can do to solve this problem.
Regards,
Danny
Ok, the problem was the divider, I was setting it to very large value.
Now I'm getting about 10-12 microseconds, per each dac write. I think it is a bit slow, is it possible to improve it to about 5 or 6 microseconds? Maybe with a faster digital write.
The SPI USART is now working fine with a SCK of about 16.8 MHz, the write to dac functions are taking about 5-6 microseconds.
I also need to test the USART1, I could use it to read from an external ADC. Another option I have is to use the same USART SPI (USART0), once I'm defining the CS "manually".
Regards,
Danny
Due_USART0_SPI_Master_High_Freq.ino (6.72 KB)