|
|
View previous topic :: View next topic |
Author |
Message |
uN_Eof
Joined: 17 May 2010 Posts: 29 Location: I live in Spain, with the toros, paella and tortilla
|
Slave SPI Inhibits SCK |
Posted: Tue Aug 30, 2011 5:12 am |
|
|
Hello all. I'm having a problem, when I configure SPI as a slave in a PIC18F4620 the PIC inhibits the clock signal coming from the master. SCK is always 0, and I don't know why.
Here is a piece of my code, if it helps.
Code: |
void dsconf(){
input(DSATT);
input(DSCMD);
input(DSCLK);
setup_spi(SPI_SLAVE);
setup_spi(SPI_H_TO_L);
setup_spi(SPI_XMIT_L_TO_H);
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
}
ack(unsigned int us){
output_low(DSACK);
delay_us(us);
input(DSACK);
}
void write(unsigned int data, int doack=1){
spi_write(data);
if(doack)
ack(12);
}
#INT_SSP
void ssp_isr(){
command = spi_read(); //IMPORTANT STUFF
if(command == 0x01){
bytecount = 0;
output_high(green_led);
}
bytecount++; //INCREMENT BYTE COUNT
switch (bytecount){
case 1:
if(digital)
//write(0x41);
write(0xFE,1);
if(analog)
write(0x79,1);
if(config)
write(0xFF,1);
break;
case 2:
if(command == 0x42){
config = 0;
write(0x5A,1);
break;
}
if(command == 0xFF){
config = 1;
write(0x5A,1);
}
write(0x5A,1);
break;
case 3:
if(config == 0 && command == 0x00){
write(0xBD,1);
}
break;
case 4:
if(config == 0 && command == 0x00){
write(0xFF,0);
}
if(digital && !config)
bytecount = 0;
break;
case 5:
if(command == 0x00 && analog && !config){
write(rxjoy);
}
break;
case 6:
if(command == 0x00 && analog && !config){
write(ryjoy);
}
break;
case 7:
if(command == 0x00 && analog && !config){
write(lxjoy);
}
break;
case 8:
if(command == 0x00 && analog && !config){
write(lyjoy);
}
break;
case 9:
if(rtstat){
write(0xFF);
} else {
write(0x00);
}
break;
case 10:
if(ltstat){
write(0xFF);
} else {
write(0x00);
}
break;
case 11:
if(upstat){
write(0xFF);
} else {
write(0x00);
}
break;
case 12:
if(dwnstat){
write(0xFF);
} else {
write(0x00);
}
break;
case 13:
if(tristat){
write(0xFF);
} else {
write(0x00);
}
break;
case 14:
if(circstat){
write(0xFF);
} else {
write(0x00);
}
break;
case 15:
if(sqrstat){
write(0xFF);
} else {
write(0x00);
}
break;
case 16:
if(xstat){
write(0xFF);
} else {
write(0x00);
}
break;
case 17:
if(l1stat){
write(0xFF);
} else {
write(0x00);
}
break;
case 18:
if(r1stat){
write(0xFF);
} else {
write(0x00);
}
break;
case 19:
if(l2stat){
write(0xFF);
} else {
write(0x00);
}
break;
case 20:
if(r2stat){
write(0xFF);
} else {
write(0x00);
}
break;
}
} |
Thanks in advance.
Some additional info: I'm trying to emulate a PS2 controller, and I'm connecting my emulator (slave) to a PS2 to PS3 usb controller adaptor, but the same thing happens if I connect the slave to an actual PS2. |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Tue Aug 30, 2011 6:11 am |
|
|
I'm pretty sure setup_spi() doesn't work incrementally. In your code only the values in the last setup_spi will have any effect. Instead you have to or the values together in one setup_spi:
setup_spi(SPI_SLAVE | SPI_H_TO_L | SPI_XMIT_L_TO_H);
That might help.
RF Developer |
|
|
uN_Eof
Joined: 17 May 2010 Posts: 29 Location: I live in Spain, with the toros, paella and tortilla
|
|
Posted: Tue Aug 30, 2011 6:14 am |
|
|
RF_Developer wrote: | I'm pretty sure setup_spi() doesn't work incrementally. In your code only the values in the last setup_spi will have any effect. Instead you have to or the values together in one setup_spi:
setup_spi(SPI_SLAVE | SPI_H_TO_L | SPI_XMIT_L_TO_H);
That might help.
RF Developer |
THANKS! Thank you so much... that seems to solve my problem... nobody knows how much I hate this kind of idiotic errors.... haha |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|