/*********************************************************************//** * @brief c_entry: Main SPI program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { PINSEL_CFG_Type PinCfg; SPI_DATA_SETUP_Type xferConfig; /* * Initialize SPI pin connect * P0.15 - SCK; * P0.16 - SSEL - used as GPIO * P0.17 - MISO * P0.18 - MOSI */ PinCfg.Funcnum = 3; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 15; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 17; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 18; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 16; PinCfg.Funcnum = 0; PINSEL_ConfigPin(&PinCfg); /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); SPI_ConfigStruct.CPHA = SPI_CPHA_SECOND; SPI_ConfigStruct.CPOL = SPI_CPOL_LO; SPI_ConfigStruct.ClockRate = 2000000; SPI_ConfigStruct.DataOrder = SPI_DATA_MSB_FIRST; SPI_ConfigStruct.Databit = SPI_DATABIT_SIZE; SPI_ConfigStruct.Mode = SPI_MASTER_MODE; // Initialize SPI peripheral with parameter given in structure above SPI_Init(LPC_SPI, &SPI_ConfigStruct); /* Initialize Buffer */ Buffer_Init(); xferConfig.tx_data = Tx_Buf; xferConfig.rx_data = Rx_Buf; xferConfig.length = BUFFER_SIZE; SPI_ReadWrite(LPC_SPI, &xferConfig, SPI_TRANSFER_POLLING); // Verify buffer after transferring Buffer_Verify(); _DBG_("Verify complete"); SPI_DeInit(LPC_SPI); /* Loop forever */ while(1); return 1; }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { GPDMA_Channel_CFG_Type GPDMACfg; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* GPDMA block section -------------------------------------------- */ /* Initialize buffer */ _DBG_("Initialize Buffer..."); Buffer_Init(); /* Disable GPDMA interrupt */ NVIC_DisableIRQ(DMA_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); /* Initialize GPDMA controller */ GPDMA_Init(); // Setup GPDMA channel -------------------------------- // channel 0 GPDMACfg.ChannelNum = 0; // Source memory GPDMACfg.SrcMemAddr = DMA_SRC; // Destination memory GPDMACfg.DstMemAddr = DMA_DST; // Transfer size GPDMACfg.TransferSize = DMA_SIZE; // Transfer width GPDMACfg.TransferWidth = GPDMA_WIDTH_WORD; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2M; // Source connection - unused GPDMACfg.SrcConn = 0; // Destination connection - unused GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; _DBG_("Start transfer..."); // Enable GPDMA channel 0 GPDMA_ChannelCmd(0, ENABLE); /* Enable GPDMA interrupt */ NVIC_EnableIRQ(DMA_IRQn); /* Wait for GPDMA processing complete */ while ((Channel0_TC == 0) && (Channel0_Err == 0)); /* Verify buffer */ Buffer_Verify(); _DBG(compl_menu); /* Loop forever */ while(1); return 1; }
/* Select the Transfer mode : Polling, Interrupt or DMA */ static void appSSPTest(void) { int key; DEBUGOUT(sspTransferModeSel); dmaChSSPTx = Chip_GPDMA_GetFreeChannel(LPC_GPDMA, LPC_GPDMA_SSP_TX); dmaChSSPRx = Chip_GPDMA_GetFreeChannel(LPC_GPDMA, LPC_GPDMA_SSP_RX); xf_setup.length = BUFFER_SIZE; xf_setup.tx_data = Tx_Buf; xf_setup.rx_data = Rx_Buf; while (1) { key = 0xFF; do { key = DEBUGIN(); } while ((key & 0xFF) == 0xFF); Buffer_Init(); switch (key) { case SSP_POLLING_SEL: /* SSP Polling Read Write Mode */ DEBUGOUT(sspWaitingMenu); xf_setup.rx_cnt = xf_setup.tx_cnt = 0; Chip_SSP_RWFrames_Blocking(LPC_SSP, &xf_setup); if (Buffer_Verify() == 0) { DEBUGOUT(sspPassedMenu); } else { DEBUGOUT(sspFailedMenu); } break; case SSP_INTERRUPT_SEL: DEBUGOUT(sspIntWaitingMenu); isXferCompleted = 0; xf_setup.rx_cnt = xf_setup.tx_cnt = 0; Chip_SSP_Int_FlushData(LPC_SSP);/* flush dummy data from SSP FiFO */ if (SSP_DATA_BYTES(ssp_format.bits) == 1) { Chip_SSP_Int_RWFrames8Bits(LPC_SSP, &xf_setup); } else { Chip_SSP_Int_RWFrames16Bits(LPC_SSP, &xf_setup); } Chip_SSP_Int_Enable(LPC_SSP); /* enable interrupt */ while (!isXferCompleted) {} if (Buffer_Verify() == 0) { DEBUGOUT(sspPassedMenu); } else { DEBUGOUT(sspFailedMenu); } break; case SSP_DMA_SEL: /* SSP DMA Read and Write: fixed on 8bits */ DEBUGOUT(sspDMAWaitingMenu); isDmaTxfCompleted = isDmaRxfCompleted = 0; Chip_SSP_DMA_Enable(LPC_SSP); /* data Tx_Buf --> SSP */ Chip_GPDMA_Transfer(LPC_GPDMA, dmaChSSPTx, (uint32_t) &Tx_Buf[0], LPC_GPDMA_SSP_TX, GPDMA_TRANSFERTYPE_M2P_CONTROLLER_DMA, BUFFER_SIZE); /* data SSP --> Rx_Buf */ Chip_GPDMA_Transfer(LPC_GPDMA, dmaChSSPRx, LPC_GPDMA_SSP_RX, (uint32_t) &Rx_Buf[0], GPDMA_TRANSFERTYPE_P2M_CONTROLLER_DMA, BUFFER_SIZE); while (!isDmaTxfCompleted || !isDmaRxfCompleted) {} if (Buffer_Verify() == 0) { DEBUGOUT(sspPassedMenu); } else { DEBUGOUT(sspFailedMenu); } Chip_SSP_DMA_Disable(LPC_SSP); break; case 'q': case 'Q': Chip_GPDMA_Stop(LPC_GPDMA, dmaChSSPTx); Chip_GPDMA_Stop(LPC_GPDMA, dmaChSSPRx); return; default: break; } DEBUGOUT(sspTransferModeSel); } }
/*********************************************************************//** * @brief Main SSP program body **********************************************************************/ int c_entry(void) { GPDMA_Channel_CFG_Type GPDMACfg; PINSEL_CFG_Type PinCfg; // DeInit NVIC and SCBNVIC NVIC_DeInit(); NVIC_SCBDeInit(); /* Configure the NVIC Preemption Priority Bits: * two (2) bits of preemption priority, six (6) bits of sub-priority. * Since the Number of Bits used for Priority Levels is five (5), so the * actual bit number of sub-priority is three (3) */ NVIC_SetPriorityGrouping(0x05); // Set Vector table offset value #if (__RAM_MODE__==1) NVIC_SetVTOR(0x10000000); #else NVIC_SetVTOR(0x00000000); #endif /* * Initialize SPI pin connect * P0.15 - SCK; * P0.16 - SSEL * P0.17 - MISO * P0.18 - MOSI */ PinCfg.Funcnum = 2; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 15; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 17; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 18; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 16; PINSEL_ConfigPin(&PinCfg); /* * Initialize debug via UART */ debug_frmwrk_init(); // print welcome screen print_menu(); /* Initializing SSP device section ------------------------------------------------------ */ // initialize SSP configuration structure to default SSP_ConfigStructInit(&SSP_ConfigStruct); // Initialize SSP peripheral with parameter given in structure above SSP_Init(LPC_SSP0, &SSP_ConfigStruct); // Enable SSP peripheral SSP_Cmd(LPC_SSP0, ENABLE); /* GPDMA Interrupt configuration section ------------------------------------------------- */ /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); /* Enable SSP0 interrupt */ NVIC_EnableIRQ(DMA_IRQn); /* Initializing Buffer section ----------------------------------------------------------- */ Buffer_Init(); /* Initialize GPDMA controller */ GPDMA_Init(); /* Setting GPDMA interrupt */ // Disable interrupt for DMA NVIC_DisableIRQ (DMA_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); /* Configure GPDMA channel 0 -------------------------------------------------------------*/ /* DMA Channel 0 */ GPDMACfg.ChannelNum = 0; // Source memory GPDMACfg.SrcMemAddr = (uint32_t) &dma_src; // Destination memory - Not used GPDMACfg.DstMemAddr = 0; // Transfer size GPDMACfg.TransferSize = sizeof(dma_src); // Transfer width - not used GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2P; // Source connection - unused GPDMACfg.SrcConn = 0; // Destination connection GPDMACfg.DstConn = GPDMA_CONN_SSP0_Tx; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg, GPDMA_Callback0); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; /* Configure GPDMA channel 1 -------------------------------------------------------------*/ /* DMA Channel 1 */ GPDMACfg.ChannelNum = 1; // Source memory - not used GPDMACfg.SrcMemAddr = 0; // Destination memory - Not used GPDMACfg.DstMemAddr = (uint32_t) &dma_dst; // Transfer size GPDMACfg.TransferSize = sizeof(dma_dst); // Transfer width - not used GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M; // Source connection GPDMACfg.SrcConn = GPDMA_CONN_SSP0_Rx; // Destination connection - not used GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg, GPDMA_Callback1); /* Reset terminal counter */ Channel1_TC = 0; /* Reset Error counter */ Channel1_Err = 0; _DBG_("Start transfer..."); // Enable Tx and Rx DMA on SSP0 SSP_DMACmd (LPC_SSP0, SSP_DMA_RX, ENABLE); SSP_DMACmd (LPC_SSP0, SSP_DMA_TX, ENABLE); // Enable GPDMA channel 0 GPDMA_ChannelCmd(0, ENABLE); // Enable GPDMA channel 0 GPDMA_ChannelCmd(1, ENABLE); // Enable interrupt for DMA NVIC_EnableIRQ (DMA_IRQn); /* Wait for GPDMA processing complete */ while (((Channel0_TC == 0) && (Channel0_Err == 0)) \ || ((Channel1_TC == 0) && (Channel1_Err ==0))); /* Verify buffer */ Buffer_Verify(); _DBG_("Verify complete!"); /* Loop forever */ while(1); return 1; }
/*********************************************************************//** * @brief Main GPDMA program body **********************************************************************/ int c_entry(void) { GPDMA_Channel_CFG_Type GPDMACfg; // DeInit NVIC and SCBNVIC NVIC_DeInit(); NVIC_SCBDeInit(); /* Configure the NVIC Preemption Priority Bits: * two (2) bits of preemption priority, six (6) bits of sub-priority. * Since the Number of Bits used for Priority Levels is five (5), so the * actual bit number of sub-priority is three (3) */ NVIC_SetPriorityGrouping(0x05); // Set Vector table offset value #if (__RAM_MODE__==1) NVIC_SetVTOR(0x10000000); #else NVIC_SetVTOR(0x00000000); #endif /* * Initialize debug via UART */ debug_frmwrk_init(); // print welcome screen print_menu(); /* GPDMA block section -------------------------------------------- */ /* Initialize buffer */ _DBG_("Initialize Buffer..."); Buffer_Init(); /* Disable GPDMA interrupt */ NVIC_DisableIRQ(DMA_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); /* Initialize GPDMA controller */ GPDMA_Init(); // Setup GPDMA channel -------------------------------- // channel 0 GPDMACfg.ChannelNum = 0; // Source memory GPDMACfg.SrcMemAddr = DMA_SRC; // Destination memory GPDMACfg.DstMemAddr = DMA_DST; // Transfer size GPDMACfg.TransferSize = DMA_SIZE; // Transfer width GPDMACfg.TransferWidth = GPDMA_WIDTH_WORD; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2M; // Source connection - unused GPDMACfg.SrcConn = 0; // Destination connection - unused GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg, GPDMA_Callback); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; _DBG_("Start transfer..."); // Enable GPDMA channel 0 GPDMA_ChannelCmd(0, ENABLE); /* Enable GPDMA interrupt */ NVIC_EnableIRQ(DMA_IRQn); /* Wait for GPDMA processing complete */ while ((Channel0_TC == 0) && (Channel0_Err == 0)); /* Verify buffer */ Buffer_Verify(); _DBG(compl_menu); /* Loop forever */ while(1); return 1; }
/*********************************************************************//** * @brief Main I2S program body **********************************************************************/ int c_entry (void) { /* Main Program */ uint32_t i; uint8_t ch; uint8_t dummy=0; I2S_MODEConf_Type I2S_ClkConfig; I2S_CFG_Type I2S_ConfigStruct; I2S_PinCFG_Type I2S_PinStruct; // DeInit NVIC and SCBNVIC NVIC_DeInit(); NVIC_SCBDeInit(); /* Configure the NVIC Preemption Priority Bits: * two (2) bits of preemption priority, six (6) bits of sub-priority. * Since the Number of Bits used for Priority Levels is five (5), so the * actual bit number of sub-priority is three (3) */ NVIC_SetPriorityGrouping(0x05); // Set Vector table offset value #if (__RAM_MODE__==1) NVIC_SetVTOR(0x10000000); #else NVIC_SetVTOR(0x00000000); #endif NVIC_SetPriorityGrouping(0x06); debug_frmwrk_init(); print_menu(); _DBG_("Press '1' to initialize buffer..."); while(_DG !='1'); Buffer_Init(); _DBG_("Transmit Buffer init: ..."); for(i=0;i<BUFFER_SIZE;i++) { _DBH32(I2STXBuffer[i]);_DBG_(""); } _DBG_("Receive Buffer init: ..."); for(i=0;i<BUFFER_SIZE;i++) { _DBH32(I2SRXBuffer[i]);_DBG_(""); } /* Initializes pin corresponding to I2S function */ I2S_PinStruct.CLK_Pin=I2S_STX_CLK_P0_7; I2S_PinStruct.WS_Pin=I2S_STX_WS_P0_8; I2S_PinStruct.SDA_Pin=I2S_STX_SDA_P0_9; I2S_PinStruct.MCLK_Pin=I2S_TX_MCLK_P4_29; PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_stx_clk_pin[I2S_PinStruct.CLK_Pin])); PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_stx_ws_pin[I2S_PinStruct.WS_Pin])); PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_stx_sda_pin[I2S_PinStruct.SDA_Pin])); PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_tx_mclk_pin[I2S_PinStruct.MCLK_Pin])); // Configure pinsel for I2S_RX I2S_PinStruct.CLK_Pin=I2S_SRX_CLK_P0_4; I2S_PinStruct.WS_Pin=I2S_SRX_WS_P0_5; I2S_PinStruct.SDA_Pin=I2S_SRX_SDA_P0_6; I2S_PinStruct.MCLK_Pin=I2S_RX_MCLK_P4_28; PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_srx_clk_pin[I2S_PinStruct.CLK_Pin])); PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_srx_ws_pin[I2S_PinStruct.WS_Pin])); PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_srx_sda_pin[I2S_PinStruct.SDA_Pin])); PINSEL_ConfigPin((PINSEL_CFG_Type *) (&i2s_rx_mclk_pin[I2S_PinStruct.MCLK_Pin])); I2S_Init(LPC_I2S); //Setup for I2S: RX is similar with TX /* setup: * - wordwidth: 16 bits * - stereo mode * - master mode for I2S_TX and slave for I2S_RX * - ws_halfperiod is 31 * - not use mute mode * - use reset and stop mode * - select the fractional rate divider clock output as the source, * - disable 4-pin mode * - MCLK ouput is disable * - Frequency = 44.1 kHz (x=8,y=51 - automatic setting) * Because we use mode I2STXMODE[3:0]= 0000, I2SDAO[5]=0 and * I2SRX[3:0]=0000, I2SDAI[5] = 1. So we have I2SRX_CLK = I2STX_CLK * --> I2SRXBITRATE = 1 (not divide TXCLK to produce RXCLK) */ /* Audio Config*/ I2S_ConfigStruct.wordwidth = I2S_WORDWIDTH_16; I2S_ConfigStruct.mono = I2S_STEREO; I2S_ConfigStruct.stop = I2S_STOP_ENABLE; I2S_ConfigStruct.reset = I2S_RESET_ENABLE; I2S_ConfigStruct.ws_sel = I2S_MASTER_MODE; I2S_ConfigStruct.mute = I2S_MUTE_DISABLE; I2S_Config(LPC_I2S,I2S_TX_MODE,&I2S_ConfigStruct); I2S_ConfigStruct.ws_sel = I2S_SLAVE_MODE; I2S_Config(LPC_I2S,I2S_RX_MODE,&I2S_ConfigStruct); /* Clock Mode Config*/ I2S_ClkConfig.clksel = I2S_CLKSEL_0; I2S_ClkConfig.fpin = I2S_4PIN_DISABLE; I2S_ClkConfig.mcena = I2S_MCLK_DISABLE; I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_TX_MODE); I2S_ClkConfig.fpin = I2S_4PIN_ENABLE; I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_RX_MODE); /* Set up frequency and bit rate*/ I2S_FreqConfig(LPC_I2S, 44100, I2S_TX_MODE); // I2S_SetBitRate(I2S, 1, I2S_RX_MODE); I2S_Start(LPC_I2S); _DBG_("Press '2' to start I2S transfer process..."); while(_DG !='2'); _DBG_("I2S Start ..."); while(I2STXDone == 0||I2SRXDone == 0){ if(I2STXDone ==0){ while (I2S_GetLevel(LPC_I2S,I2S_TX_MODE)!=0x00); I2S_Send(LPC_I2S,I2STXBuffer[I2SWriteLength]); I2SWriteLength +=1; if(I2SWriteLength == BUFFER_SIZE) I2STXDone = 1; } if(I2SRXDone == 0) { while(I2S_GetLevel(LPC_I2S,I2S_RX_MODE)==0x00); if(dummy == 0) //dummy receive { i = I2S_Receive(LPC_I2S); if(i!=0) { *(uint32_t *)(&I2SRXBuffer[I2SReadLength]) = i; I2SReadLength +=1; dummy = 1; } } else { *(uint32_t *)(&I2SRXBuffer[I2SReadLength]) = I2S_Receive(LPC_I2S); I2SReadLength +=1; } if(I2SReadLength == BUFFER_SIZE) I2SRXDone = 1; } } _DBG_("I2S Finish..."); _DBG_("Receive Buffer data: ..."); for(i=0;i<BUFFER_SIZE;i++) { _DBH32(I2SRXBuffer[i]);_DBG_(""); } if(Buffer_Verify()) { _DBG_("Verify Buffer: OK..."); } else { _DBG_("Verify Buffer: ERROR..."); } while(1); }
/*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return int **********************************************************************/ int c_entry (void) { /* Main Program */ I2S_MODEConf_Type I2S_ClkConfig; I2S_CFG_Type I2S_ConfigStruct; PINSEL_CFG_Type PinCfg; uint32_t i; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); //print menu screen print_menu(); /* Initialize I2S peripheral ------------------------------------*/ /* Pin configuration: * Assign: - P0.4 as I2SRX_CLK * - P0.5 as I2SRX_WS * - P0.6 as I2SRX_SDA * - P0.7 as I2STX_CLK * - P0.8 as I2STX_WS * - P0.9 as I2STX_SDA */ PinCfg.Funcnum = 1; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Pinnum = 4; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 5; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 6; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 7; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 8; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 9; PINSEL_ConfigPin(&PinCfg); Buffer_Init(); I2S_Init(LPC_I2S); /* setup: * - wordwidth: 16 bits * - stereo mode * - master mode for I2S_TX and slave for I2S_RX * - ws_halfperiod is 31 * - not use mute mode * - use reset and stop mode * - select the fractional rate divider clock output as the source, * - disable 4-pin mode * - MCLK ouput is disable * - Frequency = 44.1 kHz * Because we use mode I2STXMODE[3:0]= 0000, I2SDAO[5]=0 and * I2SRX[3:0]=0000, I2SDAI[5] = 1. So we have I2SRX_CLK = I2STX_CLK * --> I2SRXBITRATE = 1 (not divide TXCLK to produce RXCLK) */ /* Audio Config*/ I2S_ConfigStruct.wordwidth = I2S_WORDWIDTH_16; I2S_ConfigStruct.mono = I2S_STEREO; I2S_ConfigStruct.stop = I2S_STOP_ENABLE; I2S_ConfigStruct.reset = I2S_RESET_ENABLE; I2S_ConfigStruct.ws_sel = I2S_MASTER_MODE; I2S_ConfigStruct.mute = I2S_MUTE_DISABLE; I2S_Config(LPC_I2S,I2S_TX_MODE,&I2S_ConfigStruct); I2S_ConfigStruct.ws_sel = I2S_SLAVE_MODE; I2S_Config(LPC_I2S,I2S_RX_MODE,&I2S_ConfigStruct); /* Clock Mode Config*/ I2S_ClkConfig.clksel = I2S_CLKSEL_FRDCLK; I2S_ClkConfig.fpin = I2S_4PIN_DISABLE; I2S_ClkConfig.mcena = I2S_MCLK_DISABLE; I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_TX_MODE); I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_RX_MODE); I2S_FreqConfig(LPC_I2S, 44100, I2S_TX_MODE); I2S_SetBitRate(LPC_I2S, 0, I2S_RX_MODE); I2S_Stop(LPC_I2S, I2S_TX_MODE); I2S_Stop(LPC_I2S, I2S_RX_MODE); NVIC_EnableIRQ(I2S_IRQn); /* RX FIFO depth is 1, TX FIFO depth is 8. */ I2S_IRQConfig(LPC_I2S,I2S_TX_MODE,8); I2S_IRQConfig(LPC_I2S,I2S_RX_MODE,1); I2S_IRQCmd(LPC_I2S,I2S_RX_MODE,ENABLE); I2S_Start(LPC_I2S); /* I2S transmit ---------------------------------------------------*/ while ( I2SWriteLength < BUFFER_SIZE ) { while(I2S_GetLevel(LPC_I2S, I2S_TX_MODE)==TXFIFO_FULL); I2S_Send(LPC_I2S, I2STXBuffer[I2SWriteLength++]); } I2STXDone = 1; /* Wait for transmit/receive complete */ while ( !I2SRXDone || !I2STXDone ); for(i=0;i<BUFFER_SIZE;i++) { _DBH32(I2SRXBuffer[i]);_DBG_(""); } /* Verify RX and TX Buffer */ if(Buffer_Verify()) { _DBG_("Verify Buffer: OK..."); } else { _DBG_("Verify Buffer: ERROR..."); } return 0; }
/*********************************************************************//** * @brief c_entry: Main TI program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { PINSEL_CFG_Type PinCfg; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* * Initialize SSP pin connect * P0.6 - SSEL1 * P0.7 - SCK1 * P0.8 - MISO1 * P0.9 - MOSI1 */ PinCfg.Funcnum = 2; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 6; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 7; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 8; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 9; PINSEL_ConfigPin(&PinCfg); /* * Initialize SSP pin connect * P0.15 - SCK * P0.16 - SSEL * P0.17 - MISO * P0.18 - MOSI */ PinCfg.Funcnum = 2; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 15; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 17; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 18; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 16; PINSEL_ConfigPin(&PinCfg); /* Initializing Master SSP device section ------------------------------------------- */ // initialize SSP configuration structure to default SSP_ConfigStructInit(&SSP_ConfigStruct); // Re-configure SSP to TI frame format SSP_ConfigStruct.FrameFormat = SSP_FRAME_TI; // Initialize SSP peripheral with parameter given in structure above SSP_Init(SSPDEV_M, &SSP_ConfigStruct); // Enable SSP peripheral SSP_Cmd(SSPDEV_M, ENABLE); /* Initializing Slave SSP device section ------------------------------------------- */ // initialize SSP configuration structure to default SSP_ConfigStructInit(&SSP_ConfigStruct); /* Re-configure mode for SSP device */ SSP_ConfigStruct.Mode = SSP_SLAVE_MODE; // Re-configure SSP to TI frame format SSP_ConfigStruct.FrameFormat = SSP_FRAME_TI; // Initialize SSP peripheral with parameter given in structure above SSP_Init(SSPDEV_S, &SSP_ConfigStruct); // Enable SSP peripheral SSP_Cmd(SSPDEV_S, ENABLE); /* Interrupt configuration section ------------------------------------------------- */ #if ((USEDSSPDEV_S == 0) || (USEDSSPDEV_M == 0)) /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(SSP0_IRQn, ((0x01<<3)|0x01)); /* Enable SSP0 interrupt */ NVIC_EnableIRQ(SSP0_IRQn); #endif #if ((USEDSSPDEV_S == 1) || (USEDSSPDEV_M == 1)) /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(SSP1_IRQn, ((0x01<<3)|0x01)); /* Enable SSP0 interrupt */ NVIC_EnableIRQ(SSP1_IRQn); #endif /* Initializing Buffer section ------------------------------------------------- */ Buffer_Init(); /* Start Transmit/Receive between Master and Slave ----------------------------- */ complete_S = FALSE; complete_M = FALSE; /* Slave must be ready first */ ssp_SlaveReadWrite(SSPDEV_S, Slave_Rx_Buf, Slave_Tx_Buf, BUFFER_SIZE); /* Then Master can start its transferring */ ssp_MasterReadWrite(SSPDEV_M, Master_Rx_Buf, Master_Tx_Buf, BUFFER_SIZE); /* Wait for complete */ while ((complete_S == FALSE) || (complete_M == FALSE)); /* Verify buffer */ Buffer_Verify(); _DBG_("Verify success!\n\r"); /* Loop forever */ while(1); return 1; }
/*********************************************************************//** * @brief c_entry: Main SSP program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { #if __DMA_USED__ GPDMA_Channel_CFG_Type GPDMACfg; #else SSP_DATA_SETUP_Type xferConfig; #endif /* * Initialize SSP pin connect * P0.15 - SCK; * P0.16 - SSEL * P0.17 - MISO * P0.18 - MOSI */ #if (_SSP_NO_USING == 0) PINSEL_ConfigPin(0, 15, 2); PINSEL_ConfigPin(0, 16, 2); PINSEL_ConfigPin(0, 17, 2); PINSEL_ConfigPin(0, 18, 2); #elif (_SSP_NO_USING == 1) PINSEL_ConfigPin(0, 6, 2); PINSEL_ConfigPin(0, 7, 2); PINSEL_SetFilter(0, 7, 0); PINSEL_ConfigPin(0, 8, 2); PINSEL_SetFilter(0, 8, 0); PINSEL_ConfigPin(0, 9, 2); PINSEL_SetFilter(0, 9, 0); #else PINSEL_ConfigPin(1, 0, 4); PINSEL_ConfigPin(1, 8, 4); PINSEL_ConfigPin(1, 1, 4); PINSEL_ConfigPin(1, 4, 4); #endif /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); // initialize SSP configuration structure to default SSP_ConfigStructInit(&SSP_ConfigStruct); // Initialize SSP peripheral with parameter given in structure above SSP_Init(LPC_SSP, &SSP_ConfigStruct); // Enable SSP peripheral SSP_Cmd(LPC_SSP, ENABLE); _DBG_("Press '1' to start transfer..."); while (_DG != '1'); /* Initialize Buffer */ _DBG_("Init buffer"); Buffer_Init(); _DBG_("Start transfer..."); #if __DMA_USED__ /* Initialize GPDMA controller */ GPDMA_Init(); /* Setting GPDMA interrupt */ // Disable interrupt for DMA NVIC_DisableIRQ (DMA_IRQn); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(DMA_IRQn, ((0x01<<3)|0x01)); /* Configure GPDMA channel 0 -------------------------------------------------------------*/ /* DMA Channel 0 */ GPDMACfg.ChannelNum = 0; // Source memory GPDMACfg.SrcMemAddr = (uint32_t) &Tx_Buf; // Destination memory - Not used GPDMACfg.DstMemAddr = 0; // Transfer size GPDMACfg.TransferSize = sizeof(Tx_Buf); // Transfer width - not used GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2P; // Source connection - unused GPDMACfg.SrcConn = 0; // Destination connection GPDMACfg.DstConn = SSP_TX_SRC_DMA_CONN; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg); /* Reset terminal counter */ Channel0_TC = 0; /* Reset Error counter */ Channel0_Err = 0; /* Configure GPDMA channel 1 -------------------------------------------------------------*/ /* DMA Channel 1 */ GPDMACfg.ChannelNum = 1; // Source memory - not used GPDMACfg.SrcMemAddr = 0; // Destination memory - Not used GPDMACfg.DstMemAddr = (uint32_t) &Rx_Buf; // Transfer size GPDMACfg.TransferSize = sizeof(Rx_Buf); // Transfer width - not used GPDMACfg.TransferWidth = 0; // Transfer type GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_P2M; // Source connection GPDMACfg.SrcConn = SSP_RX_SRC_DMA_CONN; // Destination connection - not used GPDMACfg.DstConn = 0; // Linker List Item - unused GPDMACfg.DMALLI = 0; // Setup channel with given parameter GPDMA_Setup(&GPDMACfg); /* Reset terminal counter */ Channel1_TC = 0; /* Reset Error counter */ Channel1_Err = 0; // Enable Tx and Rx DMA on SSP0 SSP_DMACmd (LPC_SSP, SSP_DMA_RX, ENABLE); SSP_DMACmd (LPC_SSP, SSP_DMA_TX, ENABLE); // Enable GPDMA channel 0 GPDMA_ChannelCmd(0, ENABLE); // Enable GPDMA channel 0 GPDMA_ChannelCmd(1, ENABLE); // Enable interrupt for DMA NVIC_EnableIRQ (DMA_IRQn); /* Wait for GPDMA processing complete */ while (((Channel0_TC == 0) && (Channel0_Err == 0)) \ || ((Channel1_TC == 0) && (Channel1_Err ==0))); #else xferConfig.tx_data = Tx_Buf; xferConfig.rx_data = Rx_Buf; xferConfig.length = BUFFER_SIZE; SSP_ReadWrite(LPC_SSP, &xferConfig, SSP_TRANSFER_POLLING); #endif // Verify buffer after transferring Buffer_Verify(); _DBG_("Verify complete!"); /* Loop forever */ while(1); }
/*********************************************************************//** * @brief c_entry: Main MICROWIRE program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { uint32_t cnt; PINSEL_CFG_Type PinCfg; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* * Initialize SSP pin connect * P0.6 - SSEL1 * P0.7 - SCK1 * P0.8 - MISO1 * P0.9 - MOSI1 */ PinCfg.Funcnum = 2; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 6; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 7; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 8; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 9; PINSEL_ConfigPin(&PinCfg); /* * Initialize SSP pin connect * P0.15 - SCK * P0.16 - SSEL * P0.17 - MISO * P0.18 - MOSI */ PinCfg.Funcnum = 2; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 15; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 17; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 18; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 16; PINSEL_ConfigPin(&PinCfg); /* Initializing Master SSP device section ------------------------------------------- */ // initialize SSP configuration structure to default SSP_ConfigStructInit(&SSP_ConfigStruct); // Re-configure SSP to MicroWire frame format SSP_ConfigStruct.FrameFormat = SSP_FRAME_MICROWIRE; // Initialize SSP peripheral with parameter given in structure above SSP_Init(SSPDEV_M, &SSP_ConfigStruct); // Enable SSP peripheral SSP_Cmd(SSPDEV_M, ENABLE); /* Initializing Slave SSP device section ------------------------------------------- */ // initialize SSP configuration structure to default SSP_ConfigStructInit(&SSP_ConfigStruct); /* Re-configure mode for SSP device */ SSP_ConfigStruct.Mode = SSP_SLAVE_MODE; // Re-configure SSP to MicroWire frame format SSP_ConfigStruct.FrameFormat = SSP_FRAME_MICROWIRE; // Initialize SSP peripheral with parameter given in structure above SSP_Init(SSPDEV_S, &SSP_ConfigStruct); // Enable SSP peripheral SSP_Cmd(SSPDEV_S, ENABLE); /* Initializing Buffer section ------------------------------------------------- */ Buffer_Init(); /* Start Transmit/Receive between Master and Slave ----------------------------- */ pRdBuf_M = (uint8_t *)&Master_Rx_Buf[0]; RdIdx_M = 0; DatLen_M = BUFFER_SIZE; pWrBuf_S = (uint8_t *)&Slave_Tx_Buf[0]; WrIdx_S = 0; DatLen_S = BUFFER_SIZE; /* Force Last command to Read command as default */ Last_cmd = MicroWire_RD_CMD; /* Clear all remaining data in RX FIFO */ while (SSP_GetStatus(SSPDEV_M, SSP_STAT_RXFIFO_NOTEMPTY)) { SSP_ReceiveData(SSPDEV_M); } while (SSP_GetStatus(SSPDEV_S, SSP_STAT_RXFIFO_NOTEMPTY)) { SSP_ReceiveData(SSPDEV_S); } for (cnt = 0; cnt < BUFFER_SIZE; cnt++) { /* The slave must initialize data in FIFO for immediately transfer from master * due to last received command */ if (Last_cmd == MicroWire_RD_CMD) { // Then send the respond to master, this contains data ssp_MW_SendRSP(SSPDEV_S, (uint16_t) *(pWrBuf_S + WrIdx_S++)); } else { // Then send the respond to master, this contains data ssp_MW_SendRSP(SSPDEV_S, 0xFF); } /* Master must send a read command to slave, * the slave then respond with its data in FIFO */ ssp_MW_SendCMD(SSPDEV_M, MicroWire_RD_CMD); // Master receive respond *(pRdBuf_M + RdIdx_M++) = (uint8_t) ssp_MW_GetRSP(SSPDEV_M); // Re-assign Last command Last_cmd = ssp_MW_GetCMD(SSPDEV_S); } /* Verify buffer */ Buffer_Verify(); _DBG_("Verify success!\n\r"); /* Loop forever */ while(1); return 1; }
/*********************************************************************//** * @brief c_entry: Main TI program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); /* * Initialize SSP pin connect */ #if (SSP0_LOCALTION_NUM == 0) // SSP0 Loc 1 PINSEL_ConfigPin(0, 15, 2); // SCK J5-19 PINSEL_ConfigPin(0, 16, 2); // SSEL J3-24 PINSEL_ConfigPin(0, 17, 2); // MISO J5-20 PINSEL_ConfigPin(0, 18, 2); // MOSI J3-23 #elif (SSP0_LOCALTION_NUM == 1) // SSP0 Loc 2 PINSEL_ConfigPin(1, 20, 5); //SCK J5-32 PINSEL_ConfigPin(1, 28, 5); //SEL J5-36 PINSEL_ConfigPin(1, 23, 5); // MISO J3-35 PINSEL_ConfigPin(1, 24, 5); // MOSI J5-34 #elif (SSP0_LOCALTION_NUM == 2) //SSP0 Loc 3 PINSEL_ConfigPin(2, 22, 2); // SCK J5-47 PINSEL_ConfigPin(2, 23, 2); // SSEL J5-56 PINSEL_ConfigPin(2, 26, 2); // MISO J5-57 PINSEL_ConfigPin(2, 27, 2); // MOSI J5-49 #else while(1); #endif #if (SSP1_LOCALTION_NUM == 0) // Loc 1 PINSEL_ConfigPin(0, 7, 2); // SCK J5.17 PINSEL_SetFilter(0, 7, 0); PINSEL_ConfigPin(0, 6, 2); // SSEL J3.18 PINSEL_ConfigPin(0, 8, 2); // MISO J3.19 PINSEL_SetFilter(0, 8, 0); PINSEL_ConfigPin(0, 9, 2); // MOSI J5.18 PINSEL_SetFilter(0, 9, 0); #elif (SSP1_LOCALTION_NUM == 1) // Loc 2 PINSEL_ConfigPin(1, 19, 5); // SCK J3-33 PINSEL_ConfigPin(1, 26, 5); //SSEL J5-35 PINSEL_ConfigPin(1, 18, 5); //MISO J5-31 PINSEL_ConfigPin(1, 22, 5); //MOSI J5-33 #elif (SSP1_LOCALTION_NUM == 2) // Loc 3 PINSEL_ConfigPin(1, 31, 2); //SCK J3-39 PINSEL_ConfigPin(0, 14, 2); //SSEL J3-21 PINSEL_ConfigPin(0, 12, 2); //MISO J3-22 PINSEL_ConfigPin(0, 13, 2); //MOSI J3-13 #else while(1); #endif /* Initializing Master SSP device section ------------------------------------------- */ // initialize SSP configuration structure to default SSP_ConfigStructInit(&SSP_ConfigStruct); // Re-configure SSP to TI frame format SSP_ConfigStruct.FrameFormat = SSP_FRAME_TI; // Initialize SSP peripheral with parameter given in structure above SSP_Init(SSPDEV_M, &SSP_ConfigStruct); // Enable SSP peripheral SSP_Cmd(SSPDEV_M, ENABLE); /* Initializing Slave SSP device section ------------------------------------------- */ // initialize SSP configuration structure to default SSP_ConfigStructInit(&SSP_ConfigStruct); /* Re-configure mode for SSP device */ SSP_ConfigStruct.Mode = SSP_SLAVE_MODE; // Re-configure SSP to TI frame format SSP_ConfigStruct.FrameFormat = SSP_FRAME_TI; // Initialize SSP peripheral with parameter given in structure above SSP_Init(SSPDEV_S, &SSP_ConfigStruct); // Enable SSP peripheral SSP_Cmd(SSPDEV_S, ENABLE); /* Interrupt configuration section ------------------------------------------------- */ #if ((USEDSSPDEV_S == 0) || (USEDSSPDEV_M == 0)) /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(SSP0_IRQn, ((0x01<<3)|0x01)); /* Enable SSP0 interrupt */ NVIC_EnableIRQ(SSP0_IRQn); #endif #if ((USEDSSPDEV_S == 1) || (USEDSSPDEV_M == 1)) /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(SSP1_IRQn, ((0x01<<3)|0x01)); /* Enable SSP0 interrupt */ NVIC_EnableIRQ(SSP1_IRQn); #endif _DBG_("Press '1' to start transfer..."); while (_DG != '1'); /* Initializing Buffer section ------------------------------------------------- */ Buffer_Init(); /* Start Transmit/Receive between Master and Slave ----------------------------- */ complete_S = FALSE; complete_M = FALSE; /* Slave must be ready first */ ssp_SlaveReadWrite(SSPDEV_S, Slave_Rx_Buf, Slave_Tx_Buf, BUFFER_SIZE); /* Then Master can start its transferring */ ssp_MasterReadWrite(SSPDEV_M, Master_Rx_Buf, Master_Tx_Buf, BUFFER_SIZE); /* Wait for complete */ while ((complete_S == FALSE) || (complete_M == FALSE)); /* Verify buffer */ Buffer_Verify(); _DBG_("Verify success!\n\r"); /* Loop forever */ while(1); }
/*********************************************************************//** * @brief c_entry: Main I2S program body * @param[in] None * @return int **********************************************************************/ int c_entry (void) { uint32_t i; uint32_t dummy=0; I2S_MODEConf_Type I2S_ClkConfig; I2S_CFG_Type I2S_ConfigStruct; PINSEL_CFG_Type PinCfg; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); //print menu screen print_menu(); Buffer_Init(); /* Pin configuration: * Assign: - P0.4 as I2SRX_CLK * - P0.5 as I2SRX_WS * - P0.6 as I2SRX_SDA * - P0.7 as I2STX_CLK * - P0.8 as I2STX_WS * - P0.9 as I2STX_SDA */ PinCfg.Funcnum = 1; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Pinnum = 4; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 5; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 6; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 7; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 8; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 9; PINSEL_ConfigPin(&PinCfg); I2S_Init(LPC_I2S); //Setup for I2S: RX is similar with TX /* setup: * - wordwidth: 16 bits * - stereo mode * - master mode for I2S_TX and slave for I2S_RX * - ws_halfperiod is 31 * - not use mute mode * - use reset and stop mode * - select the fractional rate divider clock output as the source, * - disable 4-pin mode * - MCLK ouput is disable * - Frequency = 44.1 kHz (x=8,y=51 - automatic setting) * Because we use mode I2STXMODE[3:0]= 0000, I2SDAO[5]=0 and * I2SRX[3:0]=0000, I2SDAI[5] = 1. So we have I2SRX_CLK = I2STX_CLK * --> I2SRXBITRATE = 1 (not divide TXCLK to produce RXCLK) */ /* Audio Config*/ I2S_ConfigStruct.wordwidth = I2S_WORDWIDTH_16; I2S_ConfigStruct.mono = I2S_STEREO; I2S_ConfigStruct.stop = I2S_STOP_ENABLE; I2S_ConfigStruct.reset = I2S_RESET_ENABLE; I2S_ConfigStruct.ws_sel = I2S_MASTER_MODE; I2S_ConfigStruct.mute = I2S_MUTE_DISABLE; I2S_Config(LPC_I2S,I2S_TX_MODE,&I2S_ConfigStruct); I2S_ConfigStruct.ws_sel = I2S_SLAVE_MODE; I2S_Config(LPC_I2S,I2S_RX_MODE,&I2S_ConfigStruct); /* Clock Mode Config*/ I2S_ClkConfig.clksel = I2S_CLKSEL_FRDCLK; I2S_ClkConfig.fpin = I2S_4PIN_DISABLE; I2S_ClkConfig.mcena = I2S_MCLK_DISABLE; I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_TX_MODE); I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_RX_MODE); /* Set up frequency and bit rate*/ I2S_FreqConfig(LPC_I2S, 44100, I2S_TX_MODE); I2S_SetBitRate(LPC_I2S, 0, I2S_RX_MODE); I2S_Start(LPC_I2S); while(I2STXDone == 0||I2SRXDone == 0){ if(I2STXDone ==0){ I2S_Send(LPC_I2S,I2STXBuffer[I2SWriteLength]); I2SWriteLength +=1; if(I2SWriteLength == BUFFER_SIZE) I2STXDone = 1; } if(I2SRXDone == 0) { while(I2S_GetLevel(LPC_I2S,I2S_RX_MODE)==0x00); if(dummy == 0) //dummy receive { i = I2S_Receive(LPC_I2S); dummy = 1; } else { *(uint32_t *)(&I2SRXBuffer[I2SReadLength]) = I2S_Receive(LPC_I2S); I2SReadLength +=1; } if(I2SReadLength == BUFFER_SIZE) I2SRXDone = 1; } } /* print received data */ _DBG_("Receive Buffer data: ..."); for(i=0;i<BUFFER_SIZE;i++) { _DBH32(I2SRXBuffer[i]);_DBG_(""); } /* Validate received data */ if(Buffer_Verify()) { _DBG_("Verify Buffer: OK..."); } else { _DBG_("Verify Buffer: ERROR..."); } I2S_DeInit(LPC_I2S); while(1); }