#INCLUDE <16F88.h>
#FUSES XT,NOWDT
#USE delay (clock=8M)
#USE fast_io(A)
#USE fast_io(B)
#define SS PIN_B5
//PROGRAMA PRINCIPAL
void main(){
int8 dato=0;
set_tris_a(0b00000001); //Configuración I/O
set_tris_b(0b00000010);
output_high(SS);
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_XMIT_L_TO_H | SPI_CLK_DIV_16 ); //Configuramos hardware spi.
//Enviar valor numérico:
output_low(SS);
spi_write(0xAA); //Este valor se envia correctamente
output_high(SS);
//Enviar variable:
dato=0xBB;
output_low(SS);
spi_write(dato); //Al enviar la variable, se produce un error.
output_high(SS);
while(1);
}SSPSTAT,0 es el bit BF:
BF: Buffer Full Status bit
Receive (SPI and I2 C modes):
1 = Receive complete, SSPBUF is full
0 = Receive not complete, SSPBUF is empty
Transmit (in I2 C mode only):
1 = Transmit in progress, SSPBUF is full (8 bits)
0 = Transmit complete, SSPBUF is empty
output_low(SS);
#asm
BCF 03.5
MOVF 0x13,W //Leo el registro SSPBUF
#endasm
spi_write(dato); //Y despues envio el dato
output_high(SS);
int8 res;
#asm
BCF 03.5
MOVF 0x13,W
#endasm
res=spi_read(dat);
¿Ya probaste colocando un retardo antes de volver a hacer "0" el pin SS para enviar la variable dato?
dato=0xDD;
output_low(SS);
spi_write(dato);
delay_ms(2);
output_high(SS); #include <16f88.h>
#device adc= 10
#use delay (clock= 4000000)
#fuses XT,PUT,NOWDT,NOLVP
void main()
{
int i;
SETUP_SPI(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16);
output_low(pin_B5);
while(true)
{
for(i=0;i<16;i++)
{
spi_write(i);
//delay_ms(2); //Quitando este delay, deja de funcionar con el 16f88
output_high(pin_B5);
output_low(pin_B5);
delay_ms(600);
}
}
}Gracias