Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Looking for a SPI to I2C converter design

Status
Not open for further replies.

verylsi

Full Member level 2
Joined
Mar 12, 2012
Messages
123
Helped
16
Reputation
32
Reaction score
16
Trophy points
1,308
Activity points
2,130
Dear All,

I am looking to design a I2c to SPI bridge , SPI Slave on one side and I2C master on another side.
I have a reference document too - www.altera.com/literature/an/an486.pdf

I want to do it on my own, But dont know where to start from.
I dont have time, I have at max 10 days.

Please guide me.

Thanks in advance
 

Re: SPI to I2C Converter

The application note is very detailed, so I wonder what you are asking for. You should also inspect the example code
**broken link removed**

More generally
- check if the suggested SPI-to-I2C bridge functionality fits your requirements, otherwise specify a different one
- start with the design implementation
- test the design
 

Re: SPI to I2C Converter

1 - I want to do it on my own

2 - But dont know where to start from.

3 - I dont have time, I have at max 10 days.

Cool set of mutually exclusives you have there!

Please guide me.

Ditch one out of those three items?

Other than that, mostly check if the i2c master in that CPLD bridge does everything you need. Generally speaking: SPI is totally easy, and I2C master implementations are annoying / non-trivial. So the i2c master in that bridge deserves some extra careful reading to check if it really does what you hope it does.

And for the rest it's pretty much everything FvM already said. :)
 

Re: SPI to I2C Converter

Hi FVM,

Thanks, that code is in Verilog, I am little weak in that, abut anyhow I can manage.
But can you tell me how to test that code. coz that test bench is not working.

---------- Post added at 18:17 ---------- Previous post was at 18:12 ----------

Hello mrflibble,

I gone through the design example on the link provided by FvM, and it was in verilog,
can I understand the functionality of that apart from going through that code.?
 

Re: SPI to I2C Converter

Hello mrflibble,

I gone through the design example on the link provided by FvM, and it was in verilog,
can I understand the functionality of that apart from going through that code.?

Couldn't say really. I skimmed the pdf + code just to check for any obvious gotcha's. I would hope the pdf gives you a rough idea.

Okay, just did a quick check of code/SPI_to_I2C.v and the code looks readible enough. Bummer that you didn't get the testbench to work. That's always my favorite way to quickly get a rough idea of what some module is doing.

Any specific errors you are getting on simulation?
 

Re: SPI to I2C Converter

My experience with Altera reference designs is, that they are basically working. But you may want to change some features here or there and then you get the chance to introduce design errors that need to be debugged.

I didn't check it the code. Verilog testbench issues are mostly related to not knowing which libraries have to be included. It's somewhat different from VHDL, where all libraries are explicitely imported in the design. But I think, you don't necessarily need to operate the testbench. If you have a working hardware SPI master and I2C slave device, you can also debug in hardware, if you have a FPGA with sufficient resources for Altera Signal Tap or Xilinx Chipscope.
 
  • Like
Reactions: verylsi

    verylsi

    Points: 2
    Helpful Answer Positive Rating
Re: SPI to I2C Converter

I think some altera libraries might be needed. I did a real quick quick test of the testbench, and it was missing some stuff that looked suspiciously much like altera specifics. (Currently only have ISE installed, sorry...)
 
  • Like
Reactions: verylsi

    verylsi

    Points: 2
    Helpful Answer Positive Rating
Re: SPI to I2C Converter

The design uses the MAX II internal oscillator, which has a typical frequency of 3.3 to 5.5 MHz. In most cases, you'll want to replace it with an external clock source. A clock divider may be neccessary with a faster input clock to keep the I2C timing. Everything else seems to be pretty standard logic design, MAX II doesn't offer any special features except for the oscillator and the built-in user flash.
 

Re: SPI to I2C Converter

Something to note, SPI and I2C have some subtle differences. SPI is more suited to longer data streams. I2C carries addressing information inherently. I2C is more suited to memory map, register and control accesses. This is not so important for this application but good to remember.

My advice would be to:
1. Instantiate Altera reference design.
2. Test SPI slave first. You can do this by making the SPI master initiate a transaction and firstly probing the hardware signals.
3. Next, probe internally into the FPGA/CPLD (using Signal tap/Chipscope), once again check the SPI lines (SPI_sclk, SPI_cs, etc)
4. Check the command_reg, data_in, data_out and status_reg.
5. Next proceed to the I2C master. Check that command_word takes on the value of command_reg.
6. Check I2C_sda and I2C_scl.

I mostly use VHDL, not Verilog but the design is well commented and easy to follow. Just stick to the steps I have outlined. Don't try and get the entire design working in a single shot but rather verify bit by bit in the hardware if possible.
 
  • Like
Reactions: verylsi and FvM

    FvM

    Points: 2
    Helpful Answer Positive Rating

    verylsi

    Points: 2
    Helpful Answer Positive Rating
Re: SPI to I2C Converter

Thanks rreddy,

Will keep all this in mind,
I never used chipscope yet, Probably this is a good opportunity to learn how to use chipscope.

Thanks again.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top