Topics

Raduino logic levels


Jim, N5IB
 

New to the BITX community, but have had some Arduino/DDS projects in the portfolio, and while awaiting my rig have been doing dangerous and foolhardy things - reading manuals and schematics - hi

Noticed the NANO's 5 V level SCL and SDA lines are tied straight in to the 5351a's I2C inputs, with 2.2K pullups to the Vdd supply at 3.3 V
Clearly many reliably working radios are out there, but SiLabs specs 3.8V as absolute max I2C input. Have I missed a memo?

Jim, N5IB


Smitty, KR6ZY
 

The Nano can work at anywhere from 2.8 to 5.5, so it’s not phased by seeing 3.3v on it’s input.

I2C is an open collector bus, meaning none of the devices on the bus actively drive the bus high, they only ever pull it low to ground. The pull-up resistor does the job of pulling the bus high of none of the devices on the bus are actively pulling it low. So connecting the pull-ups to 3.3v mean that the bus will only ever go up to 3.3v, which is in-spec for the Si5351, and is high enough that the Nano (really an Atmel ATmega328) can tell it’s a HIGH, even though the rest of the device is operating at 5v.

The important part is that the Nano never puts 5v on the line. It only ever goes high impedance, or ground.

Does that make sense?

-Mark

On Dec 28, 2017, at 1:36 PM, n5ib_2 <n5ib@...> wrote:

New to the BITX community, but have had some Arduino/DDS projects in the portfolio, and while awaiting my rig have been doing dangerous and foolhardy things - reading manuals and schematics - hi

Noticed the NANO's 5 V level SCL and SDA lines are tied straight in to the 5351a's I2C inputs, with 2.2K pullups to the Vdd supply at 3.3 V
Clearly many reliably working radios are out there, but SiLabs specs 3.8V as absolute max I2C input. Have I missed a memo?

Jim, N5IB









MAc B
 

OK. But what to do IF I have other (additional) I2C device working at 5V?

MAc


Jerry Gaffke
 

Without a thorough analysis and a lot of spare time, best bet might be to give Lady Ada $4 for an i2c level converter.
    https://www.adafruit.com/product/757

Or read the NXP/Philips app notes under Technical Details on that webpage.
Using that info and the Mouser website, you could do it for about $0.25 plus $10 shipping.

Jerry, KE7ER


On Thu, Dec 28, 2017 at 04:57 pm, MAc B wrote:

OK. But what to do IF I have other (additional) I2C device working at 5V?

 


Michael Hagen
 

I have 2 stand alone clock boards.

The simple one has the standard SI5153, which has the one I2C address.

The second one is called "Lotsa Clocks" and has the 20 pin SI part aboard.

Both have the proper level SHIFTING to 3.3V.  Both have the 3.3V Regulator on board.

There are bare PCBs available.  And some built.

Vince got the last Lotsa Clocks today.  So I have to build more.

All run off of a 4 Pin Molex I2C and have outputs on Molex.  Basic has 3 Clocks and Lotsa Clocks has 8 Clocks on 2 8Pin Molex.

Room for Ground for Coax for each of the 8 Clocks.

The 20 Pin part has Jumper Options on board, one for I2C Address and the other Spread spectrum selection.

It can be run with an Raduino with a SI part running at address 0x60.

If interested I can send info on  these PCBs.

73'S

Mike, WA6ISP

MOTDOG@...
































On 12/28/2017 5:32 PM, Jerry Gaffke via Groups.Io wrote:
Without a thorough analysis and a lot of spare time, best bet might be to give Lady Ada $4 for an i2c level converter.
    https://www.adafruit.com/product/757

Or read the NXP/Philips app notes under Technical Details on that webpage.
Using that info and the Mouser website, you could do it for about $0.25 plus $10 shipping.

Jerry, KE7ER

On Thu, Dec 28, 2017 at 04:57 pm, MAc B wrote:

