roberto.s
Newbie level 6
Hi,
I'm traying to drive an ISD4002 with a PIC18F2520 using the SPI.
I do any kind of test, the SPI work correctly if I use another PIC instad of the ISD,
data transfer was good; but when I use the ISD I really don't know how to test it....
This is my program, I think it's correct but probably it isn't.....:
#include <p18f2520.h>
#include <portb.h>
#include <spi.h>
#include <delays.h>
#pragma config OSC = HS
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config PBADEN = OFF
#pragma config MCLRE = ON
//OSC = HS Impostato per lavorare ad alta frequenza
//WDT = OFF Disabilito il watchdog timer
//LVP = OFF Disabilito programmazione LVP
//PBADEN = OFF Disabilito gli ingressi analogici
#define POWERUP 0x20
#define SETPLAY 0xE0
#define PLAY 0xF0
#define SETREC 0xAF
#define REC 0xB0
#define STOP 0x30
#define POWERDOWN 0x10
#define ZERO 0x00
#define SPI_CS LATAbits.LATA5
#define LED LATAbits.LATA4
#define BUTTON PORTBbits.RB5
//variabili comuni ad uso contatori
unsigned int i,j,y,k;
char a,b;
// Prototipo di funzione
void High_Int_Event (void);
void high_interrupt (void){
// Salto per la gestione dell'interrupt
_asm GOTO High_Int_Event _endasm
}
#pragma code
#pragma interrupt High_Int_Event
// Funzione per la gestione dell'interruzione
void High_Int_Event (void){
//abilito la comunicazione seriale
OpenSPI(SPI_FOSC_64, MODE_00, SMPMID);
// Controllo che l'interrupt sia stato generato da PORTB
if (INTCONbits.RBIF == 1 ){
}
if(BUTTON==0){
Delay10KTCYx(10);
//creazione opzione PLAY-REC
for (i=0; i<60000&&BUTTON==0; i++){
}
if(i<60000){
//invio del comando di POWERUP
SPI_CS=0;
WriteSPI(POWERUP);
// Delay100TCYx(1);
WriteSPI(ZERO);
Delay1KTCYx(25);
//invio del comando di SETPLAY
WriteSPI(SETPLAY);
// Delay100TCYx(1);
WriteSPI(ZERO);
//invio del comando di PLAY
WriteSPI(PLAY);
// Delay100TCYx(1);
WriteSPI(ZERO);
SPI_CS=1;
//attesa dell'segnale di fine riproduzione
while (PORTBbits.RB0!=0){
LED=1;
Delay10KTCYx(1);
LED=0;
Delay1KTCYx(100);
}
//invio del comando di STOP
SPI_CS=0;
WriteSPI(STOP);
// Delay100TCYx(1);
WriteSPI(ZERO);
Delay1KTCYx(50);
//avvio della ricezione dei dati EOM ed indirizzo
a=ReadSPI();
// Delay100TCYx(1);
b=ReadSPI();
SPI_CS=1;
Delay10KTCYx(10);
}else{
//LED ON
LED=1;
//invio del comando di POWERUP
SPI_CS=0;
WriteSPI(POWERUP);
// Delay100TCYx(1);
WriteSPI(ZERO);
Delay1KTCYx(25);
//invio del comando di POWERUP
WriteSPI(POWERUP);
// Delay100TCYx(1);
WriteSPI(ZERO);
Delay1KTCYx(50);
//invio del comando di SETREC
WriteSPI(SETREC);
// Delay100TCYx(1);
WriteSPI(ZERO);
//invio del comando di REC
WriteSPI(REC);
// Delay100TCYx(1);
WriteSPI(ZERO);
SPI_CS=1;
Delay100TCYx(1);
//attesa rilascio del pulsante per finire la registrazione
while (BUTTON==0){
}
//invio del comando di STOP
SPI_CS=0;
WriteSPI(STOP);
// Delay100TCYx(1);
WriteSPI(ZERO);
Delay1KTCYx(50);
//avvio della ricezione dei dati EOM ed indirizzo
a=ReadSPI();
// Delay100TCYx(1);
b=ReadSPI();
SPI_CS=1;
//LED OFF
LED=0;
Delay10KTCYx(10);
}
}
CloseSPI();
// Resetto il flag d'interrupt per permettere nuove interruzioni
INTCONbits.RBIF = 0;
}
void main (void){
//Inizializzazione dei pin
// LATA = 0x00;
TRISA = 0b11001111;
LATAbits.LATA4 = 0;
// LATB = 0x00;
TRISB = 0xFF;
// LATC = 0x00;
TRISC = 0xFF;
//Abilita/Disabilita i resistori di pull-up sulla PORTB
//EnablePullups();
DisablePullups();
//Abilito le interruzioni su PORTB
INTCONbits.RBIE = 1;
//Abilito l'interrupt globale
INTCONbits.GIE = 1;
//Abilito l'interrupt periferiche
INTCONbits.PEIE = 1;
Delay100TCYx(1);
j=1000;
//Ciclo infinito
while(1){
}
}
Can anyone help me?
I'm traying to drive an ISD4002 with a PIC18F2520 using the SPI.
I do any kind of test, the SPI work correctly if I use another PIC instad of the ISD,
data transfer was good; but when I use the ISD I really don't know how to test it....
This is my program, I think it's correct but probably it isn't.....:
#include <p18f2520.h>
#include <portb.h>
#include <spi.h>
#include <delays.h>
#pragma config OSC = HS
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config PBADEN = OFF
#pragma config MCLRE = ON
//OSC = HS Impostato per lavorare ad alta frequenza
//WDT = OFF Disabilito il watchdog timer
//LVP = OFF Disabilito programmazione LVP
//PBADEN = OFF Disabilito gli ingressi analogici
#define POWERUP 0x20
#define SETPLAY 0xE0
#define PLAY 0xF0
#define SETREC 0xAF
#define REC 0xB0
#define STOP 0x30
#define POWERDOWN 0x10
#define ZERO 0x00
#define SPI_CS LATAbits.LATA5
#define LED LATAbits.LATA4
#define BUTTON PORTBbits.RB5
//variabili comuni ad uso contatori
unsigned int i,j,y,k;
char a,b;
// Prototipo di funzione
void High_Int_Event (void);
void high_interrupt (void){
// Salto per la gestione dell'interrupt
_asm GOTO High_Int_Event _endasm
}
#pragma code
#pragma interrupt High_Int_Event
// Funzione per la gestione dell'interruzione
void High_Int_Event (void){
//abilito la comunicazione seriale
OpenSPI(SPI_FOSC_64, MODE_00, SMPMID);
// Controllo che l'interrupt sia stato generato da PORTB
if (INTCONbits.RBIF == 1 ){
}
if(BUTTON==0){
Delay10KTCYx(10);
//creazione opzione PLAY-REC
for (i=0; i<60000&&BUTTON==0; i++){
}
if(i<60000){
//invio del comando di POWERUP
SPI_CS=0;
WriteSPI(POWERUP);
// Delay100TCYx(1);
WriteSPI(ZERO);
Delay1KTCYx(25);
//invio del comando di SETPLAY
WriteSPI(SETPLAY);
// Delay100TCYx(1);
WriteSPI(ZERO);
//invio del comando di PLAY
WriteSPI(PLAY);
// Delay100TCYx(1);
WriteSPI(ZERO);
SPI_CS=1;
//attesa dell'segnale di fine riproduzione
while (PORTBbits.RB0!=0){
LED=1;
Delay10KTCYx(1);
LED=0;
Delay1KTCYx(100);
}
//invio del comando di STOP
SPI_CS=0;
WriteSPI(STOP);
// Delay100TCYx(1);
WriteSPI(ZERO);
Delay1KTCYx(50);
//avvio della ricezione dei dati EOM ed indirizzo
a=ReadSPI();
// Delay100TCYx(1);
b=ReadSPI();
SPI_CS=1;
Delay10KTCYx(10);
}else{
//LED ON
LED=1;
//invio del comando di POWERUP
SPI_CS=0;
WriteSPI(POWERUP);
// Delay100TCYx(1);
WriteSPI(ZERO);
Delay1KTCYx(25);
//invio del comando di POWERUP
WriteSPI(POWERUP);
// Delay100TCYx(1);
WriteSPI(ZERO);
Delay1KTCYx(50);
//invio del comando di SETREC
WriteSPI(SETREC);
// Delay100TCYx(1);
WriteSPI(ZERO);
//invio del comando di REC
WriteSPI(REC);
// Delay100TCYx(1);
WriteSPI(ZERO);
SPI_CS=1;
Delay100TCYx(1);
//attesa rilascio del pulsante per finire la registrazione
while (BUTTON==0){
}
//invio del comando di STOP
SPI_CS=0;
WriteSPI(STOP);
// Delay100TCYx(1);
WriteSPI(ZERO);
Delay1KTCYx(50);
//avvio della ricezione dei dati EOM ed indirizzo
a=ReadSPI();
// Delay100TCYx(1);
b=ReadSPI();
SPI_CS=1;
//LED OFF
LED=0;
Delay10KTCYx(10);
}
}
CloseSPI();
// Resetto il flag d'interrupt per permettere nuove interruzioni
INTCONbits.RBIF = 0;
}
void main (void){
//Inizializzazione dei pin
// LATA = 0x00;
TRISA = 0b11001111;
LATAbits.LATA4 = 0;
// LATB = 0x00;
TRISB = 0xFF;
// LATC = 0x00;
TRISC = 0xFF;
//Abilita/Disabilita i resistori di pull-up sulla PORTB
//EnablePullups();
DisablePullups();
//Abilito le interruzioni su PORTB
INTCONbits.RBIE = 1;
//Abilito l'interrupt globale
INTCONbits.GIE = 1;
//Abilito l'interrupt periferiche
INTCONbits.PEIE = 1;
Delay100TCYx(1);
j=1000;
//Ciclo infinito
while(1){
}
}
Can anyone help me?