0

I have my own board with the PIC32MX795F512L and I'm trying to connect it with an SPI EEPROM (M95128-DRE). I'm writing a byte (0x80) and reading it (after a 5ms delay) but always the reading result is 0xFF. Is there something am I doing wrong? The code:

while(true)
{
  YB_posX = 0;
  uint8_t ENA= 0b00000110; //ROM write-enable instruction
  uint8_t INS1=0b00000010; //ROM write instruction
  uint8_t add1=0x00; //address byte 1
  uint8_t add2=0xee; //address byte 2
  uint8_t INS2=0b00000011; //ROM read instruction
  uint8_t INS3=0b00000101; //read status register
  uint8_t DIS = 0b00000100; //write disable sequence
  PLIB_SPI_BufferClear(SPI_ID_4);
  LATEbits.LATE9= 0 ; // EEPROM Chip Select
  PLIB_SPI_BufferWrite (SPI_ID_4,ENA); // Write Enable
  LATEbits.LATE9= 1 ; // EEPROM Chip Select 
  LATEbits.LATE9= 0 ; // EEPROM Chip Select
  PLIB_SPI_BufferWrite (SPI_ID_4,INS1);
  PLIB_SPI_BufferWrite (SPI_ID_4,add1);
  PLIB_SPI_BufferWrite (SPI_ID_4,add2);
  PLIB_SPI_BufferWrite (SPI_ID_4,0x80); //the previous five instructions writed byte 0x50 to address(1+2)
  delay_ms(1); 
  //<-----------------
  LATEbits.LATE9=1; 
  delay_ms(5); 
  LATEbits.LATE9=0; 
  delay_ms(1); 
  PLIB_SPI_BufferWrite (SPI_ID_4,INS2); //reading instruction 
  PLIB_SPI_BufferWrite (SPI_ID_4,add1);
  PLIB_SPI_BufferWrite (SPI_ID_4,add2); 
  PLIB_SPI_BufferWrite (SPI_ID_4,0x00); //this line is necessary since the ROM needs clock signal to clock out the data.
  while(!PLIB_SPI_TransmitBufferIsEmpty(SPI_ID_4))
    {} 
  YB_posX = PLIB_SPI_BufferRead(SPI_ID_4); 
  PLIB_SPI_ReceiverOverflowClear(SPI_ID_4); 
  delay_ms(1);
  LATEbits.LATE9=1; //end of reading sequence 
  printNumI(YB_posX, 350, 235, 1, ' ');
  delay_ms(1000); 
 }

Needless to mention that the SPI is initialised and opened at the start of main.



   int main(void) {
       /* Initialise all MPLAB Harmony modules, including application(s). */
       SYS_Initialize(NULL);
      DRV_SPI0_Initialize(); // SPI initialise 
       DRV_SPI_Open(SPI_ID_4,DRV_IO_INTENT_EXCLUSIVE );

I'm using MPLABX v.5.05, X32 v2.10 and Harmony Configurator, attached is the snapshot of the SPI settings. Any suggestion is welcomed.

  • If someone approaches you with a similar question - would you be able to answer it? Have you got an oscilloscope? Can you try with another simpler SPI device (or even just jumper on MISO/MOSI) to confirm SPI master works as expected? Then you should be able to come up with a simple and clear reproducer for the problem, describe the assumptions, and point us to relevant pages of datasheet, so someone can quickly check this. – domen Jul 24 '19 at 12:35

1 Answers1

0

The problem was with the Harmony itself. Unfortunately, if you start a project with Harmony, there is NO way to go back. You have to Re-write the whole code from the start.

The solution: Modify the spi example \MPLAB\microchip\harmony\v2_06\apps\driver\spi\serial_eeprom

And an advise do not shift to Harmony v.3 yet! Most of the examples are NOT running there.

Mayur
  • 4,345
  • 3
  • 26
  • 40