Hola, tengo un programita que manda un dato cada medio segundo a otro pic por SPI, el problema esta en que tiene un funcionamiento anormal, primero recibe el dato por spi y lo deja encendido unos 2 segundos, despues funciona la comunicacion correctamente por 2 segundos y luego simplemente es como si ya no recibiera nada por spi, comprobe que sigue funcionando el receptor ya que en una ocasion puse un led a paradear y lo continua haciendo aun cuando la comunicacion ya no funciona, acontinuacion pongo mi codigo, espero me pudan ayudar, muchas gracias
CODIGO DEL PIC MAESTRO
//Comunicar 2 PICs 18F4550 utilizando el protocolo SPI.
//
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
//CABECERA///////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
#include <18f4550.h> //pic a utilizar
#fuses inths //oscilador interno
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES NOSTVREN //Stack full/underflow will not cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES NOLPT1OSC //Timer1 configured for higher power operation
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use delay(internal=8Mhz) //frecuencia del oscilador
/////////////////////////////////////////////////////////////////////////////////////
//VARIABLES GLOBALES////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
//FUNCIONES/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
//PRINCIPAL/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
void main( )
{
setup_spi(spi_master | spi_l_to_h | spi_clk_div_16); //configurar spi como maestro
output_high(PIN_B2);
delay_ms(50);
while(1)
{
spi_write(1); //escribir en el pin ra1
output_low(PIN_B2);
delay_ms(50);
spi_write(0); //escribir en el pin ra1
output_high(PIN_B2);
delay_ms(50);
}
}
CODIGO DEL PIC ESCLAVO
//Comunicar 2 PICs 18F4550 utilizando el protocolo SPI. Cuando hay un "1" lógico
//en el pin ra1 se enciende un diodo led.
//
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
//CABECERA///////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
#include <18f4550.h> //pic a utilizar
#fuses inths //oscilador interno
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES NOSTVREN //Stack full/underflow will not cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES NOLPT1OSC //Timer1 configured for higher power operation
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use delay(internal=8Mhz) //frecuencia del oscilador
/////////////////////////////////////////////////////////////////////////////////////
//VARIABLES GLOBALES////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
//FUNCIONES/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
//PRINCIPAL/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
void main()
{
output_c(0x00);
setup_spi(spi_slave | spi_l_to_h | spi_clk_div_16); //configurar spi como esclavo
for(;;)
{
/* output_low(PIN_C0);
delay_ms(500);
output_high(PIN_C0);
delay_ms(500);
*/
if(spi_data_is_in()) //si hay un dato en el spi
{
//output_d(spi_read());
output_c(spi_read());
}else{
}
}
}