Bare Bones I2C Master Writer


Wicked Minds Electronics
  • Wicked wrote an excellent VHDL code that allows him to perform some I2C writes to initialize a couple of devices

click here for the Original forum thread

My design only requires me to perform some I2C writes to initialize a couple of devices. After trying several different methods and being new to FPGA in general I found that this solution was even simpler than implementing PicoBlaze.

Customizing

To define the I2C writes performed look inside SimpleI2CCore.vhd where you will find an array called seq:


constant seq: seqT:= (
-- RESET CAM
(idle, x"00"),
(start, x"00"),
(const, TCM_DEV_ADDR & '0'),
(const, TCM_REG_SLEEP),
(const, TCM_SOFT_RESET),
(stop, x"00"),

.
.
.

(start, x"00"),
(const, VIDEO_ENCODER_ADDR & '0'),
(const, VIDEO_CONTROL_5),
(const, x"60"),
(stop, x"00"),
-- end
(idle, x"00")
);

Change the const values to the appropriate ones for your device(s). In the attached project there are several writes defined for two different devices, you can remove/add as many as you like just always ensure your last value is idle so that it releases the SCL and SDA lines. Also note the device address constants are 7 bits.

Remember to modify the top boundary of the array here:


type seqT is array(0 to 41) of i2cT;

With a 24Mhz input clock, it produces a 100KHz I2C clock. The additional DCM in the attached project that provides 27MHz is only to drive the external I2C devices and can be removed or modified as needed.

Live output from Papilio:

simplei2c.jpg

Hopefully others will find this as useful as I did :)

Source Code: SimpleI2C.zip


Download Source Code
  Report Article



User Feedback


There are no comments to display.



Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.