Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of flash_audio_playerI2S by
main.cpp
00001 #include "mbed.h" 00002 //I2S Demo to display values from I2S microphone 00003 // 00004 //Only works on mbed LPC1768 - I2S is not an mbed API! 00005 //Microphone used is SPH0645LM4H 00006 //see https://www.adafruit.com/product/3421 00007 00008 #include "I2S.h" 00009 //uses patched mbed I2S library from 00010 //https://os.mbed.com/users/p07gbar/code/I2S/ 00011 //Needed a typo patch - clock was swapped p30/p15 in pin function setup code 00012 //"if (_clk == p15)" changed to "if (_clk != p15)" in I2S.cpp line 494 00013 BusOut mylevel(LED4,LED3,LED2,LED1); 00014 //4 built in mbed LEDs display audio level 00015 00016 #define sample_freq 32000.0 00017 00018 //Uses I2S hardware for input 00019 I2S i2srx(I2S_RECEIVE, p17, p16, p15); 00020 //p17(PWM value sent as serial data bit) <-> Dout 00021 //p16(WS) <-> LRC left/right channel clock 00022 //p15(bit clock) <-> BCLK 00023 00024 volatile int i=0; 00025 00026 void i2s_isr() //interrupt routine to read microphone 00027 { 00028 i = i2srx.read();//read value using I2S input 00029 mylevel = (i>>7)& 0xF; //Display Audio Level on 4 LEDs 00030 } 00031 int main() 00032 { 00033 i2srx.stereomono(I2S_MONO);//mono not stereo mode 00034 i2srx.masterslave(I2S_MASTER);//master drives clocks 00035 i2srx.frequency(sample_freq);//set sample freq 00036 i2srx.set_interrupt_fifo_level(1);//interrupt on one sample 00037 i2srx.attach(&i2s_isr);//set I2S ISR 00038 i2srx.start();//start I2S and interrupts 00039 while(1) { 00040 printf("%X\n\r",(i>>16)&(0x0000FFFF)); 00041 wait(0.5); 00042 } 00043 }
Generated on Tue Jul 12 2022 20:13:25 by
1.7.2