OK. But what to do IF I have other (additional) I2C device working at 5V?

 


-- 
Mike Hagen, WA6ISP
10917 Bryant Street
Yucaipa, Ca. 92399
(909) 918-0058
PayPal ID  "MotDog@..."
Mike@...


Smitty, KR6ZY
 

This gave me a good chuckle...  :-)

On 12/28/2017 05:32 PM, Jerry Gaffke via Groups.Io wrote:
you could do it for about $0.25 plus $10 shipping


MAc B
 

So - IF I have two (or more) I2C devices working with different levels, then one of them must be used with level shifter. It is clear.

The question is - "which strategy is better"

A.\  use 3.3V device (eg SI5351) without shifter (like Raduino) and other device (5V) shift to 3.3 and then connect to raduino (exactly "to I2C pins of si5351")

OR

B.\ cut traces to si5351 at Raduino, insert level shifter, shift SI to 5V and then use OTHER device(5V) without shifting. (connecting to 5v I2C pins of arduino)

MAc
mrn


Rod Davis
 

Hi All,

I have done over 6 projects with Arduino/I2C adapter/1602 display.
I remove the I2C pullups from the ebay PCF8574 I2C adapter assembly, and let the
pullups to 3.3v (located somewhere else, like near the SI570)
do the work. The PCF8574 easily copies the 3.3V I2C
signals, as they rise above the approx 2.5v threshold for a 0-1 transition.

In general, 5V devices will easily copy the 3.3V logic-one level, because it is higher than the 2.5V threshold.

Therefore, in a mixed system with 5V and 3.3V devices, I suggest pulling the I2C bus up to 3.3V,
and do not use level shifters.

Works like a charm.

Rod KM6SN

I bought a 4x20 display that's I2C and was really surprised that what they
used to convert the parallel to I2C was a PCF8574, an 8 bit i/o expander. 
I use the PCF8575, the 16 bit version, when I need more DIO pins.

Vince.

On 12/29/2017 03:30 AM, MAc B wrote:

So - IF I have two (or more) I2C devices working with different levels, then one of them must be used with level shifter. It is clear.

The question is - "which strategy is better"

A.\  use 3.3V device (eg SI5351) without shifter (like Raduino) and other device (5V) shift to 3.3 and then connect to raduino (exactly "to I2C pins of si5351")

OR

B.\ cut traces to si5351 at Raduino, insert level shifter, shift SI to 5V and then use OTHER device(5V) without shifting. (connecting to 5v I2C pins of arduino)

MAc
mrn



Jim, N5IB
 

A bit more digging into the datasheets for the ATMEGA328 and the Si5351a...

The I2C bus SCL and SDA pins of the NANO (A5 and A4) are part of the ATMEGA's "Port C" general purpose I/O. When used as a digital pin there are four states possible, selected by appropriately setting/clearing bits in the port's control registers:
input without pullup
input with pullup (between 20K and 50K to Vcc)
active low, capable of sinking tens of mA
active high. capable of sourcing tens of mA

As others have commented, the NANO as a data receiver can properly interpret a 3.3V signal as a logic level "1" since it exceeds the roughly 2.6V threshold for 5V operation. You give away some speed capability and noise margin, but certainly OK for these applications.

The NANO actively driving the bus low to assert a logic "0" is no problem.

But the grey area is the assertion of the logic "1" state by the NANO.
The handling of the bits is done by the "WIRE" library routines that are called by the 5351a routines.
I'm not a clever enough software guy to ferret out how the code does this at the hardware/bit level.

If the logic one state is asserted by putting the pin into "input, no pullup" mode, then all is well, as the external 2.2K pullups do their job.

Even if the pin is placed in the "input, with pullup" mode we're OK, since the resistive voltage division between the 2.2K external pullup to 3.3V and the internal 20-50K pullup to 5V will leave the pin somewhere between about 3.4 and 3.5 V, safe enough for hams if not for actual "government work" :^))

