Intelligent I2C controller


Recommended Posts

Hi, I've been quite quiet lately but here is my latest project:


It is a small programmable controller that makes it quick and easy to talk to I2C devices. The controller has a single I2C bus, 16 binary inputs, 16 binary outputs and write I2C data to 32 8-bit registers. 


It has a simple assembler-like language of 15 instructions, and the page includes a single file 'c' assembler written using only the standard C library (avoiding trying to find flex and yacc for Windows).


Here's some sample code:

;===============================================================; Reading from the HMC5883L Compass (I2C device ID is 0x3C / 0x3D);---------------------------------------------------------------        WRITE 0x3C ; Switch to continious measurement mode        WRITE 0x02        WRITE 0x00        STOP reread: WRITE 0x3C ; Start Write transaction        WRITE 0x03 ; Ponter to Reg 3        STOP         WRITE 0x3D ; Start Read transaction        MASTERACK        READ  0    ; Reg 3 - X, most significant byte        MASTERACK        READ  1    ; Reg 4 - X, least significant byte        MASTERACK        READ  2    ; Reg 5 - Y, most significant byte        MASTERACK        READ  3    ; Reg 6 - Y, least significant byte        MASTERACK        READ  4    ; Reg 7 - Z, most significant byte        READ  5    ; Reg 8 - Z, Least significant byte (no MACK on last read)        STOP         SET   0    ; Indicate that new, consistent data is available        CLEAR 0                  DELAY 32768 ; Wait for approx 1/10th of a second        JUMP reread 
Link to comment
Share on other sites

*um*, a rather heavy 160 slices (blush). It goes down to about 140 if you remove the MASTERACK instruction, but it is so useful!


That is with most of the 16 outputs and inputs wired to something. It also depends on if the code is large enough that it gets inferred as BRAM rather than LUTs (of course you want it in BRAM if you intend to update it with DATA2MEM...

Link to comment
Share on other sites

Join the conversation

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

Reply to this topic...

×   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.