LPC1768的IIS通讯

IIS是飞利浦公司定义的一种用于音频传输的数字总线,LPC1768支持该总线, I2S接口为一条3线串行总线,含有1根数据线、1根时钟线和1根字选择信号线。基本的I2S连接具有一个主机(其总是为主机)和一个从机。LPC1700系列Cortex—M3微控制器的I2S提供了彼此独立的发送和接收通道,每个通道都可作为主机或从机.

使用代码如下

void IISInit(void)

{

//打开IIS时钟

LPC_SC->PCONP |= 1<<27;

LPC_SC->PCLKSEL1 &= ~(0X03<<22);    //时钟选择25M

//0.4 IIS RX CLK

LPC_PINCON->PINSEL0 &= ~(0x03u<<8);

LPC_PINCON->PINSEL0 |= (0x01u<<8);

//0.5 IIS RX LR

LPC_PINCON->PINSEL0 &= ~(0x03u<<10);

LPC_PINCON->PINSEL0 |= (0x01u<<10);

//0.6 IIS RX DAT

LPC_PINCON->PINSEL0 &= ~(0x03u<<12);

LPC_PINCON->PINSEL0 |= (0x01u<<12);

//0.7 IIS TX CLK

LPC_PINCON->PINSEL0 &= ~(0x03u<<14);

LPC_PINCON->PINSEL0 |= (0x01u<<14);

//0.8 IIS TX LR

LPC_PINCON->PINSEL0 &= ~(0x03u<<16);

LPC_PINCON->PINSEL0 |= (0x01u<<16);

//0.9 IIS TX DAT

LPC_PINCON->PINSEL0 &= ~(0x03u<<18);

LPC_PINCON->PINSEL0 |= (0x01u<<18);

//mclk  IIS TX MCLK

LPC_PINCON->PINSEL9 &= ~(0x03u<<26);

LPC_PINCON->PINSEL9 |= (0x01u<<26);

//FS 48K DATALENGTH 16 MONO ON MCLK 256FS

LPC_I2S->I2STXRATE = 0;

LPC_I2S->I2STXRATE = (98<<8)| 100;       //X 98 Y 100 MCLK (25000000/2)*0.98 12250000

LPC_I2S->I2SRXRATE = 0;

LPC_I2S->I2SRXRATE =(98<<8)| 100;        //X 98 Y 100 MCLK (25000000/2)*0.98 12250000

LPC_I2S->I2STXBITRATE = 7;           //BIT_RATE=MCLK/(7+1)=1531250  FS = 1531250/16/2 = 47.85

LPC_I2S->I2SRXBITRATE = 7;           //BIT_RATE=MCLK/(7+1)=1531250  FS = 1531250/16/2 = 47.85

LPC_I2S->I2STXMODE |= 1<<3; //禁止TCLK输出

LPC_I2S->I2SRXMODE |= 1<<3; //禁止RCLK输出

//16位数据 立体声 使能fifo 主模式 采样周期32 仅仅发送0

LPC_I2S->I2SDAO = (1<<0)|(0<<2)|(0<<3)|(0<<4)|(0<<5)|(15<<6)|(0<<15);

LPC_I2S->I2SDAI = ((16-1)<<6)|(0<<5)|(0<<4)|(0<<3)|(0<<2)|(1<<0);

IIS_Stop();

LPC_I2S->I2SIRQ = (0<<0)|(0<<1)|(32<<8)|(32<<16);  //32位fifo深度 不使能接受中断,发送中断

NVIC_EnableIRQ(I2S_IRQn);

FillBuffer(Buf_L,1000,Buf_R,1000);

}

void IISStart()

{

LPC_I2S->I2SDAO &=  (~(1<<4)); //复位停止访问fifo使能并开始发送

LPC_I2S->I2SDAO &=  (~(1<<3));

LPC_I2S->I2SDAO &=  (~(1<<15));

}

void IISStartTransData(void)

{

IISStart();

LPC_I2S->I2SIRQ |= LPC_I2S->I2SIRQ | (1<<1);

}

void I2S_IRQHandler(void)

{

u32 state=LPC_I2S->I2SSTATE;

if(state&0x1)

{

if( ((state>>16)&0x1f)==0 )

{

s16 datl=Buf_L[current_l++];

s16 datr=Buf_R[current_r++];

LPC_I2S->I2STXFIFO = (datr<<16) | (datl & 0xFFFF);

if(current_l>=len_l)current_l=0;

if(current_r>=len_r)current_r=0;

}

}

}

上一篇:BZOJ 3563 DZY Loves Chinese


下一篇:angulajs中引用chart.js做报表,修改线条样式