Go Down

Topic: Nuvoton ISD1700 Chip (Read 13261 times) previous topic - next topic

ramesh123

//**************************************************************
//  Module d'enregistrement de son IDS1760 autonome ou piloté par ARDUINO
//  tiptopboards.com
//  Code adapté de  http://forum.arduino.cc/index.php?topic=38867.0
//  Unsped 2008
//  Modifs en français  C Rolland 18 12 2013
//
//**************************************************************
// Broches Arduino utilisées
#define DATAOUT     11   //MOSI (bleu)
#define DATAIN      12   //MISO (vert)
#define SPICLOCK    13   //SCK (marron)
#define SLAVESELECT 10   //SS (rouge)
// Relier aussi les pins +5V et GND

// Codes de commandes de ISD1760 depuis l'Arduino
// Pour plus de détails voir ici http://www.electroniccircuits.gr/files/ISD1700.pdf
#define PU          0x01  //Power Up the device
#define STOP        0x02  //Stop the current operation
#define RESET       0x03  //Reset the device
#define CLR_INT     0x04  //Clear interrupt and OEM bit
#define RD_STATUS   0x05  //Return Returns status bits & current row counter in first 1st 2 bytes and operating status in 3rd byte
#define RD_PLAY_PTR 0x06  //Returns status bits & current row counter in 1st 2 bytes and Play pointer in 3rd & 4th bytes
#define PD          0x07  //Power Down
#define RD_REC_PTR  0x08  //Returns status bits & current row counter in 1st 2 bytes and Record pointer in 3rd & 4th bytes
#define DEVID       0x09  //Read the deivce ID register.
#define PLAY        0x40  //Play from current location without LED action until EOM or STOP command received
#define REC         0x41  //Record from current location without LED action until end of memory or STOP command received
#define ERASE       0x42  //Erase current message to EOM location
#define G_ERASE     0x43  //Erase all messages (not include Sound Effects)
#define RD_APC      0x44  //Returns status bits & current row counter in first 1st 2 bytes and the contents of APC register in 3rd & 4th bytes.
#define WR_APC1     0x45  //Write the data <D10:D0> into the APC register with volume setting from VOL pin
#define WR_APC2     0x65  //Write the data <D10:D0> into the APC register with volume setting from bits <D2:D0>
#define WR_NVCFG    0x46  //Write the contents of APC to NVCFG
#define LD_NVCFG    0x47  //Load contents of NVCFG to APC Register
#define FWD         0x48  //Forward play pointer to start address of next message. Forward will be ignored during operating, except Play
#define CHK_MEM     0x49  //Check circular memory
#define EXTCLK      0x4A  //Enable/disable external clock mode
#define SET_PLAY    0x80  //Play from start address <S10:S0> to end address <E10:E0> or stop at EOM, depending on the D11 of APC
#define SET_REC     0x81  //Record from start address <S10-S0> to end address <E10:E0>
#define SET_ERASE   0x82  //Erase from start address <S10:S0> to end address <E10:E0> [Stop cmd is ignored]


void setup() {
  // Configuration des 4 pins de commande
  byte clr;
  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK,OUTPUT);
  pinMode(SLAVESELECT,OUTPUT);
 
  digitalWrite(SLAVESELECT,HIGH); //disable device 
  SPCR = B01111111; //data lsb, clock high when idle, samples on falling
  clr=SPSR;
  clr=SPDR;
  delay(10);

  //Moniteur série
  Serial.begin(9600);
 
  digitalWrite(SLAVESELECT,LOW);  //Mettre le module en route
  spi_transfer(PU); // Power Up
  spi_transfer(0x00); // data byte
  digitalWrite(SLAVESELECT,HIGH);
  delay(100); 
  Serial.println("Power Up");

  digitalWrite(SLAVESELECT,LOW);  //Clear
  spi_transfer(CLR_INT); // Clear interupt and EOM bit
  spi_transfer(0x00); // data byte
  digitalWrite(SLAVESELECT,HIGH);
  delay(100);
  Serial.println("Clear");
}

void loop() {

  // Lire un son enregistré dans la mémoire flash puis passe au suivant, en boucle
  digitalWrite(SLAVESELECT,LOW);
  spi_transfer(PLAY); // PLAY écouter le son pointé par le curseur
  spi_transfer(0x00); // data byte
  digitalWrite(SLAVESELECT,HIGH);
  Serial.println("PLAY");
  ready_wait();  //Attendre la fin de ce son
  delay(3000);
 
  digitalWrite(SLAVESELECT,LOW);
  spi_transfer(FWD); // Décaler le curseur au son suivant
  spi_transfer(0x00); // data byte
  digitalWrite(SLAVESELECT,HIGH);
  Serial.println("FWD");
}

// Fonction ready_wait
void ready_wait(){
  byte byte1;
  byte byte2;
  byte byte3;
  //Pour savoir si le son est terminé, tester le 1er bit du 3eme octet MISO
  while(byte3<<7 != 128){
    digitalWrite(SLAVESELECT,LOW);
    byte1 = spi_transfer(RD_STATUS);
    // Returns status bits & current row counter in first 1st 2 bytes
    // and operating status in 3rd byte
    byte2 = spi_transfer(0x00); // data byte
    byte3 = spi_transfer(0x00); // data byte
    digitalWrite(SLAVESELECT,HIGH);
  }
  delay(100);
  }  //Fin de la fonction

char spi_transfer(volatile char data)
{
  SPDR = data;                    // Start the transmission
  while (!(SPSR & (1<<SPIF)))     // Wait for the end of the transmission
  {
  };
  return SPDR;                    // return the received byte
}

laserau77

Thanks remesh123.

Is this code fully working? 

There was no description so just making sure its a working piece of code not a question you wanted to ask.

Thanks for posting to the thread.

Go Up