But if the pin is in "output, high" mode then it actively dives the bus towards 5V with a low impedance source, swamping the 2.2K pullup to 3.3V and carrying the bus very nearly to the 5V Vcc level; bringing, if data sheets are to be believed, death to the 5351a.

Now there are lots of perfectly functioning radios out there - so death seems not an option. I guess it's in the hands of the software gurus to resolve the question. And to us hardware guys to put a 'scope on the SCL line while the NANO is talking - will do that when my eagerly awaited uBITX arrives (I hope) sometime next month.

73,
Jim, N5IB
<http://n5ib.net/Index.xht>


Jerry Gaffke
 

I'm with Rod, should be sufficient to remove any pullups to 5v on new i2c devices and thus keep the i2c bus at 3.3v.
    https://groups.io/g/BITX20/message/37634

If 10k pullups to 5v are left in place, probably not the end of the world.
Will be around 150uA through the Si5351 protection diodes to the  3.3v rail, but nothing will spark and smoke. 

The Raduino does not drive the i2c wires to 5v, it either shorts to ground or releases it to allow the pullup resistor to take it high.
Driving the i2c lines high to 5v with some rogue sketch could be a bad thing for the 3.3v Si5351.
If that really bugs you, then talk to Mike (post 37613) or Lady Ada (post 37612).
Or replace the Nano with a modern 3.3v processor and keep all i2c peripherals at 3.3v.

Jerry, KE7ER


On Fri, Dec 29, 2017 at 06:14 am, n5ib_2 wrote:
But if the pin is in "output, high" mode then it actively dives the bus towards 5V with a low impedance source, swamping the 2.2K pullup to 3.3V and carrying the bus very nearly to the 5V Vcc level; bringing, if data sheets are to be believed, death to the 5351a.


MAc B
 

I2C is not a "normal" port. (good for us) ;-)

Two quotes from forum:

"I see, so that's what "When the TWEN is set to enable the Two-wire Serial Interface, pin PC1 is disconnected from the port" meant on the datasheet."

 

"Both pins (SDA, SLC) are bidirectional, so both must be configured always as output. They are used from the HW-I2C as open drain outputs, thus also two external pullups are needed."

The key is "open drain" (like open collector). ". Both SCL and SDA lines are "open drain" drivers. What this means is that the chip can drive its output low, but it cannot drive it high."

http://www.robot-electronics.co.uk/i2c-tutorial

 

Best 73

MAc

mrn


Jim, N5IB
 

Ah ha !!
TWEN... that's the info I was looking for... Thanks for the heads up.
Now I can sleep at night again - and put the scope probes away :^))

Jim, N5IB

From the ATMEGA328datasheet:

• SCL/ADC5/PCINT13 – Port C, Bit 5
SCL, 2-wire Serial Interface Clock:
When the TWEN bit in TWCR is set (one) to enable the 2-wire Serial Interface, pin PC5 is disconnected from the port and
becomes the Serial Clock I/O pin for the 2-wire Serial Interface. In this mode, there is a spike filter on the pin to suppress spikes shorter than 50 ns on the input signal, and the pin is driven by an open drain driver with slew-rate limitation.

• SDA/ADC4/PCINT12 –
Port C, Bit 4
SDA, 2-wire Serial Interface Data: When the TWEN bit in TWCR is set (one) to enable the 2-wire Serial Interface, pin PC4 is disconnected from the port and becomes the Serial Data I/O pin for the 2-wire Serial Interface. In this mode, there is a spike filter on the pin to suppress spikes shorter than 50 ns on the input signal, and the pin is driven by an open drain driver with slew-rate limitation


Dale Frye
 

I agree with the other posts on this thread that level shifters are not needed. Pulling up the lines to 3.3v will work fine with 5v level signals since it crosses the upper (On) threshold.

I do want to clear up a few things.

