七 ARM9(S3C2440)的IIS-理論知識及程序?qū)嵗?/h1>
本文引用地址:http://m.butianyuan.cn/article/201611/322172.htm
//L3總線接口的寫函數(shù)
//輸入?yún)?shù)data為要寫入的數(shù)據(jù)
//輸入?yún)?shù)address,為1表示地址模式,為0表示數(shù)據(jù)傳輸模式
static void WriteL3(U8 data,U8 address)
{
int i,j;
if(address == 1)
rGPBDAT = rGPBDAT & ~(L3D | L3M | L3C) | L3C; //L3D=L, L3M=L(地址模式), L3C=H
else
rGPBDAT = rGPBDAT & ~(L3D | L3M | L3C) | (L3C | L3M); //L3M=H(數(shù)據(jù)傳輸模式)
for(i=0;i<10;i++)
; //等待一段時間
//并行數(shù)據(jù)轉(zhuǎn)串行數(shù)據(jù)輸出,以低位在前、高位在后的順序
for(i=0;i<8;i++)
{
if(data & 0x1) // H
{
rGPBDAT &= ~L3C; //L3C=L
rGPBDAT |= L3D; //L3D=H
for(j=0;j<5;j++)
; //等待一段時間
rGPBDAT |= L3C; //L3C=H
rGPBDAT |= L3D; //L3D=H
for(j=0;j<5;j++)
; //等待一段時間
}
else // L
{
rGPBDAT &= ~L3C; //L3C=L
rGPBDAT &= ~L3D; //L3D=L
for(j=0;j<5;j++)
; //等待一段時間
rGPBDAT |= L3C; //L3C=H
rGPBDAT &= ~L3D; //L3D=L
for(j=0;j<5;j++)
; //等待一段時間
}
data >>= 1;
}
rGPBDAT = rGPBDAT & ~(L3D | L3M | L3C) | (L3C | L3M); //L3M=H,L3C=H
}
//放音
void playsound(unsigned char *buffer, int length)
{
int count,i;
char flag;
rGPBDAT = rGPBDAT & ~(L3M|L3C|L3D) |(L3M|L3C); //L3開始傳輸:L3M=H, L3C=H
//配置UDA1341
WriteL3(0x14 + 2,1); //狀態(tài)模式(000101xx+10)
WriteL3(0x60,0); //0,1,10, 000,0 : 狀態(tài)0,復(fù)位
WriteL3(0x14 + 2,1); //狀態(tài)模式 (000101xx+10)
WriteL3(0x10,0); //0,0,01, 000,0 : 狀態(tài)0, 384fs,IIS,no DC-filtering
WriteL3(0x14 + 2,1); //狀態(tài)模式 (000101xx+10)
WriteL3(0xc1,0); //1,0,0,0, 0,0,01:狀態(tài)1,
//Gain of DAC 6 dB,Gain of ADC 0dB,ADC non-inverting,
//DAC non-inverting,Single speed playback,ADC-Off DAC-On
//配置s3c2440的IIS寄存器
//預(yù)分頻器為3,所以CDCLK=PCLK/(3+1)=16.928kHz
rIISPSR = 3<<5|3;
//無效DMA,輸入空閑,預(yù)分頻器有效
rIISCON = (0<<5)|(0<<4)|(0<<3)|(1<<2)|(1<<1);
//PCLK為時鐘源,輸出模式,IIS模式,每個聲道16位,CODECLK=384fs,SCLK=32fs
rIISMOD = (0<<9)|(0<<8)|(2<<6)|(0<<5)|(0<<4)|(1<<3)|(1<<2)|(1<<0);
rIISFCON = (0<<15)|(1<<13); //輸出FIFO正常模式,輸出FIFO使能
flag=1;
count=0;
//開啟IIS
rIISCON |= 0x1;
while(flag)
{
if((rIISCON & (1<<7))==0) //檢查輸出FIFO是否為空
{
//FIFO中的數(shù)據(jù)為16位,深度為32
//當(dāng)輸出FIFO為空時,一次性向FIFO寫入32個16位數(shù)據(jù)
for(i=0;i<32;i++)
{
*IISFIFO=(buffer[2*i+count])+(buffer[2*i+1+count]<<8);
}
count+=64;
if(count>length)
flag=0; //音頻數(shù)據(jù)傳輸完,則退出
}
}
rIISCON = 0x0; //關(guān)閉IIS
}
void Main(void)
{
//配置MPLL
//fs=44.1kHz,CODECLK=384fs=16.9344MHz
//不改變CLKDIVN,所以PCLK=FCLK/8
//MPLLCON:MDIV=150,PDIV=5,SDIV=0,所以FCLK=541.7143MHz,PCLK=67.714MHz//上面的解釋是fs=44.1時,而我的文件fs=22.05,所以令SDIV=1
rMPLLCON = (150<<12) | (5<<4) | 1;
//配置L3接口總線,GPB2:L3MODE, GPB3:L3DATA, GPB4:L3CLOCK
rGPBCON = 0x015550; //輸出
rGPBUP = 0x7ff; //上拉無效
rGPBDAT = 0x1e4;
//配置IIS接口
rGPEUP = rGPEUP & ~(0x1f) | 0x1f; //上拉無效,GPE[4:0] 1 1111
rGPECON = rGPECON & ~(0x3ff) | 0x2aa;
Uart_Init(33857000,115200);//根據(jù)PCLK設(shè)置波特率
Uart_Printf("nNOW PLAY THE WindowsXP");
Uart_Printf("nsample=%d",*(U32 *)(WindowsXP_Wav+0x18));//輸出采樣頻率
playsound(WindowsXP_Wav+44,sizeof(WindowsXP_Wav)-44);//在數(shù)據(jù)開始處開始播放
rMPLLCON = (150<<12) | (5<<4) | 0;//為下面播放44.1KHZ文件設(shè)置
Uart_Init(33857000*2,115200);//PCLK設(shè)置波特率
Uart_Printf("nNOW PLAY THE What_are_words");
Uart_Printf("nsample=%d",*(U32 *)(What_are_words+0x18));
playsound(What_are_words+44,sizeof(What_are_words)-44);//該文件是44.1KHZ
while(1)
{
;
}
}
//L3總線接口的寫函數(shù)
//輸入?yún)?shù)data為要寫入的數(shù)據(jù)
//輸入?yún)?shù)address,為1表示地址模式,為0表示數(shù)據(jù)傳輸模式
static void WriteL3(U8 data,U8 address)
{
;
;
;
;
}
//放音
void playsound(unsigned char *buffer, int length)
{
//Gain of DAC 6 dB,Gain of ADC 0dB,ADC non-inverting,
//DAC non-inverting,Single speed playback,ADC-Off DAC-On
//預(yù)分頻器為3,所以CDCLK=PCLK/(3+1)=16.928kHz
rIISPSR = 3<<5|3;
rIISCON
for(i=0;i<32;i++)
count+=64;
}
void Main(void)
{
//配置L3接口總線,GPB2:L3MODE, GPB3:L3DATA, GPB4:L3CLOCK
rGPBCON = 0x015550;
rGPBUP
rGPBDAT = 0x1e4;
//配置IIS接口
rGPEUP = rGPEUP & ~(0x1f) | 0x1f;
playsound(WindowsXP_Wav+44,sizeof(WindowsXP_Wav)-44);//在數(shù)據(jù)開始處開始播放
rMPLLCON = (150<<12) | (5<<4) | 0;//為下面播放44.1KHZ文件設(shè)置
playsound(What_are_words+44,sizeof(What_are_words)-44);//該文件是44.1KHZ
}
}
評論