[ PIC16F690 ] SPI with [ ISD1760 ] voice coder chip - MPLAB.

[ PIC16F690 ] SPI with [ ISD1760 ] voice coder chip - MPLAB.

Postby walo » Thu Oct 30, 2014 2:10 pm

Hello,
I have been working to design an SPI interface between the pic16f690 and isd1760 voice chip using MPLAB XC8
the purpose is to be able to play four 5second sounds depending on which switch is selected (4 switches, each plays a different sound).
I am able to get the ISD chip to play on standalone mode, but that doesn't allow random address access.
I've been working on this for the past 4 weeks with no luck, i think my main issue could be the code, any help is much appreciated

below is the code i have so far - just a basic PLAY_command (it is not working)
isd1700 design guide - http://www.microtechnica.tv/support/man ... _Guide.pdf

Code: Select all
#include <xc.h>
#include <pic.h>
#define _XTAL_FREQ 8000000

// CONFIG
#pragma config FOSC = INTRCIO   // Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON       // MCLR Pin Function Select bit (MCLR pin function is MCLR)
#pragma config CP = OFF         // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF        // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = OFF      // Brown-out Reset Selection bits (BOR disabled)
#pragma config IESO = OFF       // Internal External Switchover bit (Internal External Switchover mode is disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)


#define S0  RB5     //[record] switch
#define S1  RB7     //sound 1_ [play]switch
#define CS  RC6     //chip select
#define led1 RC5    //led

//function prototypes*********************
void init(void);
void tmr_delay(unsigned short lenght);
void spi_initialize(void);
unsigned char uc_send_receive_spi(unsigned char uc_data);

//void record_M1(void);
void play_M1(void);


void main(void){
    init();
   
    while(1){
        //delay(2000);    //short 2secs delay
        if (S1 == 0)    //[play]switch 1 pressed
        {
            while(S1 == 0) continue;    //wait for S1 release
            play_M1();
        }
    }
}


void init(void){
//i/o config************
    TRISA = 0b00000000;
    TRISB = 0b10100000; //s1,s2 inputs_ reset outputs
    TRISC = 0b00000000;

    PORTA = 0;      //CLR PORTA (0v)
//ADC OFF****************
    ANSEL = 0;
    ANSELH = 0;
//COMARATOR OFF**********
    CM1CON0 = 0;
    CM2CON0 = 0;
//TM0 CONFIG*************
    T0CS = 0;   //set timer 0 clock source to internal instruction clock cycle
    PSA = 0;    //assign prescaler to timer 0 module
    PS2 = 1;   //set timer 0 prescaler (bit 2)
    PS1 = 1;   //set timer 0 prescaler   (bit 1)
    PS0 = 1;   //set timer 0 prescaler   (bit 0)

    spi_initialize();// initialize SPI mode

    //reset ISD1790**********
   CS = 0;
        led1 = 0;
        //start receiving spi command
   uc_send_receive_spi(0b10000000);      //turn on spi
   uc_send_receive_spi(0b00000000);      //stop receiving spi command
   CS = 1;

   tmr_delay(10);                     //delay 100 milisecond

   CS = 0;
   uc_send_receive_spi(0b11000000);      //reset device
   uc_send_receive_spi(0b00000000);
   CS = 1;

   tmr_delay(10);                     //delay 100 milisecond

   CS = 0;
   uc_send_receive_spi(0b11100000);      //turn off spi
   uc_send_receive_spi(0b00000000);
   CS = 1;
        led1 = 1;
}
void tmr_delay(unsigned short lenght)   //delay lenght = given value*10ms
{               //delay using timer 0
   for( ;lenght>0;lenght-=1)
   {
      TMR0=0;         //clear timer 0 value
      while(TMR0<195);   //wait timer 0 value to reach 195 (10ms)
   }
}
void spi_initialize(void) //check 178-179
{
   // Set the SDO,SCL as output. SDI is automatically controlled by the SPI module.
   TRISC7 = 0;
        TRISB6 = 0;

   // Input data sampled at middle of data output time.
   SMP = 0;
        // Select SPI mode 1, 1.
   CKE = 0;      // Output data changes on transition from idle to active clock state.
   CKP = 1;      // Idle state for clock is a high level.

   // SPI Master mode, clock = FOSC/4.
   SSPM3 = 0;
   SSPM2 = 0;
   SSPM1 = 0;
   SSPM0 = 0;

   // Clear the Write Collision Detect bit.
   WCOL = 0;
        // Enable the MSSP module.
   SSPEN = 1;
}
unsigned char uc_send_receive_spi(unsigned char uc_data)
{
   // Send the data
   SSPBUF = uc_data;

   // Wait for the SPI module to finish sending / receiving.
   while(BF == 0);

   // Return the received data.
   return SSPBUF;
}
void play_M1(void){
    //********** TURN ON SPI ***********
        CS = 0;
        led1 = 0;
   uc_send_receive_spi(0b10000000); //PU_
   uc_send_receive_spi(0b00000000);

        //tmr_delay(5);                   //(100ms)delay

        uc_send_receive_spi(0b00100000); //CLR_INT
   uc_send_receive_spi(0b00000000);

        //tmr_delay(5);                   //(100ms)delay

        uc_send_receive_spi(0b00000010); //PLAY_
   uc_send_receive_spi(0b00000000);
        //delay(6000);
        //tmr_delay(5);                   //(100ms)delay

        uc_send_receive_spi(0b11100000); //PD_
   uc_send_receive_spi(0b00000000);
        tmr_delay(5);
        CS = 1;
        led1 = 1;
        __delay_ms(5000);
    //**********************************
}
walo
 
Posts: 2
Joined: Thu Oct 30, 2014 2:06 pm
PIC experience: EE Student

Re: [ PIC16F690 ] SPI with [ ISD1760 ] voice coder chip - MP

Postby ric » Fri Oct 31, 2014 1:15 pm

I wondered why all your command codes looked wrong, until I spotted that the application guide specifies "LSB first", which is very unusual for SPI.
I see that your init() code is correctly toggling the CS pin around each command, but your play_M1() code is not. It drives CS low at the start, and keeps it low while sending several commands, which is incorrect.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: [ PIC16F690 ] SPI with [ ISD1760 ] voice coder chip - MP

Postby walo » Sun Nov 09, 2014 12:33 pm

Hello Ric,
Yes ISD chip has a weird SPI, so i have to reverse all the commands prior to sending them.
As for the init() you were right, i have to trigger cs on before sending each command and then trigger it back off. My circuit & code are working perfectly
now doing exactly what is required.

Thank you very much for your help :)
walo
 
Posts: 2
Joined: Thu Oct 30, 2014 2:06 pm
PIC experience: EE Student

Re: [ PIC16F690 ] SPI with [ ISD1760 ] voice coder chip - MP

Postby emirhan » Thu Feb 04, 2016 9:10 am

Could you please write the final version of the code
emirhan
 
Posts: 1
Joined: Thu Feb 04, 2016 9:02 am
PIC experience: EE Student


Return to SSP (IIC, SPI)

Who is online

Users browsing this forum: No registered users and 5 guests

cron