?? init1835viaspi.c
字號:
#include "Sample Playback.h"
#include "ad1835.h"
void Delay(int);
void SetupSPI1835(void);
void DisableSPI1835(void);
/* Setup the SPI pramaters here in a buffer first */
unsigned int Config1835Param [] = {
WR | DACCTRL1 | DACI2S | DAC24BIT | DACFS48,
WR | DACCTRL2 ,//| DACMUTE_R4 | DACMUTE_L4,
WR | DACVOL_L1 | DACVOL_MAX,
WR | DACVOL_R1 | DACVOL_MAX,
WR | DACVOL_L2 | DACVOL_MAX,
WR | DACVOL_R2 | DACVOL_MAX,
WR | DACVOL_L3 | DACVOL_MAX,
WR | DACVOL_R3 | DACVOL_MAX,
WR | DACVOL_L4 | DACVOL_MAX,
WR | DACVOL_R4 | DACVOL_MAX,
WR | ADCCTRL1 | ADCFS48,
WR | ADCCTRL2 | ADCI2S | ADC24BIT,
WR | ADCCTRL3 | IMCLKx2
} ;
volatile int spiFlag ;
void SetupSPI1835 ()
{
/* First configure the SPI Control registers */
/* First clear a few registers */
*pSPICTL = (TXFLSH | RXFLSH) ;
*pSPIFLG = 0;
/* Setup the baud rate to 1MHz */
*pSPIBAUD = 100;
/* Setup the SPI Flag register to FLAG3 : 0xF708*/
*pSPIFLG = 0xF708;
/* Now setup the SPI Control register : 0x5281*/
*pSPICTL = (SPIEN | SPIMS | MSBF | WL16 | TIMOD1) ;
}
void DisableSPI1835 ()
{
*pSPICTL = (TXFLSH | RXFLSH);
}
void Configure1835Register (int val)
{
int i ;
*(volatile int *)TXSPI = val ;
Delay (100) ;
// Now wait until you have got a flag from the ISR that says
// transmission of the data is complete.
while (1)
{
spiFlag = *(volatile int *)SPISTAT ;
if (spiFlag & SPIF)
break ;
}
Delay (100) ;
}
unsigned int Get1835Register (int val)
{
int i ;
*(volatile int *)TXSPI = val ;
Delay (100) ;
// Now wait until you have got the receive falg from ISR
// that says you received the data well.
while (1)
{
spiFlag = *(volatile int *)SPISTAT ;
if (spiFlag & RXS)
break ;
}
Delay (100) ;
i = (*(volatile int *)RXSPI) ;
return i ;
}
void Init1835viaSPI()
{
int configSize = sizeof (Config1835Param) / sizeof (int) ;
int i ;
SetupSPI1835 () ;
for (i = 0; i < configSize; ++i)
{
Configure1835Register (Config1835Param[i]) ;
}
DisableSPI1835 () ;
}
void Delay (int i)
{
for (;i>0;--i)
asm ("nop;") ;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -