• AVR Freaks

Hot!PIC24 I2C Master to EERAM 47L16 with MCC ADDRERR trap

Author
iprat
Senior Member
  • Total Posts : 122
  • Reward points : 0
  • Joined: 2003/11/07 12:36:56
  • Status: offline
2019/07/04 09:47:58 (permalink)
0

PIC24 I2C Master to EERAM 47L16 with MCC ADDRERR trap

Hi everyone:
 
In my last project I've used a PIC24FJ128GA606 that has a 47L16 EERAM interfaced with an I2C.
 
Project build with MPLAB X IDE 5.20, XC16 (1.36) optimization level 0, and using Foundation Libraries of current MCC, in particular 47XXX I2C EERAM version 1.0.2 library.
 
I can read in the headers this notice:
    The generated drivers are tested against the following:
        Compiler          :  XC16 v1.36
        MPLAB             :  MPLAB X v5.10
 
Everything has worked quite beautifully, I can read status, write status, read data single and multiple byte, and write single byte data from the EERAM directly with Foundation Libraries of MCC, very nice implementation.
 
But I wanted to optimize EERAM writes when I had 4 byte wide changed data, so I set up a sample code where made use of I2C_EERAM_SequentialWrite() instead of the already tested and working I2C_EERAM_ByteWrite().
 
It succeeded in make the I2C transaction, I mean that data is sent to EERAM, and it is stored there, it even exits the routine cleanly with an ERR_I2C_MESSAGE_COMPLETE successful message, but a few instructions after executing I2C_EERAM_SequentialWrite(), the PIC24 halts to TRAPS_halt_on_error() with code error 2. This is an ADDRERR trap.
 
I tried with errLoc=getErrLoc() and discovered that the theoretically offending call was from the root of main, tried for hours to isolate an offending code, but no result. I simplified the code to the bare minimum, just call the offending routine and then just halt in a while(1){ClrWdt()};
 
The results have been always the same. Only when calling:
errStatus=I2C_EERAM_SequentialWrite(&eeramInstance, byteArray, 4, 0);
The PIC24 halts to ADDRERR trap after a few cicles after successfully saving and exiting the routine with ERR_I2C_MESSAGE_COMPLETE successful message.
 
If I do the same with:
errStatus=I2C_EERAM_ByteWrite(&eeramInstance, byteArray[0], 0);
errStatus=I2C_EERAM_ByteWrite(&eeramInstance, byteArray[1], 1);
errStatus=I2C_EERAM_ByteWrite(&eeramInstance, byteArray[2], 2);
errStatus=I2C_EERAM_ByteWrite(&eeramInstance, byteArray[3], 3);
The PIC24 successfully saves but there's never a halt.
 
I've invested a lot of hours in this issue, and as the other parts seem to work beautifully I'll leave it like it is, ugly and unoptimized but working with single byte writes.
 
If anyone at Microchip wants to improve this driver for the PIC24, I'm all ears and open to help as much as I am able, as for now I've been unable to progress further.
 
There are another 2 small issues:
1st minor issue) declaration on statusRegister is bit inverted, it is declared as:
typedef union statusRegister
{
  unsigned char value;
  struct {
  unsigned AM      :1; ///< Array Modified bit
  unsigned RESERVED:2; ///< Additional byte-wide padding, bits not used in status register
  unsigned BP      :3; ///< Block Protect bits
  unsigned ASE     :1; ///< Auto Store Enable bit
  unsigned EVENT   :1; ///< Event bit
  };
} I2C_EERAM_STATUS_REGISTER_T;
 
but should be:
 
typedef union statusRegister
{
  unsigned char value;
  struct {
  unsigned EVENT   :1; ///< Event bit
  unsigned ASE     :1; ///< Auto Store Enable bit
  unsigned BP      :3; ///< Block Protect bits
  unsigned RESERVED:2; ///< Additional byte-wide padding, bits not used in status register
  unsigned AM      :1; ///< Array Modified bit
  };
} I2C_EERAM_STATUS_REGISTER_T;
 
2nd minor issue) Generated code always includes the header file without extension:
#include "i2c_eeram_app"
It's not difficult for me to correct this to:
#include "i2c_eeram_app.h"
 
But it is surprising that this has escaped any automated compilation test.
 
Best regards, hope this helps !
#1

