Using microphones with filtering to attempt to spatially find aspects.
Fork of i2s_microphone by
main.cpp@2:04ffcc436ac0, 2018-01-26 (annotated)
- Committer:
- 4180_1
- Date:
- Fri Jan 26 00:55:11 2018 +0000
- Revision:
- 2:04ffcc436ac0
- Parent:
- 1:8fda76e11be8
ver 1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180_1 | 0:e4f991474a45 | 1 | #include "mbed.h" |
4180_1 | 2:04ffcc436ac0 | 2 | //I2S Demo to display values from I2S microphone |
4180_1 | 2:04ffcc436ac0 | 3 | // |
4180_1 | 2:04ffcc436ac0 | 4 | //Only works on mbed LPC1768 - I2S is not an mbed API! |
4180_1 | 2:04ffcc436ac0 | 5 | //Microphone used is SPH0645LM4H |
4180_1 | 2:04ffcc436ac0 | 6 | //see https://www.adafruit.com/product/3421 |
4180_1 | 2:04ffcc436ac0 | 7 | |
4180_1 | 1:8fda76e11be8 | 8 | #include "I2S.h" |
4180_1 | 2:04ffcc436ac0 | 9 | //uses patched mbed I2S library from |
4180_1 | 2:04ffcc436ac0 | 10 | //https://os.mbed.com/users/p07gbar/code/I2S/ |
4180_1 | 2:04ffcc436ac0 | 11 | //Needed a typo patch - clock was swapped p30/p15 in pin function setup code |
4180_1 | 2:04ffcc436ac0 | 12 | //"if (_clk == p15)" changed to "if (_clk != p15)" in I2S.cpp line 494 |
4180_1 | 2:04ffcc436ac0 | 13 | BusOut mylevel(LED4,LED3,LED2,LED1); |
4180_1 | 2:04ffcc436ac0 | 14 | //4 built in mbed LEDs display audio level |
4180_1 | 2:04ffcc436ac0 | 15 | |
4180_1 | 2:04ffcc436ac0 | 16 | #define sample_freq 32000.0 |
4180_1 | 1:8fda76e11be8 | 17 | |
4180_1 | 2:04ffcc436ac0 | 18 | //Uses I2S hardware for input |
4180_1 | 2:04ffcc436ac0 | 19 | I2S i2srx(I2S_RECEIVE, p17, p16, p15); |
4180_1 | 2:04ffcc436ac0 | 20 | //p17(PWM value sent as serial data bit) <-> Dout |
4180_1 | 2:04ffcc436ac0 | 21 | //p16(WS) <-> LRC left/right channel clock |
4180_1 | 2:04ffcc436ac0 | 22 | //p15(bit clock) <-> BCLK |
4180_1 | 2:04ffcc436ac0 | 23 | |
4180_1 | 2:04ffcc436ac0 | 24 | volatile int i=0; |
4180_1 | 0:e4f991474a45 | 25 | |
4180_1 | 2:04ffcc436ac0 | 26 | void i2s_isr() //interrupt routine to read microphone |
4180_1 | 2:04ffcc436ac0 | 27 | { |
4180_1 | 2:04ffcc436ac0 | 28 | i = i2srx.read();//read value using I2S input |
4180_1 | 2:04ffcc436ac0 | 29 | mylevel = (i>>7)& 0xF; //Display Audio Level on 4 LEDs |
4180_1 | 2:04ffcc436ac0 | 30 | } |
4180_1 | 2:04ffcc436ac0 | 31 | int main() |
4180_1 | 0:e4f991474a45 | 32 | { |
4180_1 | 2:04ffcc436ac0 | 33 | i2srx.stereomono(I2S_MONO);//mono not stereo mode |
4180_1 | 2:04ffcc436ac0 | 34 | i2srx.masterslave(I2S_MASTER);//master drives clocks |
4180_1 | 2:04ffcc436ac0 | 35 | i2srx.frequency(sample_freq);//set sample freq |
4180_1 | 2:04ffcc436ac0 | 36 | i2srx.set_interrupt_fifo_level(1);//interrupt on one sample |
4180_1 | 2:04ffcc436ac0 | 37 | i2srx.attach(&i2s_isr);//set I2S ISR |
4180_1 | 2:04ffcc436ac0 | 38 | i2srx.start();//start I2S and interrupts |
4180_1 | 2:04ffcc436ac0 | 39 | while(1) { |
4180_1 | 2:04ffcc436ac0 | 40 | printf("%X\n\r",(i>>16)&(0x0000FFFF)); |
4180_1 | 2:04ffcc436ac0 | 41 | wait(0.5); |
4180_1 | 0:e4f991474a45 | 42 | } |
4180_1 | 0:e4f991474a45 | 43 | } |