Saturday, March 8, 2008

Arduino & the ISD4002

I've been taking an engineering class this semester that focuses on designing electronics that produce music. We're all using the Arduino microcontroller platform, and one of our tasks is to get the ISD4002 chip (a sound recorder) communicating with the Arduino through SPI. I haven't been able to find any evidence of the ISD4002 chip working with the Arduino on Google, so hopefully this code will be useful to someone.

The following program first initializes SPI, Serial, and the ISD chip. The flow of the main loop is:
Record for 10 sec --> Pause 2 sec --> Play for 10 sec --> Pause for 2 sec.


#define DATAOUT 11 // MOSI
#define DATAIN 12 // MISO
#define SPICLOCK 13 // SCK
#define SLAVESELECT 10 // SS

#define ISD_OPCODE_POWERUP B00100
#define ISD_OPCODE_SETPLAY B00111
#define ISD_OPCODE_PLAY B01111
#define ISD_OPCODE_SETREC B00101
#define ISD_OPCODE_REC B01101
#define ISD_OPCODE_STOP B01100
#define ISD_OPCODE_POWERDOWN B00000
#define ISD_POWERUP_DELAY 25

char spi_transfer(volatile char data) {
SPDR = data;
while (!(SPSR & (1<<SPIF))) { }
return SPDR;
}

void spi_init() {
byte clr;
pinMode(DATAOUT, OUTPUT);
pinMode(DATAIN, INPUT);
pinMode(SPICLOCK, OUTPUT);
pinMode(SLAVESELECT, OUTPUT);

digitalWrite(SLAVESELECT, HIGH); // Disable device

SPCR = (1<<SPE)|(1<<MSTR);
clr=SPSR;
clr=SPDR;
delay(10);
}

void isd_send_command(unsigned char command, unsigned int address) {
digitalWrite(SLAVESELECT, LOW);
spi_transfer(address & 0xff);
spi_transfer(((address & 0xff00) >> 3) | command);
digitalWrite(SLAVESELECT, HIGH);
}

void isd_powerdown() {
Serial.println("Powering down...");
isd_send_command(ISD_OPCODE_POWERDOWN, 0);
}

void isd_powerup() {
Serial.println("Powering up...");
isd_send_command(ISD_OPCODE_POWERUP, 0);
delay(ISD_POWERUP_DELAY);
}

void isd_play(unsigned int address) {
Serial.println("Playing...");
isd_send_command(ISD_OPCODE_SETPLAY, address);
isd_send_command(ISD_OPCODE_PLAY, 0);
}

void isd_record(unsigned int address) {
Serial.println("Recording...");
isd_send_command(ISD_OPCODE_SETREC, address);
isd_send_command(ISD_OPCODE_REC, 0);
}

void isd_stop() {
Serial.println("Stopping...");
isd_send_command(ISD_OPCODE_STOP, 0);
}

void setup() {
spi_init();
Serial.begin(9600);
isd_powerup();
}

void loop() {
isd_record(0);
delay(10000);

isd_stop();
delay(2000);

isd_play(0);
delay(10000);

isd_stop();
delay(2000);
}

6 comments:

menuka said...

thanks for sharing this information..
do you also have schematic for this?thanks in advance


Mike

menuka said...

thanks for sharing this information..
do you also have schematic for this?thanks in advance

Anonymous said...

http://thechipcode.com/article.php?artical_id=141

Anonymous said...

ISD4002 Artcle in THECHIPCODE

Unknown said...
This comment has been removed by the author.
PatTheBuilder said...

I'm in an engineering class, and I'm making a loop pedal for my guitar with an Arduino Uno and the ISD4002. These wiring schematics don't want to pull up, could someone post another one?