• AVR Freaks

Hot!Writing to I2C EEPROM with MCC Support

Author
Wesley_88
New Member
  • Total Posts : 11
  • Reward points : 0
  • Joined: 2018/11/26 17:19:06
  • Location: 0
  • Status: offline
2019/10/30 12:18:10 (permalink)
0

Writing to I2C EEPROM with MCC Support

HI,

I am using MCC support for writing to an external I2C EEPROM.
Master is PIC18F47K42 and Slave is 24LC024H.
The i2c code generated by MCC is hard to understand
See MCC example code in attachment.
On top of that it seem to have some error on the MCC generated code that doesn't let me compile.  

on the code below, do anybody know what is "I2C_EEPROM_T * eepromInstance" and "ERR_STATUS_T *pstatus" for I am not sure what I should replace them with.

I2Cx_MasterWrite(I2C_EEPROM_T * eepromInstance, uint8_t *data, uint8_t size, uint8_t busAddress, ERR_STATUS_T *pstatus);

Thank you

Attached Image(s)

#1

9 Replies Related Threads

    katela
    Super Member
    • Total Posts : 1808
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: offline
    Re: Writing to I2C EEPROM with MCC Support 2019/10/31 05:41:15 (permalink)
    +1 (1)
    There are some short descriptions in the I2C.h file how to use those functions. Here is an example: https://mplabxpress.micro...ud/example/details/519

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #2
    Mysil
    Super Member
    • Total Posts : 3671
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: Writing to I2C EEPROM with MCC Support 2019/10/31 10:45:28 (permalink)
    +1 (1)
    Duplicate thread, see
    https://www.microchip.com/forums/FindPost/1117059
     
        Mysil
    #3
    Wesley_88
    New Member
    • Total Posts : 11
    • Reward points : 0
    • Joined: 2018/11/26 17:19:06
    • Location: 0
    • Status: offline
    Re: Writing to I2C EEPROM with MCC Support 2019/10/31 12:01:41 (permalink)
    0
    Thank you for the link, but I believe the information is for the slave mode I2C. 
    For my application I need the master mode I2C.
     
    Initially I tried several attempt by using the typical I2C2 code that was generated by MCC for PIC18F47K42 to write to an external I2C EEPROM 24LC024H with the code below but no success
     
    i2c2_write1ByteRegister(uint8_t address, uint8_t reg, uint8_t data)
     
    I contacted the tech support and they told me by using the I2C EEPROM code generate by MCC below will work
     
    I2Cx_MasterWrite(I2C_EEPROM_T * eepromInstance, uint8_t *data, uint8_t size, uint8_t busAddress, ERR_STATUS_T *pstatus);
     
    But once I generate the code, there were 2 error being generated by MCC on the i2c_eeprom_app.c which I have no idea how to correct, and because of the error I was not able to compile the code.
    #4
    du00000001
    Just Some Member
    • Total Posts : 3774
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: Writing to I2C EEPROM with MCC Support 2019/10/31 14:53:48 (permalink)
    +3 (3)
    Would be nice if you provided the error texts instead of only ranting about these.
    post edited by du00000001 - 2019/11/05 12:56:23

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #5
    Wesley_88
    New Member
    • Total Posts : 11
    • Reward points : 0
    • Joined: 2018/11/26 17:19:06
    • Location: 0
    • Status: offline
    Re: Writing to I2C EEPROM with MCC Support 2019/11/05 10:24:49 (permalink)
    -1 (1)
    What error texts do you want to see ? 
    I actually attached 2 picture showing the error generated by MCC on my original post on top. The errors occur on the i2c_eeprom.t and i2c_eeprom.c file
     
     
    #6
    du00000001
    Just Some Member
    • Total Posts : 3774
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: Writing to I2C EEPROM with MCC Support 2019/11/05 13:04:00 (permalink)
    +1 (1)
    I would have loved to see some compiler error output, not some fancy hardcopies of MPLAB's screen.
    Anyway: if you did not configues I2C2, i2c2.h will not be available. Including all definitions contained within.
    And if the 2nd I2C isn't denominated I2C2 on the PIC18s, this would be another indication that the i2c_eeprom_app isn't targeting PIC18s.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #7
    Wesley_88
    New Member
    • Total Posts : 11
    • Reward points : 0
    • Joined: 2018/11/26 17:19:06
    • Location: 0
    • Status: offline
    Re: Writing to I2C EEPROM with MCC Support 2019/11/07 16:53:51 (permalink)
    0
    I finally resolve my own issue.
     
    Apparently, it is easier to use the below generic I2C command to write to an external EEPROM
     
    i2c1_write1ByteRegister(uint8_t address, uint8_t reg, uint8_t data);
     
    Previously it did not work because I enter one extra bit for the slave address. Instead of 7 bits, I included the last write bit and make it 8 bits.
     
    Thank you for everyone help. 
    #8
    meanilkp
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2018/08/19 22:12:10
    • Location: India
    • Status: offline
    Re: Writing to I2C EEPROM with MCC Support 2020/05/04 21:11:14 (permalink)
    0
    Hi,

    You can use these below MCC functions for communicating with 24LC024H
    inlcude mcc_generated_files\examples\i2c1_master_example.h
    Ex:
    24LC024H Slave Address: 0x50
    #define 7BIT_24LC024H_ADDR 0x50

    Write Data to specific memory location (0xAA(Data) to 0x1002(Memory Address location))
    unint8_t txBuff[20] = {0x10,0x02,0xAA};
    I2C1_WriteNBytes(7BIT_24LC024H_ADDR,txBuff,3);
    Memory Location = Data
    0x1002 = 0xAA

    Write array to 4 subsequent memory location
    0x1020 = 0x11, 0x1021 = 0x22, 0x1022 = 0x33, 0x1023 = 0x44
    unint8_t txBuff[20] = {0x10,0x20,0x11,0x22,0x33,0x44};
    I2C1_WriteNBytes(7BIT_24LC024H_ADDR,txBuff,6);
    Memory Location = Data
    0x1020 = 0x11;
    0x1021 = 0x22;
    0x1022 = 0x33;
    0x1023 = 0x44;

    Read data from Specific memory location (Memory location is 0x10)
    //Set Write location to 0x1002
    unint8_t rxBuff[20];
    unint8_t txBuff[20] = {0x10,0x02};
    I2C1_WriteNBytes(7BIT_24LC024H_ADDR,txBuff,2); //Set memory location
    I2C1_ReadNBytes(7BIT_24LC024H_ADDR,rxBuff,1); //Read from setted located
    Output
    rxBuff[0] = 0xAA;

    Read data to continues memory location
    Read data from Start memory location (Memory location is 0x1020)
    //Set Write location to 0x20
    unint8_t rxBuff[20];
    unint8_t txBuff[20] = {0x10,0x02};
    I2C1_WriteNBytes(7BIT_24LC024H_ADDR,txBuff,2);
    I2C1_ReadNBytes(7BIT_24LC024H_ADDR,rxBuff,4);
    Output
    rxBuff[0] = 0x11;
    rxBuff[1] = 0x22;
    rxBuff[2] = 0x33;
    rxBuff[3] = 0x44;
    post edited by meanilkp - 2020/05/05 22:29:44
    #9
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11882
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: Writing to I2C EEPROM with MCC Support 2020/05/04 23:02:00 (permalink)
    +1 (1)
    7BIT_24LC024H_ADDR

     
    I hope that's not from MCC since it's not valid C.
    #10
    Jump to:
    © 2020 APG vNext Commercial Version 4.5