Skip to content

Commit b49c17d

Browse files
authored
Merge pull request #182 from sandeepmistry/i2s
Add I2S support
2 parents 8a200ca + 5a033fe commit b49c17d

File tree

14 files changed

+1536
-0
lines changed

14 files changed

+1536
-0
lines changed

cores/arduino/wiring.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ void init( void )
6565
// Capture error
6666
while ( 1 ) ;
6767
}
68+
NVIC_SetPriority (SysTick_IRQn, (1 << __NVIC_PRIO_BITS) - 2); /* set Priority for Systick Interrupt (2nd lowest) */
6869

6970
// Clock PORT for Digital I/O
7071
// PM->APBBMASK.reg |= PM_APBBMASK_PORT ;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
This example reads audio data from an Invensense's ICS43432 I2S microphone
3+
breakout board, and prints out the samples to the Serial console. The
4+
Serial Plotter built into the Arduino IDE can be used to plot the audio
5+
data (Tools -> Serial Plotter)
6+
7+
Circuit:
8+
* Arduino/Genuino Zero or MKR1000 board
9+
* ICS43432:
10+
* GND connected GND
11+
* 3.3V connected 3.3V
12+
* WS connected to pin 0 (Zero) or pin 3 (MKR1000)
13+
* CLK connected to pin 1 (Zero) or pin 2 (MKR1000)
14+
* SD connected to pin 9 (Zero) or pin A6 (MKR1000)
15+
16+
created 17 November 2016
17+
by Sandeep Mistry
18+
*/
19+
20+
#include <I2S.h>
21+
22+
void setup() {
23+
// Open serial communications and wait for port to open:
24+
// A baud rate of 115200 is used instead of 9600 for a faster data rate
25+
// on non-native USB ports
26+
Serial.begin(115200);
27+
while (!Serial) {
28+
; // wait for serial port to connect. Needed for native USB port only
29+
}
30+
31+
// start I2S at 8 kHz with 32-bits per sample
32+
if (I2S.begin(I2S_PHILIPS_MODE, 8000, 32)) {
33+
Serial.println("Failed to initialize I2S!");
34+
while (1); // do nothing
35+
}
36+
}
37+
38+
void loop() {
39+
// read a sample
40+
int sample = I2S.read();
41+
42+
if (sample) {
43+
// if it's non-zero print value to serial
44+
Serial.println(sample);
45+
}
46+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
This example generates a square wave based tone at a specified frequency
3+
and sample rate. Then outputs the data using the I2S interface to a
4+
MAX08357 I2S Amp Breakout board.
5+
6+
Circuit:
7+
* Arduino/Genuino Zero or MKR1000 board
8+
* MAX08357:
9+
* GND connected GND
10+
* VIN connected 5V
11+
* LRC connected to pin 0 (Zero) or pin 3 (MKR1000)
12+
* BCLK connected to pin 1 (Zero) or pin 2 (MKR1000)
13+
* DIN connected to pin 9 (Zero) or pin A6 (MKR1000)
14+
15+
created 17 November 2016
16+
by Sandeep Mistry
17+
*/
18+
19+
#include <I2S.h>
20+
21+
const int frequency = 440; // frequency of square wave in Hz
22+
const int amplitude = 500; // amplitude of square wave
23+
const int sampleRate = 8000; // sample rate in Hz
24+
25+
const int halfWavelength = (sampleRate / frequency); // half wavelength of square wave
26+
27+
short sample = amplitude; // current sample value
28+
int count = 0;
29+
30+
void setup() {
31+
Serial.begin(9600);
32+
Serial.println("I2S simple tone");
33+
34+
// start I2S at the sample rate with 16-bits per sample
35+
if (I2S.begin(I2S_PHILIPS_MODE, sampleRate, 16)) {
36+
Serial.println("Failed to initialize I2S!");
37+
while (1); // do nothing
38+
}
39+
}
40+
41+
void loop() {
42+
if (count % halfWavelength == 0) {
43+
// invert the sample every half wavelength count multiple to generate square wave
44+
sample = -1 * sample;
45+
}
46+
47+
// write the same sample twice, once for left and once for the right channel
48+
I2S.write(sample);
49+
I2S.write(sample);
50+
51+
// increment the counter for the next sample
52+
count++;
53+
}

libraries/I2S/keywords.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#######################################
2+
# Syntax Coloring Map I2S
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
I2S KEYWORD1
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2)
13+
#######################################
14+
begin KEYWORD2
15+
end KEYWORD2
16+
17+
onReceive KEYWORD2
18+
onTransmit KEYWORD2
19+
20+
#######################################
21+
# Constants (LITERAL1)
22+
#######################################
23+
I2S_PHILIPS_MODE LITERAL1
24+
I2S_RIGHT_JUSTIFIED_MODE LITERAL1
25+
I2S_LEFT_JUSTIFIED_MODE LITERAL1

libraries/I2S/library.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=I2S
2+
version=1.0
3+
author=Arduino
4+
maintainer=Arduino <info@arduino.cc>
5+
sentence=Enables the communication with devices that use the Inter-IC Sound (I2S) Bus. Specific implementation for Arduino Zero.
6+
paragraph=
7+
category=Communication
8+
url=http://www.arduino.cc/en/Reference/I2S
9+
architectures=samd

0 commit comments

Comments
 (0)