You could possibly try to have the SPI module do that. Use the clock of the SPI as the clock for the chip, the MOSI as the SD and you could even choose a CS of the SPI module to connect to the LOAD. If you use pin 10 as your CS/LOAD, you can get inspiration from my post here https://forum.pjrc.com/threads/68521...CS-pin-and-DMA.
Your SPI setup function could look like this:
Code:
void adc_setup() {
SPI.setCS(10); /* Connect pin 10 to LOAD pin on YM3014 */
LPSPI4_TCR |= LPSPI_TCR_FRAMESZ(15); /* Every transfer will automatically shift out 15 + 1 bits */
LPSPI4_CFGR1 |= LPSPI_CFGR1_PCSPOL(1); /* Inverts the polarity of the CS pin, so that the edge falls at the end of the frame */
SPI.begin(); /* Starts the SPI moule with 4MHz clock by default. Isn't that convenient? ;) */
}
After this, everything you write to LPSPI4_TDR will be automatically shifted out. Example:
Code:
void loop() {
LPSPI4_TDR = 0x1234; /* Transmit 0x1234 */
delay(100); /* Or do something else */
}
You can write to LPSPI4_TDR as fast as you want, which will queue up the data to be sent. Keep in mind that the queue has 16 spots available. After the queue is full, you can't write anymore. You'll have to wait for the module to shift out the bytes in the queue to add more data to send.
Also keep in mind that the module will "receive" data (which will appear as zeros since you won't have anything connected to the MISO pin) at the same time as it is sending. If the receive queue fills up, this will also prevent you from sending further. To fix that you could flush the receive queue before trying to send anything. Example:
Code:
void loop() {
LPSPI4_CR |= LPSPI_CR_RRF; /* Reset receive queue */
LPSPI4_TDR = 0x1234; /* Transmit 0x1234 */
delay(100); /* Or do something else */
}