5 Replies Related Threads

    ric
    Super Member
    • Total Posts : 24593
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC24 I2C Master to EERAM 47L16 with MCC ADDRERR trap 2019/07/04 21:21:48 (permalink)
    0
    I've never used that chip or code, so this is just an "out there" guess.
    Could it by trying to use DWORD access to your byte array?
    Is the array location aligned to a multiple of 4?
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    iprat
    Senior Member
    • Total Posts : 122
    • Reward points : 0
    • Joined: 2003/11/07 12:36:56
    • Status: offline
    Re: PIC24 I2C Master to EERAM 47L16 with MCC ADDRERR trap 2019/07/05 05:06:10 (permalink)
    0
    Hi ric:
     
    The array is an uint8_t array that starts at 0x890.
    All access to it is by byte.
    The libraries from microchip seem to access it by byte.
     
    I've played with my code, and had to move a local variable to global, that moved the array to 0x892 (this is expected), but surprisingly that has solved the issue, no more traps, not any.
     
    The local variable was created a few instructions before calling the I2C_EERAM_SequentialWrite() function, and was destroyed a few instructions after. This changes the stack, but I really don't understand why this solves the issue.
     
    In this kind of situations I usually search for user (me) error and only after compiler error. I've invested a few hours searching for my error, I'm beginning to think of a compiler/library/tool error. As it is now working, and I still have some weeks of programming with connected ICD3/ICD4 with this project maybe I'll learn new things about this strange issue.
     
    #3
    iprat
    Senior Member
    • Total Posts : 122
    • Reward points : 0
    • Joined: 2003/11/07 12:36:56
    • Status: offline
    Re: PIC24 I2C Master to EERAM 47L16 with MCC ADDRERR trap 2019/07/19 09:18:34 (permalink)
    0
    Hi ric and specially Microchip MCC team:
     
    I've finally found the bug, and it is at the MCC code in i2c_eeram_app.c, inside I2C_EERAM_SequentialWrite function.
     
    The condition at line 91 is incorrect:
     
    ERR_STATUS_T I2C_EERAM_SequentialWrite       (I2C_EERAM_T * eeramInstance, uint8_t * data, uint16_t size, uint16_t startAddress)
    {   
        static uint16_t        counter, timeOut, slaveTimeOut;

        eeramBuffer[0] = (startAddress >> 8);                // high address
        eeramBuffer[1] = (uint8_t)(startAddress);            // low low address
        
        for (counter=0;counter < size;counter++)
            eeramBuffer[counter+2]=*(data+counter);
             
        timeOut = 0;
        slaveTimeOut = 0;
        
        ERR_STATUS_T status = ERR_I2C_MESSAGE_PENDING;
        while(status != ERR_I2C_MESSAGE_FAIL)
        {
            I2Cx_MasterWrite(eeramInstance, eeramBuffer, size+2, eeramInstance->busAddress, &status);
    line 91-->>       while(status == ERR_I2C_MESSAGE_FAIL)
    new line 91--->>should be changed to:     while(status == ERR_I2C_MESSAGE_PENDING)
            {                
                if (slaveTimeOut == I2C_EERAM_GENERIC_DEVICE_TIMEOUT)
                    break;
     
    This error and the 2 others, bit order at I2C_EERAM_STATUS_REGISTER_T, and #includes lacking the ".h" extensions should be corrected.
     
    Which is the way to reach the MCC responsible of maintaining this libraries ?
    #4
    NKurzman
    A Guy on the Net
    • Total Posts : 18038
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: PIC24 I2C Master to EERAM 47L16 with MCC ADDRERR trap 2019/07/19 09:29:40 (permalink)
    0
    This is Not the MCC Forum.  You can try cross posting it there, Or put in a Support ticket.
    #5
    iprat
    Senior Member
    • Total Posts : 122
    • Reward points : 0
    • Joined: 2003/11/07 12:36:56
    • Status: offline
    Re: PIC24 I2C Master to EERAM 47L16 with MCC ADDRERR trap 2019/07/19 11:33:44 (permalink)
    0
    Cross posting means pasting a link to this thread in the other forum ? or do you prefer to just copy the text in a new thread over there ?
     
    Thanks for the hint ! I didn't notice there was an MCC on its own.
     
    post edited by iprat - 2019/07/19 11:35:28
    #6
    Jump to:
    © 2019 APG vNext Commercial Version 4.5