This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Programming to external EEPROM

Hello. I need some help.
I'm trying to write, read and erase an external EEPROM (25AA040 MICROCHIP) via SPI from XC164CS board, for example, one byte at 0x00 adress of the eeprom, but i don't know how to do it.
Into the datasheet, I can see some instructions but i don't know what to do with them:
img28.imagevenue.com/img.php
Could anyone help me?
Thank you very much. :)

Parents
  • Hi Chris,
    I have 3 questions about the project:

    First one: I suppose the program writes and reads this array: txBuf[] = "Welcome to XC164CS Serial EEPROM reading/writing" into EEPROM. Isn't it?
    How can I check if this program writes and reads correctly?

    Second one: How does the "EepromStartTx" function work? It doesnÂ't have any "for" loop to send each byte of txBuf[] to SSC0_TB?

    Third one:Is SSC0 interrupt system similar to ASC0?
    Thanks. I go on studying.

Reply
  • Hi Chris,
    I have 3 questions about the project:

    First one: I suppose the program writes and reads this array: txBuf[] = "Welcome to XC164CS Serial EEPROM reading/writing" into EEPROM. Isn't it?
    How can I check if this program writes and reads correctly?

    Second one: How does the "EepromStartTx" function work? It doesnÂ't have any "for" loop to send each byte of txBuf[] to SSC0_TB?

    Third one:Is SSC0 interrupt system similar to ASC0?
    Thanks. I go on studying.

