Sign in to follow this  

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
Sign in to follow this  


User Feedback


There are no comments to display.



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now