KSDK I2C EEPROM Example

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

KSDK I2C EEPROM Example

KSDK I2C EEPROM Example

Hello Kinetis world!

Kinetis SDK is here to stay and with it there are good opportunities ahead, such as coding flexibility, portability, RTOS enablement, projects scalability and more.

Right now this is a brand new solution introduced by Freescale, so a lot of tutorials, How-To's and demo codes are coming, in addition to those already in the KSDK installation.

I wanted to share an example project developed with KSDK v1.0.0 and KDS v1.1.1, which uses a simple driver to communicate to an I2C EEPROM memory using a FRDM-K64F board. The driver is focused and was tested with a 256 Kbit memory (24xx256), but it should be compatible with the 64Kbit, 128 Kbit, 256 Kbit and 512 Kbit versions. This demo project demonstrates how to use the APIs of the KSDK I2C Master Driver.

The connections are as next:

FRDMK64_EEPROM.png

Please notice this is not intended to be a robust driver for I2C EEPROMs. Instead consider it a basic demo code, but with time we could improve it.

The attached pdf is an overview/explanation of the example, while the zip folder contains the project for Kinetis Design Studio v1.1.1.

:smileyalert: Before the project can be successfully compiled, you need to have installed KSDK v1.0.0 (www.freescale.com/ksdk) and have the FRDM-K64F platform library already built. For instructions on how to build the platform library you can refer to Appendix A of the next document in KSDK installation folder:

C:\Freescale\KSDK_1.0.0\doc\Kinetis SDK K64 User's Guide.pdf

:smileyinfo: NOTE: Disregard IAR and Keil instructions and refer to KDS part.

Importing and compiling the example project with KDS


     1) Unzip the package. It is recommended to place it into your KDS workspace, but it can be located at any place.

     2) From KDS go to File -> Import -> General -> Existing Projects into Workspace.

     3) Check "Select root directory" and click on "Browse" to search for the location of the unzipped folder. Then click OK.

     4) Mark the check box for "I2C_EEPROM_K64" and click on "Finish".

     5) Go to Project -> Build Project or simply click on the hammer icon. Build process should finish with no errors.

The project provides a default Debug Configuration to use with the Segger J-Link emulator firmware v2.0 installed in the FRDM-K64F. If you wish to use a different connection please refer to the next link:

https://community.freescale.com/docs/DOC-101845

I hope you like this demo.

Many thanks and credits to abigailinzunza, for her valuable help developing this project.

Regards!

Jorge Gonzalez

Labels (1)
Attachments
Comments

Just one small technical note: Prior we start with EEPROM connecting we have to check schematic revision of our FRDM-K64F board. Old boards with schematic version older than version D1 had swapped SCL&SDA signals. More details here:

http://www.freescale.com/files/32bit/doc/errata/FRDMK64F_ERRATA.pdf

BR

RadekS

Good morning Jorge_Gonzalez

I have a complication which should envar i2c slave a 7-bit address and 8 bit address needs to be manimupado, ie, time need to send it to "1" and Oura to "0", however I am having difficulty manipulating this bit in your example.

Could you give me a hand in this case.

Hello Paulo Montanher:

The address is defined with the macro "EEPROM_ADDRESS" in the file I2C_EEPROM.h. This address is used in the structure eeprom from the file I2C_EEPROM.c, together with the baudrate. This structure is used to call the KSDK I2C driver APIs.

Just notice the address is right justified and the driver takes care of shifting the address 1-bit to the left.

Regards!

Jorge Gonzalez

Hello  Jorge;

Is it possible to provide zip file for KDS 3.1 with KSDK 1.3

Thanks

Shaul

Hello shaul dorf:

Right now I don't have this project for KSDK v1.3 and KDS v3.1. However I checked the APIs and configuration structures from the I2C driver in KSDK v1.3 and there is not much difference, so you can easily replicate it.

- Create a new KSDK v1.3 project with KDS wizard or use the KSDK_Project_Generator.

- Import the files I2C_EEPROM_Example.c, I2C_EEPROM.c and I2C_EEPROM.h.

- In the case of the file fsl_i2c_irq.c you have to use the one from KSDK v1.3 instead of the old one.

- Do not forget to build the KSDK platform library for your device and add the binary from the linker options (Project -> Properties -> C/C++ Build -> Settings -> Cross ARM C++ Linker -> Miscellaneous -> Other objects).

If you run into any issues please feel free to ask.

Regards!

Jorge Gonzalez

Hi Jorge,

  I have a K22 as the I2C master using PE and KSDK 1.3  and that seems to be working fine,

however, it is talking to the I2C slave which is a sensor based on the KE02 which also uses PE.

But I have only gotten the slave to be able to respond to the master sending (using I2C_DRV_MasterRecieveDataBlocking).

In the slave it responds to this in the I2C_OnSlaveTxRequest() event handler, where I call the function

I2C_SlaveSendBlock(...).

I tried to do something similar in the I2C_OnSlaveRxRequest() event with the I2C_SlaveReceiveBlock(...) function,

but I can't get it to work right.

I am not even convinced that the part I have working is the 'right' way to do it.

Can you give an example of I2C slave code that can respond to the Master doing both write and reads, instead of the one way communication I have right now?

What I would really like to do is have the master send a command byte, and then receive the a response.

It is the slave code that I am having troubles with.

Thanks,  Brynn

Hello Brynn:

The projects in the next links should help you as reference for what you try to achieve. In these projects the K22 master sends 4 bytes (0,1,2,3) to the KE02 slave and then the slave sends 4 bytes (4,5,6,7) to the master. I used FRDM-K22F and FRDM-KE02Z40M (R47 and R39 need to be soldered).

K22FN512_I2C_Master_KSDK_1_3.zip

KE02_I2C_Slave_PE_LDD.zip

I hope this helps!

Regards,

Jorge Gonzalez !

Hello Jorge;

Finally I have time to check your Project Import recommendations.

The final results are importing warnings and Build errors that I don’t understand.

It was done with KSDK 1.2 and 1.3.

I’m attaching images of my Importing steps.

0_UserVariables.jpg

2_Import.jpg

Unexplained import message

3_UpgradeLegacy.jpg

4_WarmingProblem.jpg

Project setting

7_ProjectSetting.jpg

6_BuildErrors.jpg

I don't understand what is wrong in my steps

Thanks,

Shaul

Hello Shaul Dorf:

You tried to import the project and fix it to work with KSDK v1.3. As I mentioned it should be simpler if you create a project for KSDK v1.3 using the project generator and then just copy the relevant EEPROM source/header files from my example.

/Jorge Gonzalez

Hello Jorge;

Thanks

1. My initial assumption was that import is working. Now I understand that it is good for importing examples from KSDK examples folder. Is it correct?

2. I create new project using “Writing my first KSDK Application in KDS Hello World and Toggle LED with GPIO Interrupt”

3. I used your files from Sources folder and hardware_init.c from Board folder.

4. I had changed the HW_I2C2 to 0 in fsl_i2c_irq.c

5. In hardware_init.c there is variable named HW_PORT_INSTANCE_COUNT (lines 68 and 88) that Builder claims as undefined. I didn’t find where it is defined, without any knowledge why I changed it to 10.

6. There is only one warning that variable ‘dataRByte’ is not used file I2C_EEPROM_Example.c (line 60)

Regards

Shaul

No ratings
Version history
Last update:
‎10-09-2014 02:30 PM
Updated by: