So I did some reading and made a few projects but for the last few days I've got a bit stuck, and I'm running out of ideas to try. I can initialise the SPI module, I can write to the flash chip (0x9F for ID) however I only get 3 bytes in return which isn't what I should get according to the flash memory datasheet, additionally I get the same 3 bytes if I repeat the read without writing anything else, so if I write 0x9F i will get 0x1C 0x30 0x14 in return even if i read multiple times without writing a second time.
Here's my init code (using spi module 6):
Code: Select all
TRISD.b14 = 0; //slave select output
TRISF.B8 = 0; //mosi output
TRISF.b2 = 1; //miso input
TRISD.B15 = 0; //clock output
Code: Select all
Unlock_IOLOCK();
PPS_Mapping(_RPF8, _Output, _SDO6);
PPS_Mapping(_RPF2, _Input, _SDI6);
Lock_IOLOCK();
SPI6_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, 64, _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_END, _SPI_CLK_IDLE_HIGH, _SPI_active_2_IDLE);
and here is the code to test the read and write:
Code: Select all
LATD.B14 = 0; //set the CS pin low
SPI6_Write(0x9F); //write command for chip ID
//we are expecting 20 bytes back
for (i = 0; i< 20; i++){
RX_Buff[i] = SPI6_Read(0x00);
}
LATD.B14 = 1; //set the CS pin high
I understand I am likely missing something really basic here, unfortunately I don't have a logic analyser so goosed as to what any ideas?