以下是我写的一段通过IIS接口播放音频的程序
void BoFangYinPing(U32 Addr) { U16 *buf; U16 *buf_tmp; U32 size; U8 i; buf = (U16 *)Addr; buf_tmp = buf + 22; size = (*(buf + 21) << 16) | *(buf + 20); pllcon_save = rPLLCON; rPLLCON = (0x69 << 12) | (0x17 << 4) | 0; //如果不屏蔽不可播放 Delay(10); rIISCON=0x02; //IIS interface enable: no //IIS prescaler enable: yes //receive channel idle command: IISLRCK is generated //transmit channel idle command: IISLRCK is generated //receive DMA service request enable:no //transmit DMA service request enable:no //Master,Tx,L-ch=low,iis,16bit ch.,codeclk=256fs,lrck=32fs rIISMOD=0x89; //Serial bit clock frequency slect:32fs //Master clock(CODECLK) frequency select:256fs //Serial data bit per channel:16 bit //Serial interface format: IIS compatible format //Active level of left/right channel:Low for left channel ( high for right channel) //Transmit/rec.eive mode select:transfer mode //Master/slave mode:master mode //Prescaler_A/B enable, value=3 rIISPSR=0x33; //prescaler value B:3 //Prescaler value A:3
//Tx/Rx normal,Tx FIFO enable--> start piling.... rIISFCON=0x200; //receive fifo enable:no //transmit fifo enable:yes //receive fifo access mode:normal access mode //transmite access mode select:normal access mode /****** IIS Tx Start ******/ rIISCON |=0x1; while(Uart_Getch() != ESC_KEY) { if(IIS_FIFOREADY) { for(i=0;i<8;i++) { *rIISFIF = *buf_tmp++; } if( ((U32)buf_tmp-(U32)(buf+22)) > size ) { buf_tmp = (U16 *)(buf+22); WrUTXH0('#'); } } } /****** IIS Tx Stop ******/ rIISCON=0x0; //IIS stop rPLLCON = pllcon_save; Delay(10); } 一开始总是不能播放音频,经过检查,我发现问题出在Uart_Printf()函数。这个函数原先是这样定义的 char Uart_Getch(void) { while(!(rUTRSTAT0 & 0x1)); //Receive data ready return RdURXH0(); } 如果改为 char Uart_Getch(void) { if(rUTRSTAT0 & 0x1) //Receive data ready return RdURXH0(); } 就可以播放音频了。
两种写法,逻辑上是一样的啊,为什么会有这么大的区别呢? 请高手指教,不胜感谢!
|