Autor Tema: Cambiar dspic entre Maestro y esclavo, SPI  (Leído 1605 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado mmX

  • PIC10
  • *
  • Mensajes: 37
Cambiar dspic entre Maestro y esclavo, SPI
« en: 03 de Abril de 2009, 17:18:00 »
Hola, estoy en un segmento de mi proyecto y necesito pasar información del panel de usuario, realizado con un PIC18f4550 a un dsPIC33fj32mc204... He colocado el dspic como maestro a enviarle datos al pic18, luego deseo recibir una respuesta del pic18 y procesarla en el dsPIC. y aqui está mi problema. No he podido enviar ni un dato al dspic.

Alguna idea?

Código: [Seleccionar]
void Init_SPI(void)
{
    TRISC = 0x0FF;
    TRISA = 0x000;
RPINR20bits.SCK1R = 19;
RPINR20bits.SDI1R = 20;
RPINR21bits.SS1R = 21;
    RPOR12bits.RP24R = 8; //SCK1
    RPOR12bits.RP25R = 7; //SD01
// setup the SPI peripheral
SPI1STAT = 0x0;  // disable the SPI module (just in case)
SPI1CON1 = 0x0161; // FRAMEN = 0, SPIFSD = 0, DISSDO = 0, MODE16 = 0; SMP = 0; CKP = 1; CKE = 1; SSEN = 0; MSTEN = 1; SPRE = 0b000, PPRE = 0b01
SPI1CON1bits.CKE = 0x01;
SPI1CON1bits.CKP = 0x00;
    SPI1CON1bits.MODE16=0;
SPI1CON1bits.SSEN = 1;
    SPI1CON1bits.MSTEN = 0;
SPI1STAT = 0x8000; // enable the SPI module

}

void write_SPI1(short command)
{
short temp=0;

PORTBbits.RB0 = 0; // lower the slave select line
temp = SPI1BUF; // dummy read of the SPI1BUF register to clear the SPIRBF flag
   
SPI1BUF = command; // write the data out to the SPI peripheral
    while (!SPI1STATbits.SPIRBF) // wait for the data to be sent out
;
PORTBbits.RB0 = 1; // raise the slave select line
}

void read_spi()
{
 int temp;
if(SPI1STATbits.SPIRBF == 1){
 temp = SPI1BUF;
 PORTA = temp;
}
}


 

anything