I am trying to setup the SPI1 port on my PIC24HJ206GP256 micro. I have set the SPI1CON1 control register with 0x0020, the SPI1STAT control register with 0x8000 (I.E. turn on the SPIEN) and SPI1CON2 = 0.
At the moment a simple write to the SPI1BUF is written like this:
void writeSPI1(char data){
_SPI1IF = 0; //set interrupt flag to zero
SPI1BUF = data; //write data to SPI1BUF
while( _SPI1IF == 0); //wait to flag to go high
}
However when the data is written, the SPI1IF should go high, however it never reaches this point so the program simply remains in the loop forever. So it seems no data will ever be clocked out of the SPI port through MOSI.
I have tried to make it work by setting TRISF = 0x0000. Although I have read that the SPI port should take care of SPI pin configuration.
I am using a watch window to view the contents of the SPI1BUF.
I have tried with different settings within the control registers but have had no luck. Also have tried enabling the SPI1IF (IEC0: Interrupt Enable Control Register 0) and still the problem persists.
Are there any extra configurations I have forgotten, like some odd functionality of PORTF which takes precedence over the SPI port. Any help would be greatly appreciated.
Thanks