Skip to content

Add I2S support #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cores/arduino/wiring.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void init( void )
// Capture error
while ( 1 ) ;
}
NVIC_SetPriority (SysTick_IRQn, (1 << __NVIC_PRIO_BITS) - 2); /* set Priority for Systick Interrupt (2nd lowest) */

// Clock PORT for Digital I/O
// PM->APBBMASK.reg |= PM_APBBMASK_PORT ;
Expand Down
46 changes: 46 additions & 0 deletions libraries/I2S/examples/InputSerialPlotter/InputSerialPlotter.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
This example reads audio data from an Invensense's ICS43432 I2S microphone
breakout board, and prints out the samples to the Serial console. The
Serial Plotter built into the Arduino IDE can be used to plot the audio
data (Tools -> Serial Plotter)

Circuit:
* Arduino/Genuino Zero or MKR1000 board
* ICS43432:
* GND connected GND
* 3.3V connected 3.3V
* WS connected to pin 0 (Zero) or pin 3 (MKR1000)
* CLK connected to pin 1 (Zero) or pin 2 (MKR1000)
* SD connected to pin 9 (Zero) or pin A6 (MKR1000)

created 17 November 2016
by Sandeep Mistry
*/

#include <I2S.h>

void setup() {
// Open serial communications and wait for port to open:
// A baud rate of 115200 is used instead of 9600 for a faster data rate
// on non-native USB ports
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

// start I2S at 8 kHz with 32-bits per sample
if (I2S.begin(I2S_PHILIPS_MODE, 8000, 32)) {
Serial.println("Failed to initialize I2S!");
while (1); // do nothing
}
}

void loop() {
// read a sample
int sample = I2S.read();

if (sample) {
// if it's non-zero print value to serial
Serial.println(sample);
}
}
53 changes: 53 additions & 0 deletions libraries/I2S/examples/SimpleTone/SimpleTone.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
This example generates a square wave based tone at a specified frequency
and sample rate. Then outputs the data using the I2S interface to a
MAX08357 I2S Amp Breakout board.

Circuit:
* Arduino/Genuino Zero or MKR1000 board
* MAX08357:
* GND connected GND
* VIN connected 5V
* LRC connected to pin 0 (Zero) or pin 3 (MKR1000)
* BCLK connected to pin 1 (Zero) or pin 2 (MKR1000)
* DIN connected to pin 9 (Zero) or pin A6 (MKR1000)

created 17 November 2016
by Sandeep Mistry
*/

#include <I2S.h>

const int frequency = 440; // frequency of square wave in Hz
const int amplitude = 500; // amplitude of square wave
const int sampleRate = 8000; // sample rate in Hz

const int halfWavelength = (sampleRate / frequency); // half wavelength of square wave

short sample = amplitude; // current sample value
int count = 0;

void setup() {
Serial.begin(9600);
Serial.println("I2S simple tone");

// start I2S at the sample rate with 16-bits per sample
if (I2S.begin(I2S_PHILIPS_MODE, sampleRate, 16)) {
Serial.println("Failed to initialize I2S!");
while (1); // do nothing
}
}

void loop() {
if (count % halfWavelength == 0) {
// invert the sample every half wavelength count multiple to generate square wave
sample = -1 * sample;
}

// write the same sample twice, once for left and once for the right channel
I2S.write(sample);
I2S.write(sample);

// increment the counter for the next sample
count++;
}
25 changes: 25 additions & 0 deletions libraries/I2S/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#######################################
# Syntax Coloring Map I2S
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

I2S KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################
begin KEYWORD2
end KEYWORD2

onReceive KEYWORD2
onTransmit KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################
I2S_PHILIPS_MODE LITERAL1
I2S_RIGHT_JUSTIFIED_MODE LITERAL1
I2S_LEFT_JUSTIFIED_MODE LITERAL1
9 changes: 9 additions & 0 deletions libraries/I2S/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=I2S
version=1.0
author=Arduino
maintainer=Arduino <[email protected]>
sentence=Enables the communication with devices that use the Inter-IC Sound (I2S) Bus. Specific implementation for Arduino Zero.
paragraph=
category=Communication
url=http://www.arduino.cc/en/Reference/I2S
architectures=samd
Loading