1: The data signal is bidirectional but the clock is always provided by the master. In single master mode (most commonly used) this signal is technically unidirectional. (That's one nit picked!)

2: The exact value used for the terminating (pull-up) resistors is not critical but remember that the lower resistance value from multiple resistors on the line means that the devices have to sink more current. This could cause issues with either the pin on the device eventually burning out or the signal not being pull low enough. The total resistance should be somewhere in the area of about 10K +/- 50%. I recommend to try to get as close to 10K as you reasonable can. If you want something different then read the spec sheets to see how much current these pins can sink. Too much resistance will cause the edge of the signal to round or ramp up instead of sharply rising. Too little resistance can cause the signal edge to ring. If this become severe it can cause issues. There are filters on the devices to deal with these issues but they can only do so much. The signal edges of the clock are most important. The data signal needs to be stable at the time it is sampled starting on the rising edge of the clock and continued stable until the falling edge of the clock. See spec sheets for more info.

3: If all the devices are in close proximity the placement of the resistors are not critical. However as the lines get longer or many devices are placed on the I2C bus the resistor placement can become critical. On a single master system the master should be at one end of the bus and the terminating resistors at the other end. In a multi master system there should be terminating resistors on each end of the bus. Resistors in the middle of the bus can potentially cause weirdness on the signal edges due to reflection. If you are using a lot of devices or long lines then you should scope the lines to see the signal edges to determine how much resistance should be used.  Do also pay attention to the voltage supply line to the resistors. Some resistance or noise in this line can cause issues.

4: It is possible to have multiple masters on the bus but it is more complicated. The driver software needs to support this mode. Most drivers do not support it.

5: Many of the arduino drivers do support both master and slave modes. I have used the slave mode when I needed a second processor to deal with a cpu intensive sensor so that the master could handle everything else.

6: TWI (Two-Wire Interface) is just another name for I2C. Sometimes other similar names with references to "Two Wire" are used. To add to the confusion there are similar standards that may or may not be compatible. For example, the CAN bus often used in cars is similar and sometimes devices for one bus may (or may not) work on the other. YMMV

My comments may make I2C sound hard but it really isn't. I usually just slap a few I2C devices on a controller and go with it. Only if you start pushing things do you need to worry about all the details. Main thing is to just make sure the resistors are connected to the correct voltage and there should only be one (or maybe two) per line. Do note that many of the little I2C modules you find often have the resistors (SMD) attached. You may need to remove them as needed. A few boards have jumpers (closely spaced solder pads) that allow you to enable/disable these resistors.

One more thing that I see people getting flustered with I2C. I2C addresses can be confusing. There are several different ways to specify an I2C address. First, most people use hex numbers but sometimes someone will use decimal. A more confounding problem is due to the way the address is passed on the bus. Technically the address is 8 bits with all the odd addresses are read and even addresses are writes. (Confused already?) Chip manufacturers like to list the address write/read pairs. Software, however, likes to specify just the top 7 bits and then shift 1 bit left.  The 0 bit is then treated as a write/read flag. See example below:

Given the following 8 address bits
10100010
Hex = A2 write address, 10100011 (A3) is the matching read address
Decimal = 162 write address, 163 read address
Adjusted = 1010001 = Hex 51, Decimal 81 for both read and write.

See how the adjusted binary is just the upper 7 bits so the 8 bit format is 1010001X where X is 0 for read and 1 for write.

Oops, I think I may have just hijacked this thread. Once I get started it's hard to stop.

Dale
KJ4C


Dave Bottom <ars.kd6az@...>
 

Nice tutorial!  Worth putting in the library.  Thanks
Dave WI6R

On Fri, Dec 29, 2017 at 4:15 PM, Dale Frye <frye.dale@...> wrote:
I agree with the other posts on this thread that level shifters are not needed. Pulling up the lines to 3.3v will work fine with 5v level signals since it crosses the upper (On) threshold.

I do want to clear up a few things.

1: The data signal is bidirectional but the clock is always provided by the master. In single master mode (most commonly used) this signal is technically unidirectional. (That's one nit picked!)

2: The exact value used for the terminating (pull-up) resistors is not critical but remember that the lower resistance value from multiple resistors on the line means that the devices have to sink more current. This could cause issues with either the pin on the device eventually burning out or the signal not being pull low enough. The total resistance should be somewhere in the area of about 10K +/- 50%. I recommend to try to get as close to 10K as you reasonable can. If you want something different then read the spec sheets to see how much current these pins can sink. Too much resistance will cause the edge of the signal to round or ramp up instead of sharply rising. Too little resistance can cause the signal edge to ring. If this become severe it can cause issues. There are filters on the devices to deal with these issues but they can only do so much. The signal edges of the clock are most important. The data signal needs to be stable at the time it is sampled starting on the rising edge of the clock and continued stable until the falling edge of the clock. See spec sheets for more info.

3: If all the devices are in close proximity the placement of the resistors are not critical. However as the lines get longer or many devices are placed on the I2C bus the resistor placement can become critical. On a single master system the master should be at one end of the bus and the terminating resistors at the other end. In a multi master system there should be terminating resistors on each end of the bus. Resistors in the middle of the bus can potentially cause weirdness on the signal edges due to reflection. If you are using a lot of devices or long lines then you should scope the lines to see the signal edges to determine how much resistance should be used.  Do also pay attention to the voltage supply line to the resistors. Some resistance or noise in this line can cause issues.

4: It is possible to have multiple masters on the bus but it is more complicated. The driver software needs to support this mode. Most drivers do not support it.

5: Many of the arduino drivers do support both master and slave modes. I have used the slave mode when I needed a second processor to deal with a cpu intensive sensor so that the master could handle everything else.

6: TWI (Two-Wire Interface) is just another name for I2C. Sometimes other similar names with references to "Two Wire" are used. To add to the confusion there are similar standards that may or may not be compatible. For example, the CAN bus often used in cars is similar and sometimes devices for one bus may (or may not) work on the other. YMMV

My comments may make I2C sound hard but it really isn't. I usually just slap a few I2C devices on a controller and go with it. Only if you start pushing things do you need to worry about all the details. Main thing is to just make sure the resistors are connected to the correct voltage and there should only be one (or maybe two) per line. Do note that many of the little I2C modules you find often have the resistors (SMD) attached. You may need to remove them as needed. A few boards have jumpers (closely spaced solder pads) that allow you to enable/disable these resistors.

One more thing that I see people getting flustered with I2C. I2C addresses can be confusing. There are several different ways to specify an I2C address. First, most people use hex numbers but sometimes someone will use decimal. A more confounding problem is due to the way the address is passed on the bus. Technically the address is 8 bits with all the odd addresses are read and even addresses are writes. (Confused already?) Chip manufacturers like to list the address write/read pairs. Software, however, likes to specify just the top 7 bits and then shift 1 bit left.  The 0 bit is then treated as a write/read flag. See example below:

Given the following 8 address bits
10100010
Hex = A2 write address, 10100011 (A3) is the matching read address
Decimal = 162 write address, 163 read address
Adjusted = 1010001 = Hex 51, Decimal 81 for both read and write.

See how the adjusted binary is just the upper 7 bits so the 8 bit format is 1010001X where X is 0 for read and 1 for write.

Oops, I think I may have just hijacked this thread. Once I get started it's hard to stop.

Dale
KJ4C




--
73 Dave WI6R


MAc B
 

From the History:

I2C is a Philips patent and there was legal prroblem - so other companies started using name TWI. Generally it is identical protocol, but I've found information, that some functions (eg clock stretching) could be not supported in TWI.

But it does not matter in our case, and we cas use that names interchangebly.

 

MAc/mrn