Go Down

Topic: 3.3V Sensors for I2C with Mega 2560 Rev 3 (Read 380 times) previous topic - next topic

PowerPro25

Oct 19, 2018, 08:10 pm Last Edit: Oct 19, 2018, 08:18 pm by PowerPro25
Cross posted here (https://www.reddit.com/r/arduino/comments/9ousm4/three_33v_sensors_using_i2c_on_mega2560/?utm_content=full_comments&utm_medium=message&utm_source=reddit&utm_name=frontpage)

Okay, so we are designing a project that is going to use the Mega 2560 Rev 3, and it will use the adafruit datalogging shield (part # 1141) to write sensor information from 3 sensors to the SD card. We are going to use 2 MPU-9250's 9-DOF sensors and 1 T9602-3-D-1 temperature and humidity sensor. All of these sensors run on 3.3V and are NOT 5V tolerant. The max is around 3.6V for the 9250 and 3.465V for the T9602. Each one of these sensors is on a breakout board and has 10k pull-up resistors on the SCL and SDA lines.

So, without using a level shifter, would I be able to just disable the internal pull-up resistors on the SDA and SCL lines so that the voltage is not pulled up to 5V and thus allowing all of the sensors to run on 3.3V to get the correct logic level information?

It looks like the Mega2560 has to see a minimum of 0.7V * VCC for a logic level high which leads me to believe it would have to be a minimum of 3.5V which would not work.

I know the Mega 2560 has 10k pull-up resistors, but I do not know if the I2C lines will operate correctly if they are disabled (or whether or not I can even disable them). If they were not disabled then I suppose I could put a 30k resistor in series with SCA and SDL lines to get a 40k pull-up, and then if I have the 10k pull-ups from the 3 sensors in parallel, then I would actually have about 1, 3.3k resistor. So when I do the voltage divider I would get 3.3k/(40k+3.3k)*(5V-3.3V)=0.13V so I would have approximately 3.43 volts across the sensors which I believe would work.

Please let me know if you have any guidance or how you would recommend going about this.

Grumpy_Mike

Quote
It looks like the Mega2560 has to see a minimum of 0.7V * VCC for a logic level high which leads me to believe it would have to be a minimum of 3.5V which would not work.
Strictly speaking true. However in practice you will find it most of the times it does work but it is not guaranteed.

Quote
I know the Mega 2560 has 10k pull-up resistors, but I do not know if the I2C lines will operate correctly if they are disabled (or whether or not I can even disable them).
They are hardware resistors so the only way to disable them is to remove them. Then you must disable the internal pull up resistors by using a libiary that does not enable them by default, or by turning them off with a pin mode INPUT call for both pins just after calling the wire begin.

Quote
If they were not disabled then I suppose I could put a 30k resistor in series with SCA and SDL lines to get a 40k pull-up, and then if I have the 10k pull-ups from the 3 sensors in parallel, then I would actually have about 1, 3.3k resistor.
No don't even go there, it will not work.




PowerPro25

So basically my only option would be to either use a level shifter or to go with a 3.3V board like the Due? My problem with the level shifter is finding one that won't interfere with the signals and will work for the high speed polling rates of 4KHz for the two MPU-9250 accelerometer portions. The temp/humidity is only at 1Hz so not really too worried about that.

CrossRoads

Or use a part like this

http://www.ti.com/lit/ds/symlink/tca9543a.pdf

Quote
The pass gates of the switches are constructed such  that the VCC pin can be used to limit the maximum high voltage which will be passed by the TCA9543A. This allows the use of different bus voltages on each pair, so that 1.8-V, 2.5-V, or 3.3-V parts can communicate with 5-V parts without any additional protection. External pull-up resistors pull the bus up to the desired voltage level for each channel. All I/O pins are 5.5-V tolerant.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

PowerPro25

Or use a part like this

http://www.ti.com/lit/ds/symlink/tca9543a.pdf

Isn't this essentially just a multiplexer like this one https://www.adafruit.com/product/2717?gclid=CjwKCAjwgabeBRBuEiwACD4R5hjl7jZ8E8IHj_vvEAxF4eJEtbFjiQEBB67p1RfPsEuwNVge-_KslRoCP-kQAvD_BwE, so wouldn't it still require the sensors to be 5V compliant in order to work correctly? Also with this, can't you only read in one clock and data line at a time or can you read in multiple busses with this?

Would you recommend using a multiplexer, or a level shifter, or just switching to a due and not having to worry about either of them.

Wawa

The Mega has physical 10k pull up resistors on the I2C lines.
You can counteract that with 20k resistors to ground.

Not sure if Wire.begin() also enables the internal pull up on a Mega.
If so, you can counteract that as well with a "digitalWrite, LOW" to the pins right after the Wire.begin() command.
Code: [Select]
 Wire.begin();
  digitalWrite(SDA, 0);
  digitalWrite(SCL, 0);


Now measure the I2C pins, and see if the pull up voltage is <=3.5volt, before you connect the sensors (with their own onboard 3.3volt pull up).

The switchpoints of a Mega are 0.3*VCC and 0.6*VCC on a 5volt MCU supply (not 0.7*VCC).
See page 355 of the Atmel 2560 datasheet.
Leo..



wvmarle

My problem with the level shifter is finding one that won't interfere with the signals
Based on the circuit (a MOSFET + extra pull-ups) it seems they do not interfere with the signals much if at all. You can of course just use stronger pull-ups.

Quote
and will work for the high speed polling rates of 4KHz for the two MPU-9250 accelerometer portions. The temp/humidity is only at 1Hz so not really too worried about that.
That is more of a problem. At a typical 400 kHz I2C clock speed you can transmit 100 bits in total per poll: that starts with the 16 or 24 bits just for the request sent to each device! What are you going to do with all that data, and do you really need that kind of polling frequencies?
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

PowerPro25

Based on the circuit (a MOSFET + extra pull-ups) it seems they do not interfere with the signals much if at all. You can of course just use stronger pull-ups.

That is more of a problem. At a typical 400 kHz I2C clock speed you can transmit 100 bits in total per poll: that starts with the 16 or 24 bits just for the request sent to each device! What are you going to do with all that data, and do you really need that kind of polling frequencies?
We have to write the data to an SD card, but it does not have to continuously poll at 4kHz for the accelerometer, it just has to write to the SD card when it goes above a certain threshold. I assume it would not be writing for more than 30 seconds but both of them would have to write to the SD card. It is just going to write the temp/humidity sensor information, the gyro information, and both acceleration data to the SD card with times from the RTC.

The request for 4kHz is from our sponsor and he is adamant on having it poll that fast so that he can calculate a power spectral density. The sensor is set up for I2C and some other people said they got it to work at 4kHz. Is there anyway to figure out how many bits of data is going to get sent? You will have to excuse me as I have hardly any arduino coding experience, the computer guy on our team will be doing most of the coding.

wvmarle

Is there anyway to figure out how many bits of data is going to get sent?
Yes: read the data sheet of the sensor carefully, and make sure you fully understand the I2C protocol. If your sensor (and Arduino) can do the 1 MHz+ I2C speed you got more leeway.

You're talking about TWO sensors, on the same bus, so each gets only half the available bandwidth.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up