spi clock
Posted: Wed Nov 20, 2013 8:55 am
in flowcode i can communicate with external eeprom and sram chips with spi clock set to idle low which would be mode 0,0... in c this works as well with the exception that the master can't read the slaves sent data correctly..... the only way using spi in c that i can receive information from external chips is if i set clock to idle high.... here is the code that works
here is the code that does work as viewed with logic16 but master pic can't read incoming data correctly
i don't see anything in the datasheet that would explain that this won't work with 23lc512 or 25lc512?
Code: Select all
void spi_init(){
clearbit(trisc,3);
setbit(trisc,4);
clearbit(trisc,5);
smp_bit=0;//data sampled at end
cke_bit=0;//SPI MODE 1,1
ckp_bit=1;// SPI MODE 1,1
clearmask(sspcon1,15);// 8Mhz bitrate
sspie_bit=1;// enable spi done interrupt
sspif_bit=0;//clear done flag
sspen_bit=1;//sets up serial port
peie_bit=1;// enable peripherial interrupts
gie_bit=1;// enable global interrupts
}
char spi_get(void){
sspbuf=0;// send dummy
while(sspif_bit==0);// wait for done
sspif_bit=0;// clear done flag
return sspbuf;// return read
}
void spi_send(char dip){
char dummy;
sspbuf=dip;
while(sspif_bit==0);// wait for done
sspif_bit=0;// clear done flag
dummy=sspbuf;
}
Code: Select all
smp_bit=0;//data sampled at end
cke_bit=1;//SPI MODE 0,0
ckp_bit=0;// SPI MODE 0,0