Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

I2C/SPI interweaving

Status
Not open for further replies.

dknguyen

Well-Known Member
Most Helpful Member
Hi all. So it turns out that this one sensor I want to use only has SPI control but all my other existing devices are I2C. My microcontroller has SPI and I2C pins on the same line basically.

The pins are multiplexed:
SDA/SDI
SCL/SDO
SCK

I read here
https://www.i2cchip.com/mix_spi_i2c.html
that if you did it properly, you could use software switch back and forth between the buses using the chip select lines to ensure the SPI ignores I2C communications.

Everything I know about I2C comes from here:
https://www.robot-electronics.co.uk/htm/using_the_i2c_bus.htm

So I2C devices ignore data that does not come in between a start/stop sequence (or after a start a sequence if you will). This somehow has to be used to ensure the I2C devices ignore the SPI communications. Normally, the I2C data does not change in the middle of a clock pulse, and when it does this means indicates an I2C start/stop sequence.

1.I haven't used SPI before, so I'm not sure how you can prevent this from happening while the SPI is doing it's stuff (so a false I2C trigger doesn't happen).

2. Do the I2C pull-up resistors do anything to affect the SPI?

3. I2C filters have filters while SPI does not, but this device is a compass and has to sit a foot away form everything else (noisy motors and stuff). I've never had to filter a digital signal before...just analog where I knew exactly what bandwidth I wanted and only cared about uniform phase response (rather than uniform magnitude response). Does anyone know what kind of filters to start looking at (and something about clock harmonics too? The only thing applicable thing I remember is elliptical filter- the word, nothing else).

4. Also about shielding (separate from the rest). My robot has an aluminum base and a roll cage which most of the electronics sit between. But some periphreals sit on top of the roll cage so I have a bunch of I2C/SPI and "motor-level current" cables running up and down the one foot distance between the base and roll cage. There are also noisy motors sitting underneath the baseplate. My motors are inside some aluminum motor mounts that are essentially an 5-sided aluminum box mounted onto a relatively large aluminum plate. The open face of the motor mounts enclosure faces the ground. THe electronics sit on top of the aluminum base. I'm wondering how this compares to a Faraday cage in terms of shielding since it's not totally enclosed, but rather is a metal plate and a 5-sided "cage" sitting between the detector/receiver (with the open face pointing away from the receiver). I'm worried about the noise mucking up things. I think the biggest problem right now is the power cables running up and down.

==============
EDIT: I just noticed that the compass's SPI interface is half duplex. I guess this means only the SDI/SDA or SDO/SCL line is transferring SPI data at any one time. So if I just hold the unused line low, it should never interfere with the I2C? If so...that makes things so much simpler. I guess that answers question 1.
 
Last edited:
justDIY said:
i2c is pretty forgiving ... how about using your hardware SSP module for the SPI bus, and use two other plain-jane pins for the I2C bus (software emulation)?

If you're talking about bit-banging, it's going to be integrating a gyro reading which is pretty inaccurate and is going to turn out pretty bad anyways...I'd like to dedicate most of the processor time to that. Let's not forget laziness...oh yeah, and I'm out of pins, hehe.
 
Last edited:
1. If the SCK line doesn't move, the SPI device doesn't care. Read-only SPI device would make sense - if it were bidirectional, I don't think you'd be able to share any lines.

2. pull-ups don't matter

3. I'd guess that the hardware "filters" are usually just glitch filters that get rid of nsec level spikes.

4. You need to figure out how much motor current is going through the ground line, and how much differential voltage you're going to see as a result of that current...
 
Hmm. So you're saying I don't even need a separate chip select to prevent the SPI from responding to I2C commands? Just tie the chip select input on the compass low and and just hold SCK low to disable the compass?
 
You might need access to the chip select to synchronize things (dunno, you'll have to check the actual device), but all the SPI devices I know of are essentially shift registers with SCK connected to the clocks. If the clock doesn't move, the registers don't care what happens at the input.
 
hjames said:
You might need access to the chip select to synchronize things (dunno, you'll have to check the actual device), but all the SPI devices I know of are essentially shift registers with SCK connected to the clocks. If the clock doesn't move, the registers don't care what happens at the input.

Makes sense, no clock = no data. Oh well, I got one extra digital pin that has no periphreals on it so might as well make that one the CS.
 
Status
Not open for further replies.

Latest threads

Back
Top