• AVR Freaks

Hot!SPI EEPROM connection

Author
lamdaelectronics
Starting Member
  • Total Posts : 61
  • Reward points : 0
  • Joined: 2010/07/23 04:04:41
  • Location: 0
  • Status: offline
2019/07/25 00:44:25 (permalink)
0

SPI EEPROM connection

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 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=0x10; //address byte 1
    uint8_t add2=0x00; //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 wrote 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.
post edited by lamdaelectronics - 2019/07/25 01:56:53

Attached Image(s)

#1

12 Replies Related Threads

    muellernick
    Super Member
    • Total Posts : 474
    • Reward points : 0
    • Joined: 2015/01/06 23:58:23
    • Location: Germany
    • Status: offline
    Re: SPI EEPROM connection 2019/07/25 01:58:53 (permalink)
    3 (2)
    Hi!
     
    Don't use "delay" in your state machine. Your state machine (AKA task) has to return if it is waiting for something. That's the only way to give processing time to the other tasks, mainly system task.
    You will have to wait forever if system tasks aren't called.
    You need to have a new state for waiting. delay in general is a terrible idea in any state machine.
     
    Nick
    #2
    lamdaelectronics
    Starting Member
    • Total Posts : 61
    • Reward points : 0
    • Joined: 2010/07/23 04:04:41
    • Location: 0
    • Status: offline
    Re: SPI EEPROM connection 2019/07/25 03:01:27 (permalink)
    0
    Hello muellernick
    Clearly the problem is NOT the delay! that's a testing program and at the delay time I want the μC to do nothing.
    And again the response is 0xFF (delay on not) why?



    #3
    mlp
    boots too small
    • Total Posts : 805
    • Reward points : 0
    • Joined: 2012/09/10 15:12:07
    • Location: previously Microchip XC8 team
    • Status: offline
    Re: SPI EEPROM connection 2019/07/29 09:34:41 (permalink)
    3 (2)
    lamdaelectronics
    Clearly the problem is NOT the delay!

    Not "clearly" at all.
    You have not shown a complete program that can be compiled and investigated by other forum users, so all we can do is guess based on what you have shown.
    Since you have not bothered to use [ code ] tags to make your code look decent within your posting, few can be bothered to look beyond immediately-obvious things.
     
    Post a complete minimal test program (formatted with [ code ] tags so it's readable) and details of the compiler options used to build it.
     
    Note that you did say
    Any suggestion is welcomed.

    If you go back on that promise, what incentive does anyone have to bother helping?

    Mark (this opinion available for hire)
    #4
    muellernick
    Super Member
    • Total Posts : 474
    • Reward points : 0
    • Joined: 2015/01/06 23:58:23
    • Location: Germany
    • Status: offline
    Re: SPI EEPROM connection 2019/07/29 23:41:37 (permalink)
    3 (2)
    His answer already qualified as what his intents are:
     
    that's a testing program and at the delay time I want the μC to do nothing

    He doesn't want the µC to do anything. Only thing missing is that he concludes that absolutely nothing will happen.
     
    So in my eyes, he gave him his own answer. Case closed.
     
    Nick
    #5
    lamdaelectronics
    Starting Member
    • Total Posts : 61
    • Reward points : 0
    • Joined: 2010/07/23 04:04:41
    • Location: 0
    • Status: offline
    Re: SPI EEPROM connection 2019/07/30 09:37:10 (permalink)
    0
    Dear "judges" to my defence I should stress that the SPI still DOES NOT WORK!!!
    The problem is there clearly. The delays on the other hand work perfectly well! 
    Are you in a position to help or you are just showing off?
    I've tried to upload the zipped project but the system didn't let me, so if your honours  are keen to condemn someone these (system programmers) are the truly guilty!
    #6
    ChrisG42
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2019/07/29 10:33:50
    • Location: 0
    • Status: offline
    Re: SPI EEPROM connection 2019/07/30 11:30:27 (permalink)
    3 (1)
    Any chance you have access to an oscilloscope or digital logic analyzer so you can verify the EEPROM isn't in fact reporting 0xFF? Many EEPROM's default all values to 0xFF, so you may just not be writing correctly or may be reading somewhere you didn't write to.
    #7
    lamdaelectronics
    Starting Member
    • Total Posts : 61
    • Reward points : 0
    • Joined: 2010/07/23 04:04:41
    • Location: 0
    • Status: offline
    Re: SPI EEPROM connection 2019/07/31 10:22:43 (permalink)
    0
    Well spotted Chris, first of all the Developer's Example DOES NOT RUN (let's hope that someone from Microchip will see this). 
    I tried the STATIC SPI driver (which works with the communication with two other μCs) and I've tried the oscilloscope and I can tell that the EEPROM is sending back something. Unfortunately, the board is so small that I can not place the logic analyser leads.
    #8
    lamdaelectronics
    Starting Member
    • Total Posts : 61
    • Reward points : 0
    • Joined: 2010/07/23 04:04:41
    • Location: 0
    • Status: offline
    Re: SPI EEPROM connection 2019/08/01 04:07:26 (permalink)
    0
    There was a suggestion which led to the solution in a similar post:
    https://www.microchip.com/forums/m1106689.aspx
    If anybody needs help on changing the Harmony Configuration let post a follow up post.
    #9
    mlp
    boots too small
    • Total Posts : 805
    • Reward points : 0
    • Joined: 2012/09/10 15:12:07
    • Location: previously Microchip XC8 team
    • Status: offline
    Re: SPI EEPROM connection 2019/08/01 06:07:06 (permalink)
    4 (1)
    lamdaelectronics
    let's hope that someone from Microchip will see this

    Vain hope.
    Even vainer to hope that someone who can do something about it might see it.
     
    If you want something fixed, lodge a support case. Then they have to formally ignore you.

    Mark (this opinion available for hire)
    #10
    lamdaelectronics
    Starting Member
    • Total Posts : 61
    • Reward points : 0
    • Joined: 2010/07/23 04:04:41
    • Location: 0
    • Status: offline
    Re: SPI EEPROM connection 2019/08/02 04:41:17 (permalink)
    0
    Yes, I've done it a week ago! 
    But the support is not as it used to. The change point was the ATMEL - Microchip merger.
    They leave the ticket standing there unanswered for ages.


    #11
    lamdaelectronics
    Starting Member
    • Total Posts : 61
    • Reward points : 0
    • Joined: 2010/07/23 04:04:41
    • Location: 0
    • Status: offline
    Re: SPI EEPROM connection 2019/08/06 04:25:31 (permalink)
    0
    I had a response from Microchip support. If I manage to get it run with their help I will upload the project, followed by the Harmony procedure to set the SPI driver.
    #12
    lamdaelectronics
    Starting Member
    • Total Posts : 61
    • Reward points : 0
    • Joined: 2010/07/23 04:04:41
    • Location: 0
    • Status: offline
    Re: SPI EEPROM connection 2019/08/06 23:58:56 (permalink)
    0
    I've posted a solution using Harmony in 
    https://www.microchip.com/forums/FindPost/1108061
     
    #13
    Jump to:
    © 2019 APG vNext Commercial Version 4.5