1 Reply Latest reply on Nov 17, 2014 6:24 AM by MichaelF_56

    WICED Smart BCM92073X I2C EEPROM Emulation Porting Guide

    userc_4697

      Preface

      I2C Timing of EEPROM

      State Machines of Emulation Code

      Porting Steps

      Debug Code

      Generate the BCM2073x Image Array

      Get the Emulation Code

       

      Preface

      If BCM2073x connects a powerful host MCU and the host MCU has a big capacity memory, it’s possible to store the BCM2073x image in the host MCU memory. But the host MCU usually does not have I2C slave port, so we implement the code to emulate I2C slave timing of EEPROM by using two GPIOs on host MCU side. This document introduces how to port the emulation code for different MCU.

      Note:

      1. The code only emulates reading data from EEPROM, because it’s difficulty to catch the I2C slave timing when writing data to EEPROM.
      2. Detect the SCL/SDA level by polling in emulation code. Please disable the interrupt when running the simulation code, because one or more I2C SDA/SCL bit will be missed when executing the ISR. The valid level of SCL/SDA only keeps 5us when I2C speed is 100K, and only keeps 1.25us when I2C speed is 400K.
      3. The emulation code needs fine-tune after porting based on different HW.

       

      I2C Timing of EEPROM

      The following figures are the timing of read or write EEPROM, please refer to EEPROM datasheet to get more information.

      1. Random Read

      1.png

      2. Sequential Read

      2.png

      3. Byte Write

      3.png

      4. Page Write

      4.png

       

      State Machines of Emulation Code

      The emulation code runs on host MCU side only for reading the BCM2073x image from the host MCU memory. BCM2073x loads the image from EEPROM by “Random Read” or “Sequential Read”.

      The following is the state machines of emulation code.

      • SM1 - Idle
      • SM2 - Receive device address from BCM2073x
      • SM3 - Receive the data address from BCM2073x
      • SM4 - Send data to BCM2073x

       

        SM1 - Idle

      Detect I2C start bit, transfer to SM2 if found the I2C start bit, or exit the simulation if not detect the start bit after idle timer timeout expires.

        SM2 – Receive device address from BCM2073x

      Receive the device address, transfer to SM1 if device address isn’t matched, or transfer to SM3 if the device address is matched.  

        SM3 – Receive data address from BCM2073x

      Receive the two byte data address, transfer to SM4 if the correct address is gotten.

        SM4 – Send data to BCM2073x

      Send one byte data to BCM2073x, transfer to SM1 if got the I2C stop bit, or keep the SM4 and continue to send more data if ACK is received.

       

      Porting Steps

         1. Re-write the following functions.

      void scl_sda_init(void)

      BYTE get_scl(void)

      BYTE get_sda(void)

      void set_sda(void)

      void change_sda_to_output(void)

      void change_sda_to_input(void)

      void scl_sda_follow_init(void)

      void scl_follow_high(void)

      void scl_follow_low(void)

      void sda_follow_high(void) 

      void sda_follow_low(void)

      2. Re-define the follow timeout.

      #define SCL_HIGH_TIMEOUT         200

      #define SCL_LOW_TIMEOUT         200

      #define STOP_TIMEOUT                 1000

      #define START_TIMEOUT               1000

      #define IDLE_TIMEOUT                   5000  // 2s

      3. Change the WICED Smart Code to make the corresponding BCM2073x image.

      • Enable the RAMBUFENABLE macro in sparinit.c, use the RAM to store the data that wrote to NVRAM (VS section in EEPROM).
      • Change the I2C speed from 400K to 100K in the mandatory.cgs if can’t catch the I2C 400K timing.

       

       

      Debug Code

       

      Don’t use functions that like “printf” to debug code, because the SCL/SDA bit will be missed when executing these functions.

      Suggest using the following ways to debug code.

      1. Use another two GPIOs to sync the SCL/SDA timing in the I2C communication, named the two GPIO as following SCL/SDA. We can look the waveform of following SCL/SDA to judge whether code is correct or not. If the waveform of following SCL/SDA matches the waveform of original SCL/SDA, it means the emulation works correctly.
      2. Save the running information in the temporary variants when running the emulation code, and print the variants when exited the emulation.

       

      Generate the BCM2073x Image Array

      If the host MCU has file system, you can directly store the BCM20732 binary image (*.bin) in the file system. If the host MCU does not have the file system, we usually use an array to store the BCM20732 image in MCU memory. Refer to the following steps to generate the BCM2073x image array.

      1. Run windows console on PC.
      2. Covert image from HEX format to BIN format.

      ihex2bin.exe -f 0x00 xxx.hex xxx.bin

         3.  Covert BIN image to an array.

      bin2c -m 128 xxx.bin xxx.h xxx_image

         4. You can find the image array named xxx_image in xxx.h.