These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Committer:
frank26080115
Date:
Sun Mar 20 05:38:56 2011 +0000
Revision:
0:bf7b9fba3924

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frank26080115 0:bf7b9fba3924 1 /***********************************************************************//**
frank26080115 0:bf7b9fba3924 2 * @file i2s_test_4_wire.c
frank26080115 0:bf7b9fba3924 3 * @purpose This example describes how to use I2S 4-wire mode
frank26080115 0:bf7b9fba3924 4 * @version 2.0
frank26080115 0:bf7b9fba3924 5 * @date 21. May. 2010
frank26080115 0:bf7b9fba3924 6 * @author NXP MCU SW Application Team
frank26080115 0:bf7b9fba3924 7 *---------------------------------------------------------------------
frank26080115 0:bf7b9fba3924 8 * Software that is described herein is for illustrative purposes only
frank26080115 0:bf7b9fba3924 9 * which provides customers with programming information regarding the
frank26080115 0:bf7b9fba3924 10 * products. This software is supplied "AS IS" without any warranties.
frank26080115 0:bf7b9fba3924 11 * NXP Semiconductors assumes no responsibility or liability for the
frank26080115 0:bf7b9fba3924 12 * use of the software, conveys no license or title under any patent,
frank26080115 0:bf7b9fba3924 13 * copyright, or mask work right to the product. NXP Semiconductors
frank26080115 0:bf7b9fba3924 14 * reserves the right to make changes in the software without
frank26080115 0:bf7b9fba3924 15 * notification. NXP Semiconductors also make no representation or
frank26080115 0:bf7b9fba3924 16 * warranty that such application will be suitable for the specified
frank26080115 0:bf7b9fba3924 17 * use without further testing or modification.
frank26080115 0:bf7b9fba3924 18 **********************************************************************/
frank26080115 0:bf7b9fba3924 19 #include "lpc17xx_i2s.h"
frank26080115 0:bf7b9fba3924 20 #include "lpc17xx_libcfg.h"
frank26080115 0:bf7b9fba3924 21 #include "lpc17xx_pinsel.h"
frank26080115 0:bf7b9fba3924 22 #include "debug_frmwrk.h"
frank26080115 0:bf7b9fba3924 23
frank26080115 0:bf7b9fba3924 24 /* Example group ----------------------------------------------------------- */
frank26080115 0:bf7b9fba3924 25 /** @defgroup I2S_test_4_wire I2S_test_4_wire
frank26080115 0:bf7b9fba3924 26 * @ingroup I2S_Examples
frank26080115 0:bf7b9fba3924 27 * @{
frank26080115 0:bf7b9fba3924 28 */
frank26080115 0:bf7b9fba3924 29
frank26080115 0:bf7b9fba3924 30 ///************************** PRIVATE DEFINITIONS *************************/
frank26080115 0:bf7b9fba3924 31 /** Max buffer length */
frank26080115 0:bf7b9fba3924 32 #define BUFFER_SIZE 0x400
frank26080115 0:bf7b9fba3924 33 /** I2S Buffer Source Address is AHBRAM1_BASE that used for USB RAM purpose, but
frank26080115 0:bf7b9fba3924 34 * it is not used in this example, so this memory section can be used for general purpose
frank26080115 0:bf7b9fba3924 35 * memory
frank26080115 0:bf7b9fba3924 36 */
frank26080115 0:bf7b9fba3924 37 #define I2S_BUFFER_SRC LPC_AHBRAM1_BASE
frank26080115 0:bf7b9fba3924 38 /** I2S Buffer Destination Address is (AHBRAM1_BASE + 0x100UL) that used for USB RAM purpose, but
frank26080115 0:bf7b9fba3924 39 * it is not used in this example, so this memory section can be used for general purpose
frank26080115 0:bf7b9fba3924 40 * memory
frank26080115 0:bf7b9fba3924 41 */
frank26080115 0:bf7b9fba3924 42 #define I2S_BUFFER_DST (I2S_BUFFER_SRC+0x1000UL)
frank26080115 0:bf7b9fba3924 43
frank26080115 0:bf7b9fba3924 44 /************************** PRIVATE VARIABLES ***********************/
frank26080115 0:bf7b9fba3924 45 uint8_t menu[]=
frank26080115 0:bf7b9fba3924 46 "********************************************************************************\n\r"
frank26080115 0:bf7b9fba3924 47 "Hello NXP Semiconductors \n\r"
frank26080115 0:bf7b9fba3924 48 " I2S 4-wire demo \n\r"
frank26080115 0:bf7b9fba3924 49 "\t - MCU: LPC17xx \n\r"
frank26080115 0:bf7b9fba3924 50 "\t - Core: ARM CORTEX-M3 \n\r"
frank26080115 0:bf7b9fba3924 51 "\t - Communicate via: UART0 - 115200 bps \n\r"
frank26080115 0:bf7b9fba3924 52 " Use two I2S channels in the same board to transfer data in 4-wire mode\n\r"
frank26080115 0:bf7b9fba3924 53 "********************************************************************************\n\r";
frank26080115 0:bf7b9fba3924 54 volatile uint8_t I2STXDone = 0;
frank26080115 0:bf7b9fba3924 55 volatile uint8_t I2SRXDone = 0;
frank26080115 0:bf7b9fba3924 56
frank26080115 0:bf7b9fba3924 57 volatile uint32_t *I2STXBuffer = (uint32_t*)(I2S_BUFFER_SRC);
frank26080115 0:bf7b9fba3924 58 volatile uint32_t *I2SRXBuffer = (uint32_t *)(I2S_BUFFER_DST);
frank26080115 0:bf7b9fba3924 59
frank26080115 0:bf7b9fba3924 60 volatile uint32_t I2SReadLength = 0;
frank26080115 0:bf7b9fba3924 61 volatile uint32_t I2SWriteLength = 0;
frank26080115 0:bf7b9fba3924 62
frank26080115 0:bf7b9fba3924 63
frank26080115 0:bf7b9fba3924 64 /************************** PRIVATE FUNCTIONS *************************/
frank26080115 0:bf7b9fba3924 65 void Buffer_Init(void);
frank26080115 0:bf7b9fba3924 66 Bool Buffer_Verify(void);
frank26080115 0:bf7b9fba3924 67 void print_menu(void);
frank26080115 0:bf7b9fba3924 68
frank26080115 0:bf7b9fba3924 69 /*-------------------------PRIVATE FUNCTIONS------------------------------*/
frank26080115 0:bf7b9fba3924 70 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 71 * @brief Initialize buffer
frank26080115 0:bf7b9fba3924 72 * @param[in] None
frank26080115 0:bf7b9fba3924 73 * @return None
frank26080115 0:bf7b9fba3924 74 **********************************************************************/
frank26080115 0:bf7b9fba3924 75 void Buffer_Init(void) {
frank26080115 0:bf7b9fba3924 76 uint32_t i;
frank26080115 0:bf7b9fba3924 77
frank26080115 0:bf7b9fba3924 78 for (i = 0; i < BUFFER_SIZE; i++) {
frank26080115 0:bf7b9fba3924 79 I2STXBuffer[i] = i;
frank26080115 0:bf7b9fba3924 80 I2SRXBuffer[i] = 0;
frank26080115 0:bf7b9fba3924 81 }
frank26080115 0:bf7b9fba3924 82 }
frank26080115 0:bf7b9fba3924 83
frank26080115 0:bf7b9fba3924 84 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 85 * @brief Verify buffer
frank26080115 0:bf7b9fba3924 86 * @param[in] none
frank26080115 0:bf7b9fba3924 87 * @return TRUE - if two buffers are similar
frank26080115 0:bf7b9fba3924 88 * FALSE - if two buffers are different
frank26080115 0:bf7b9fba3924 89 **********************************************************************/
frank26080115 0:bf7b9fba3924 90 Bool Buffer_Verify(void) {
frank26080115 0:bf7b9fba3924 91 uint32_t i;
frank26080115 0:bf7b9fba3924 92 uint32_t *pTX = (uint32_t *) &I2STXBuffer[0];
frank26080115 0:bf7b9fba3924 93 /* Generally, first element of RX buffer is a dummy data, so
frank26080115 0:bf7b9fba3924 94 * it will be discarded
frank26080115 0:bf7b9fba3924 95 */
frank26080115 0:bf7b9fba3924 96 uint32_t *pRX = (uint32_t *) &I2SRXBuffer[1];
frank26080115 0:bf7b9fba3924 97
frank26080115 0:bf7b9fba3924 98 for (i = 1; i < BUFFER_SIZE; i++) {
frank26080115 0:bf7b9fba3924 99 if (*pTX++ != *pRX++) {
frank26080115 0:bf7b9fba3924 100 return FALSE;
frank26080115 0:bf7b9fba3924 101 }
frank26080115 0:bf7b9fba3924 102 }
frank26080115 0:bf7b9fba3924 103 return TRUE;
frank26080115 0:bf7b9fba3924 104 }
frank26080115 0:bf7b9fba3924 105 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 106 * @brief Print menu
frank26080115 0:bf7b9fba3924 107 * @param[in] none
frank26080115 0:bf7b9fba3924 108 * @return None
frank26080115 0:bf7b9fba3924 109 **********************************************************************/
frank26080115 0:bf7b9fba3924 110 void print_menu(void)
frank26080115 0:bf7b9fba3924 111 {
frank26080115 0:bf7b9fba3924 112 _DBG_(menu);
frank26080115 0:bf7b9fba3924 113 }
frank26080115 0:bf7b9fba3924 114
frank26080115 0:bf7b9fba3924 115 /*-------------------------MAIN FUNCTION------------------------------*/
frank26080115 0:bf7b9fba3924 116 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 117 * @brief c_entry: Main I2S program body
frank26080115 0:bf7b9fba3924 118 * @param[in] None
frank26080115 0:bf7b9fba3924 119 * @return int
frank26080115 0:bf7b9fba3924 120 **********************************************************************/
frank26080115 0:bf7b9fba3924 121 int c_entry (void) {
frank26080115 0:bf7b9fba3924 122 uint32_t i;
frank26080115 0:bf7b9fba3924 123 uint8_t dummy=0;
frank26080115 0:bf7b9fba3924 124 I2S_MODEConf_Type I2S_ClkConfig;
frank26080115 0:bf7b9fba3924 125 I2S_CFG_Type I2S_ConfigStruct;
frank26080115 0:bf7b9fba3924 126 PINSEL_CFG_Type PinCfg;
frank26080115 0:bf7b9fba3924 127
frank26080115 0:bf7b9fba3924 128 /* Initialize debug via UART0
frank26080115 0:bf7b9fba3924 129 * – 115200bps
frank26080115 0:bf7b9fba3924 130 * – 8 data bit
frank26080115 0:bf7b9fba3924 131 * – No parity
frank26080115 0:bf7b9fba3924 132 * – 1 stop bit
frank26080115 0:bf7b9fba3924 133 * – No flow control
frank26080115 0:bf7b9fba3924 134 */
frank26080115 0:bf7b9fba3924 135 debug_frmwrk_init();
frank26080115 0:bf7b9fba3924 136
frank26080115 0:bf7b9fba3924 137 //print menu screen
frank26080115 0:bf7b9fba3924 138 print_menu();
frank26080115 0:bf7b9fba3924 139
frank26080115 0:bf7b9fba3924 140 Buffer_Init();
frank26080115 0:bf7b9fba3924 141
frank26080115 0:bf7b9fba3924 142 /* Pin configuration:
frank26080115 0:bf7b9fba3924 143 * Assign: - P0.4 as I2SRX_CLK
frank26080115 0:bf7b9fba3924 144 * - P0.5 as I2SRX_WS
frank26080115 0:bf7b9fba3924 145 * - P0.6 as I2SRX_SDA
frank26080115 0:bf7b9fba3924 146 * - P0.7 as I2STX_CLK
frank26080115 0:bf7b9fba3924 147 * - P0.8 as I2STX_WS
frank26080115 0:bf7b9fba3924 148 * - P0.9 as I2STX_SDA
frank26080115 0:bf7b9fba3924 149 */
frank26080115 0:bf7b9fba3924 150 PinCfg.Funcnum = 1;
frank26080115 0:bf7b9fba3924 151 PinCfg.OpenDrain = 0;
frank26080115 0:bf7b9fba3924 152 PinCfg.Pinmode = 0;
frank26080115 0:bf7b9fba3924 153 PinCfg.Pinnum = 4;
frank26080115 0:bf7b9fba3924 154 PinCfg.Portnum = 0;
frank26080115 0:bf7b9fba3924 155 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 156 PinCfg.Pinnum = 5;
frank26080115 0:bf7b9fba3924 157 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 158 PinCfg.Pinnum = 6;
frank26080115 0:bf7b9fba3924 159 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 160 PinCfg.Pinnum = 7;
frank26080115 0:bf7b9fba3924 161 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 162 PinCfg.Pinnum = 8;
frank26080115 0:bf7b9fba3924 163 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 164 PinCfg.Pinnum = 9;
frank26080115 0:bf7b9fba3924 165 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 166
frank26080115 0:bf7b9fba3924 167 I2S_Init(LPC_I2S);
frank26080115 0:bf7b9fba3924 168
frank26080115 0:bf7b9fba3924 169 //Setup for I2S: RX is similar with TX
frank26080115 0:bf7b9fba3924 170 /* setup:
frank26080115 0:bf7b9fba3924 171 * - wordwidth: 16 bits
frank26080115 0:bf7b9fba3924 172 * - stereo mode
frank26080115 0:bf7b9fba3924 173 * - master mode for I2S_TX and slave for I2S_RX
frank26080115 0:bf7b9fba3924 174 * - ws_halfperiod is 31
frank26080115 0:bf7b9fba3924 175 * - not use mute mode
frank26080115 0:bf7b9fba3924 176 * - use reset and stop mode
frank26080115 0:bf7b9fba3924 177 * - select the fractional rate divider clock output as the source,
frank26080115 0:bf7b9fba3924 178 * - disable 4-pin mode
frank26080115 0:bf7b9fba3924 179 * - MCLK ouput is disable
frank26080115 0:bf7b9fba3924 180 * - Frequency = 44.1 kHz (x=8,y=51 - automatic setting)
frank26080115 0:bf7b9fba3924 181 * Because we use mode I2STXMODE[3:0]= 0000, I2SDAO[5]=0 and
frank26080115 0:bf7b9fba3924 182 * I2SRX[3:0]=0000, I2SDAI[5] = 1. So we have I2SRX_CLK = I2STX_CLK
frank26080115 0:bf7b9fba3924 183 * --> I2SRXBITRATE = 1 (not divide TXCLK to produce RXCLK)
frank26080115 0:bf7b9fba3924 184 */
frank26080115 0:bf7b9fba3924 185
frank26080115 0:bf7b9fba3924 186 /* Audio Config*/
frank26080115 0:bf7b9fba3924 187 I2S_ConfigStruct.wordwidth = I2S_WORDWIDTH_16;
frank26080115 0:bf7b9fba3924 188 I2S_ConfigStruct.mono = I2S_STEREO;
frank26080115 0:bf7b9fba3924 189 I2S_ConfigStruct.stop = I2S_STOP_ENABLE;
frank26080115 0:bf7b9fba3924 190 I2S_ConfigStruct.reset = I2S_RESET_ENABLE;
frank26080115 0:bf7b9fba3924 191 I2S_ConfigStruct.ws_sel = I2S_MASTER_MODE;
frank26080115 0:bf7b9fba3924 192 I2S_ConfigStruct.mute = I2S_MUTE_DISABLE;
frank26080115 0:bf7b9fba3924 193 I2S_Config(LPC_I2S,I2S_TX_MODE,&I2S_ConfigStruct);
frank26080115 0:bf7b9fba3924 194
frank26080115 0:bf7b9fba3924 195 I2S_ConfigStruct.ws_sel = I2S_SLAVE_MODE;
frank26080115 0:bf7b9fba3924 196 I2S_Config(LPC_I2S,I2S_RX_MODE,&I2S_ConfigStruct);
frank26080115 0:bf7b9fba3924 197
frank26080115 0:bf7b9fba3924 198 /* Clock Mode Config*/
frank26080115 0:bf7b9fba3924 199 I2S_ClkConfig.clksel = I2S_CLKSEL_FRDCLK;
frank26080115 0:bf7b9fba3924 200 I2S_ClkConfig.fpin = I2S_4PIN_DISABLE;
frank26080115 0:bf7b9fba3924 201 I2S_ClkConfig.mcena = I2S_MCLK_DISABLE;
frank26080115 0:bf7b9fba3924 202 I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_TX_MODE);
frank26080115 0:bf7b9fba3924 203 I2S_ClkConfig.fpin = I2S_4PIN_ENABLE;
frank26080115 0:bf7b9fba3924 204 I2S_ModeConfig(LPC_I2S,&I2S_ClkConfig,I2S_RX_MODE);
frank26080115 0:bf7b9fba3924 205
frank26080115 0:bf7b9fba3924 206 /* Set up frequency and bit rate*/
frank26080115 0:bf7b9fba3924 207 I2S_FreqConfig(LPC_I2S, 44100, I2S_TX_MODE);
frank26080115 0:bf7b9fba3924 208
frank26080115 0:bf7b9fba3924 209 I2S_Start(LPC_I2S);
frank26080115 0:bf7b9fba3924 210 while(I2STXDone == 0||I2SRXDone == 0){
frank26080115 0:bf7b9fba3924 211 if(I2STXDone ==0){
frank26080115 0:bf7b9fba3924 212 while (I2S_GetLevel(LPC_I2S,I2S_TX_MODE)!=0x00);
frank26080115 0:bf7b9fba3924 213 I2S_Send(LPC_I2S,I2STXBuffer[I2SWriteLength]);
frank26080115 0:bf7b9fba3924 214 I2SWriteLength +=1;
frank26080115 0:bf7b9fba3924 215 if(I2SWriteLength == BUFFER_SIZE) I2STXDone = 1;
frank26080115 0:bf7b9fba3924 216
frank26080115 0:bf7b9fba3924 217 }
frank26080115 0:bf7b9fba3924 218 if(I2SRXDone == 0)
frank26080115 0:bf7b9fba3924 219 {
frank26080115 0:bf7b9fba3924 220 while(I2S_GetLevel(LPC_I2S,I2S_RX_MODE)==0x00);
frank26080115 0:bf7b9fba3924 221 if(dummy == 0) //dummy receive
frank26080115 0:bf7b9fba3924 222 {
frank26080115 0:bf7b9fba3924 223 i = I2S_Receive(LPC_I2S);
frank26080115 0:bf7b9fba3924 224 dummy = 1;
frank26080115 0:bf7b9fba3924 225 }
frank26080115 0:bf7b9fba3924 226 else
frank26080115 0:bf7b9fba3924 227 {
frank26080115 0:bf7b9fba3924 228 *(uint32_t *)(&I2SRXBuffer[I2SReadLength]) = I2S_Receive(LPC_I2S);
frank26080115 0:bf7b9fba3924 229 I2SReadLength +=1;
frank26080115 0:bf7b9fba3924 230 }
frank26080115 0:bf7b9fba3924 231 if(I2SReadLength == BUFFER_SIZE) I2SRXDone = 1;
frank26080115 0:bf7b9fba3924 232 }
frank26080115 0:bf7b9fba3924 233 }
frank26080115 0:bf7b9fba3924 234 for(i=0;i<BUFFER_SIZE;i++)
frank26080115 0:bf7b9fba3924 235 {
frank26080115 0:bf7b9fba3924 236 _DBH32(I2SRXBuffer[i]);_DBG_("");
frank26080115 0:bf7b9fba3924 237 }
frank26080115 0:bf7b9fba3924 238 if(Buffer_Verify())
frank26080115 0:bf7b9fba3924 239 {
frank26080115 0:bf7b9fba3924 240 _DBG_("Verify Buffer: OK...");
frank26080115 0:bf7b9fba3924 241 }
frank26080115 0:bf7b9fba3924 242 else
frank26080115 0:bf7b9fba3924 243 {
frank26080115 0:bf7b9fba3924 244 _DBG_("Verify Buffer: ERROR...");
frank26080115 0:bf7b9fba3924 245 }
frank26080115 0:bf7b9fba3924 246 while(1);
frank26080115 0:bf7b9fba3924 247 }
frank26080115 0:bf7b9fba3924 248
frank26080115 0:bf7b9fba3924 249 /* With ARM and GHS toolsets, the entry point is main() - this will
frank26080115 0:bf7b9fba3924 250 allow the linker to generate wrapper code to setup stacks, allocate
frank26080115 0:bf7b9fba3924 251 heap area, and initialize and copy code and data segments. For GNU
frank26080115 0:bf7b9fba3924 252 toolsets, the entry point is through __start() in the crt0_gnu.asm
frank26080115 0:bf7b9fba3924 253 file, and that startup code will setup stacks and data */
frank26080115 0:bf7b9fba3924 254 int main(void)
frank26080115 0:bf7b9fba3924 255 {
frank26080115 0:bf7b9fba3924 256 return c_entry();
frank26080115 0:bf7b9fba3924 257 }
frank26080115 0:bf7b9fba3924 258
frank26080115 0:bf7b9fba3924 259 #ifdef DEBUG
frank26080115 0:bf7b9fba3924 260 /*******************************************************************************
frank26080115 0:bf7b9fba3924 261 * @brief Reports the name of the source file and the source line number
frank26080115 0:bf7b9fba3924 262 * where the CHECK_PARAM error has occurred.
frank26080115 0:bf7b9fba3924 263 * @param[in] file Pointer to the source file name
frank26080115 0:bf7b9fba3924 264 * @param[in] line assert_param error line source number
frank26080115 0:bf7b9fba3924 265 * @return None
frank26080115 0:bf7b9fba3924 266 *******************************************************************************/
frank26080115 0:bf7b9fba3924 267 void check_failed(uint8_t *file, uint32_t line)
frank26080115 0:bf7b9fba3924 268 {
frank26080115 0:bf7b9fba3924 269 /* User can add his own implementation to report the file name and line number,
frank26080115 0:bf7b9fba3924 270 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
frank26080115 0:bf7b9fba3924 271
frank26080115 0:bf7b9fba3924 272 /* Infinite loop */
frank26080115 0:bf7b9fba3924 273 while(1);
frank26080115 0:bf7b9fba3924 274 }
frank26080115 0:bf7b9fba3924 275 #endif
frank26080115 0:bf7b9fba3924 276
frank26080115 0:bf7b9fba3924 277 /*
frank26080115 0:bf7b9fba3924 278 * @}
frank26080115 0:bf7b9fba3924 279 */