Children
  • Other question:
    Is there any time to comply with this?

    void SSC0_viTx(void) interrupt SSC0TINT
    ...
            if ((eeprom.cmd == WRITE) && (eeprom.bytesTx == START_TX_MSG))
    ...
    


    eeprom.bytesTx is going to take as maximum, 2, isn't it?

  • There are two functions to read/write the serial EEPROM

    U8 EepromRead(U16 address, S8 *des, U16 cnt);
    U8 EepromWrite(U16 address, S8 *src, U16 cnt);
    

    Each has three parameters, the address, a pointer to first element of data (to read/write) and the number of bytes elements to read or write from the serial EEPROM.

    In the example the txbuf[] is a constant string which is written to the serial EEPROM. Again it is an argument so you can write what you want. In this example the SSC0 is assumed to be exclusively used for communication to the serial EEPROM. In addition it also puts the command and address into the data stream that the serial EEPROM sees. The EepromRead routine also strips out the address and command from the data receive stream so the data the application sees is strictly application data (protocol overhead of the serial EEPROM has been removed). In other words the driver is hiding some details from the application which is what I wanted.

    How can I check if this program writes and reads correctly?. You read back what you wrote and if they are the same then you were successful. You could also add more checks to make sure that a write actually started by querying the serial EEPROM. Hook up a LSA and look at the SPI data streams...

    How does the "EepromStartTx" function work?
    It only starts the transmission and the interrupts serve to fill the rest of the data. No for is used as it is interrupt driven in the background.

    Is SSC0 interrupt system similar to ASC0? They are similar in that they are both interrupts and relate to a serial protocol. The user's manual explains how they each behave.

  • Is there any time to comply with this?

    Not sure what you mean? The transmit interrupt is working on a pointer from the serial EEPROM driver that changes depending on what count it is on and what mode (read or write).

    The driver is sending the command and address which is not it the data string you are passing. The transmit interrupt routine could be made simpler if you want to include the command and address in your data. It depends on what is more important to you, abstraction of your data from the driver or not.

  • Hi,
    I tested the program by using the uVision Debugger in evaluation mode.
    I don't understand why the program enters into the receive interrupt while the message array is being written in EEPROM.
    I am trying to visualize what I read from EEPROM ("Welcome to XC164CS Serial EEPROM reading/writing")
    in hyperterminal through ASC0.
    How could I transfer the read data from EEPROM to new array in order to send this array afterwards for ASC0?
    How would you do this?
    Thanks

  • In any case, I think that the program doesn't read properly the written data because when it gets EepromRead function, the receive interrupt is executed only once. Correct me if I am wrong.

  • Chris,
    Have you tested this program by using keils ulink2?

  • I tested it with ULINK and Lauterbach. Everything works as expected.

    What hardware are you using? The hardware I used was the Starter kit which uses SSC0 and P3.6 for the chip select.

    -Chris

  • I don't have any type of hardware to test the programs :(. I can only use the ASC0 and hyperterminal to show the bytes I read/write from EEPROM and for every tests.
    In my project we don't have much money to buy debuggers, such as uLink jejeje.

  • Hello Chris,
    Despite I have tried so much, I am not able to read what I have written in the EEPROM. I am trying to store everything I receive from EEPROM in an array located in reception interruption. I only get as answer [00][FF]. What could it be the problem?
    Thank you.

  • John,
    Despite our desire to help you, we are not mind readers. Please post the core of your code - just the essentials so that it can be analyzed.

  • Tamir, if you want, I will send you the keil proyect to your mail right?

  • John,
    I don't have your hardware so sending me your code is not going to help a lot. Besides I am at work and I don't time too much time...Just post a couple of code snippets: your peripheral configuration, ISRs, and buffers that interact with incoming data. Are you sure your external bus interface is correctly configured? Did you try to minimize the scope of the program to the absolute minimum, so that you can rule out external interferences? That can you and us, too.

  • Hello John,

    I don't see the same issue so something must be different in your implementation. What pins are connected from the serial EERPOM to what pins of the XC164CS. What about the WR and HOLD pins (they are tied high in my configuration)?

    The read and write routines are completely interrupt driven and are the same implementation only the instruction (sent to the serial EEPROM) is changed.

    You would need to isolate your problem/issue and properly communicate the defect for someone else to understand what the cause might be and provide suggestions.

    If you run the code using the simulator you will see that the interrupts are more than two. You would not have the correct data but the transfers should work.

    -Chris

  • void SSC0_viRx(void) interrupt SSC0RINT {
    
      if (eeprom.bytesRx < eeprom.rxCnt) {
              eeprom.bytesRx++;
    
              if ((eeprom.cmd == READ) && (eeprom.bytesRx >= START_RX_MSG)) {
           *eeprom.rxptr++ = (S8) (SSC0_RB);
              }
            else {
            eeprom.data = (S8) (SSC0_RB);   /* */
                    my_array[j] = SSC0_RB;
                    j++;
                    if (j == NUMBER)
                    {
                            flag = 1;
                            ASC0_TBIC_IR = 1;
                    }
    
        }
    
              if (eeprom.bytesRx >= eeprom.rxCnt) {
                eeprom.busy = false;
                            CS_EEPROM = high;
              }
      }
    }
    void ASC0_viTxBuffer(void) interrupt ASC0_TBINT using RB_LEVEL14
    {
             if ((j > 0) && (flag == 1))
             {
                            j--;
                            ASC0_TBUF = mi_array[j];
                            if (j == 0) flag = 0;
             }
    }
    

  • void SSC0_viRx(void) interrupt SSC0RINT {
    
      if (eeprom.bytesRx < eeprom.rxCnt) {
              eeprom.bytesRx++;
    
              if ((eeprom.cmd == READ) && (eeprom.bytesRx >= START_RX_MSG)) {
           *eeprom.rxptr++ = (S8) (SSC0_RB);
              }
            else {
            eeprom.data = (S8) (SSC0_RB);   /* */
                    my_array[j] = SSC0_RB;
                    j++;
                    if (j == NUMBER)
                    {
                            flag = 1;
                            ASC0_TBIC_IR = 1;
                    }
    
        }
    
              if (eeprom.bytesRx >= eeprom.rxCnt) {
                eeprom.busy = false;
                            CS_EEPROM = high;
              }
      }
    }
    void ASC0_viTxBuffer(void) interrupt ASC0_TBINT using RB_LEVEL14
    {
             if ((j > 0) && (flag == 1))
             {
                            j--;
                            ASC0_TBUF = my_array[j];
                            if (j == 0) flag = 0;
             }
    }