Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC24Fj128ga006 spi-slave problem

Status
Not open for further replies.

shahrol_hisham

Advanced Member level 4
Joined
Aug 1, 2002
Messages
111
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Location
malaysia
Activity points
869
Hi....

Need Help

My project - set the controller as spi slave (interrupt base) using MPLAB C30
I can receive data from spi but cannot transmit back - SDO cannot work

this is my code:
void init_spi1(void)
{

//SPI1BUF = 0x00; //clear spi buffer
IFS0bits.SPI1IF = 0x00;//clear interrupt flag status
IEC0bits.SPI1IE = 0x00;//disable spi interrupts

SPI1CON1bits.DISSCK = 0x00;//internal serial clock is enable
SPI1CON1bits.DISSDO = 0x00;//sdo pin control by module
SPI1CON1bits.MODE16 = 0x00;//8 bit operation
SPI1CON1bits.SMP = 0x00;//clr if used in slave mode
SPI1CON1bits.CKE = 0x00;//output data change from active clk to idle clk state

SPI1CON1bits.SSEN = 0x00;//ss used for slave mode
SPI1CON1bits.CKP = 0x00;//idle state for clk-low; active high
SPI1CON1bits.MSTEN = 0x00;//slave mode

SPI1STAT = 0x0004;
SPI1STATbits.SPIROV = 0;
SPI1STATbits.SPIEN |= 1;

IFS0bits.SPI1IF = 0x00;//clear interrupt flag status
IEC0bits.SPI1IE = 0x01;//disable spi interrupts

}

//interrupt

void __attribute__((interrupt,no_auto_psv)) _SPI1Interrupt(void)
{

inSPI[inSPIctr++] = SPI1BUF; //store data receive Increment pointer.
SPI1BUF=0x55; //write data to buffer

if((inSPI[0]==0x01)&&(inSPI[1]==0x02)&&(inSPI[2]==0x03)){
PORTD = 0x00; //if data store equale led on
inSPI[0]=0x00;
inSPIctr = 0x00;
}
else if((inSPI[0]==0x04)&&(inSPI[1]==0x05)&&(inSPI[2]==0x06)){
PORTD = 0x01; //if data store equale led off
inSPI[0]=0x00;
inSPIctr = 0x00;
}

_SPI1IF = 0x00;//clear interrupt flag status
}

//my simulation using protesu
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top