這里用DMA方式寫入DPI 只是證明控制字寫入,其數(shù)據(jù)的寫入只需將DC 控制端口設(shè)置為1;
#include <cdefBF533.h> //BF533 Register Pointer Definition #include <stdio.h> #include <sys\exception.h>
#define CODEC_1836_REGS_LENGTH 7
short sCodec1836TxRegs[CODEC_1836_REGS_LENGTH] = {0x21,0xc8,0x06,0x13,0x20,0x0c,0x80};
void Init_EBIU(void) { *pEBIU_AMBCTL0 = 0x7bb07bb0; *pEBIU_AMBCTL1 = 0x7bb07bb0; *pEBIU_AMGCTL = 0x000f; }
void main(void) {
int i; int j; *pFIO_DIR=0x0f; Init_EBIU();
// write to Port A to reset AD1836 *pFIO_FLAG_C = 0x08; //reset
// write to Port A to enable AD1836 *pFIO_FLAG_S = 0x08;
// wait to recover from reset for (i=0; i<0xf0000; i++) asm("nop;");
// Enable PF4 *pSPI_FLG = FLS4; // Set baud rate SCK = HCLK/(2*SPIBAUD) SCK = 2MHz *pSPI_BAUD = 16; // configure spi port // SPI DMA write, 16-bit data, MSB first, SPI Master *pSPI_CTL = 0x03 | SIZE | MSTR; //有下劃線的是與普通模式不同的
// Set up DMA5 to transmit // Map DMA5 to SPI *pDMA5_PERIPHERAL_MAP = 0x5000;
// Configure DMA5 // 16-bit transfers *pDMA5_CONFIG = WDSIZE_8;
*pFIO_FLAG_C = 0x02;
// Start address of data buffer *pDMA5_START_ADDR = (void *)sCodec1836TxRegs; // DMA inner loop count *pDMA5_X_COUNT = CODEC_1836_REGS_LENGTH; // Inner loop address increment *pDMA5_X_MODIFY = 2; // enable DMAs *pDMA5_CONFIG = (*pDMA5_CONFIG | DMAEN); // enable spi *pSPI_CTL = (*pSPI_CTL | SPE);
// wait until dma transfers for spi are finished for (j=0; j<0xaff0; j++) asm("nop;");
// disable spi // *pSPI_CTL = 0x0000; }
|