5 volts Atmega2560 SPI linking 3.3V sensor chip - Page 1
Forum section: electronics / projects

author: Wilson__
author_rank: Frequent Contributor
timestamp: August 25, 2024, 02:22:27 am
content: We need to link an Arduino Atmega 2560 5-volts board with 3.3 volts sensor chip over SPI. Would below work?Atmega3 output pins, MOSI, CLOCK and nChipSelect, will go through passive resistorvoltage divider, 2k ohms series and 3k ohms to ground. Should make 3 volts output from a high from ATMEGA.One sensor out pin to Atmega MISO, wired directly from sensor to Atmega. Datasheet says, logic high need 3 volts, seem a bit marginal. Will use low clock speed so signal has enough time to rise up (setup time)Many thanks

author: zapta
author_rank: Super Contributor
timestamp: August 25, 2024, 03:22:38 am
content: Also make sure that the transition time of the clock after the resistor network is not too long.Why not using a proper level converter, cost?

author: Nominal Animal
author_rank: Super Contributor
timestamp: August 25, 2024, 06:32:20 am
content: My solution would be aTI TXU0304, a proper voltage level translator. It costs 0.80€ in singles in TSSOP-14 at Mouser, USD $0.63 at JLCPCB for PCB assembly, and 0.61€ in singles at LCSC. For rock-solid operation, add two 0.1µF = 100nF bypass capacitors, one each between VCC and GND.These are so useful for exactly SPI voltage level translation at even very high clock frequencies (we're talking up to 200 MHz for 5V-3.3V translation), that I createda TXU0304 SPI break-out board(Public Domain). Its BOM refers to Samsung CL10B104KB8NNNC 100nF X7R capacitors in 0603, but any 100nF X7R or C0G or NP0 will do; also it specifies a more robust (automotive-rated) but also expensive TI TXU0304QPWRQ1 (TXU0304-Q1), while TI TXU0304PWR will work as-is.Essentially, you connect the TXU0304 between the MCU and the device: CS, SCLK, MOSI/DO, MISO/DI. The first three go from MCU and device (or rather, master to slave), and the last one from device to MCU. The GND is the same for both the MCU and the device, although I put one on either side on the board for convenience. Each side has also their own VCC, which determines the voltage level used for the signals. On the MCU side, OP would connect VCC to 5V, and on the device side, VCC to 3.3V. If they do not already have a 3.3V supply for the device, I would modify the board to add a 3.3V LDO regulator.I would personally adjust the design a bit, tying the enable bit directly to 5V, and add suitable mounting holes. If I knew the exact dev board, I might do a carrier board (that the dev board will sit on top of) with mounting holes. I've done this using the EasyEDA online PCB editor for a number of different dev boards, and can say that it is very easy to do for someone new to PCB design. Creating the schematic first helps, because then the PCB editor in EasyEDA can verify your design and tell you if you've forgotten any of the traces.I recommend against bidirectional level translators, because they tend to have a "glitch" in the low level voltage when they erroneously change direction. With 3.3V and lower logic level microcontrollers that have particularly low logic low threshold, this has caused quite a few issues. In OP's case the microcontroller uses 5V logic levels, so even bidirectional level translators will likely work fine. Personally, however, I like to keep a few TXU0304 in stock just for SPI voltage level translation.

author: Nominal Animal
author_rank: Super Contributor
timestamp: August 25, 2024, 09:05:39 am
content: In fact, I justcreated such a board at EasyEDA, using components available at JLCPCB, with BOM cost of USD $1.06 per board when manufactured and assembled at JLCPCB right now (2024-08-25). It is in Public Domain, so anyone can do whatever they want with it.Attached is a 3D image of the board. It is 1" × 1" = 25.4mm × 25.4mm, with 0.1" = 2.54mm mounting holes at the corners, with 0.8" = 20.32mm between centers. I obviously haven't tested the board itself, but it uses component values recommended in the respective datasheets, and similar designs have worked well for me thus far. Although the 3.3V regulator is rated for up to 1A of current, I haven't checked if it has sufficient cooling at maximum current. I do know that it should certainly work well for 100mA or less of current (because then, even without any kind of heatsink, the AP2114AH will heat up by under 30°C).The through holes are standard 0.1" spacing, 0.035" = 0.9mm diameter holes.

author: Wilson__
author_rank: Frequent Contributor
timestamp: August 25, 2024, 11:13:39 am
content: It is a quick once-off setup to run a piece of Arduino library code for debugging and test purposes. Using on-hands R.if works ok, then move to all 3v3 design.

author: Wilson__
author_rank: Frequent Contributor
timestamp: August 25, 2024, 11:23:20 am
content: Thanks for making the design. How we can get an assembled and (may be even tested) board? Order from JLCPCB? Or someone has made a batch and sell on Tindie or similar?

author: Wilson__
author_rank: Frequent Contributor
timestamp: August 25, 2024, 11:24:12 am
content: Thanks for making the design. How we can get an assembled and (may be even tested) board? Order from JLCPCB? Or someone has made a batch and sell on Tindie or similar?

author: Nominal Animal
author_rank: Super Contributor
timestamp: August 25, 2024, 04:11:39 pm
content: Quote from: Wilson__ on August 25, 2024, 11:24:12 amYep. I don't personally need a version with a 3.3V regulator on it. Arduino MEGA2560 Rev3 already has a 3.3V regulator on it, that can provide about 100mA of current; it's the fourth closest pin to the DC input barrel connector, between RESET and 5V.If you don't need the 3.3V regulator, then I'd use theno-regulator versionI just updated (top and bottom picture attached). This one is just 15.24mm × 15.24mm (0.6" × 0.6").First, register at JLCPCB, and log in. Then, open the project in EasyEDA (Open in Editorfrom theproject page), clickFileand thenGenerate PCB Fabrication File (Gerber). (It does not matter whether you check DRC or not, I've done it already and it passes.) Set PCB quantity to 5, pick whatever PCB color you want, and thenOne-click Order PCB/SMT, andOk. This opens a new window at JLCPCB PCB Prototype & PCB Fabrication, where you can change the settings if you want. At the bottom, enablePCB Assembly. Then, clickNext.At the top, clickBill of Materials. It may complain that J1 and J2 designators don't exist in the BOM file; that is because they are just the through-hole pads, so clickContinuehere. Because of the fee structure at JLCPCB, by default you'll have 10 extra Samsung 100nF X7R 50V capacitors in 0603 (CL10B104KB8NNNC) and 2 extra 3.3V Diodes Inc. LDO regulators (AP2114HA-3.3TRG1) if you used the project with the regulator. You can also buy other users'Idle partsinstead. Then, clickNext, andDo not Placeif it asks (since those J1 and J2 will not be populated). You should next see the board, with the TSSOP-14 TXU0304 in the center, with two small 0603 capacitors above it, and for the one with the 3.3V regulator, the SOT-223 LDO regulator above it with big 1210-sized capacitors on its left and right side. The components should show up in this view. (There is nothing but a ground plane on the bottom side of the board.) ClickNext. Note that in your cart, the PCB and its assembly will show up as separate items.For me, the total quote including shipping was just under 35€ including shipping for 5 boards with the regulator, just under 27€ for the non-regulator version, although I do have a couple of coupons giving me free shipping. Making a larger batch of boards would bring down the per-board price, because of the fixed assembly and component fees. The board without the regulator is easy to solder by hand (drag-solder the TSSOP-14 TXU0304PWR), so one could just order the plain boards (for < $10 for ten) and the components off LCSC, Mouser, or Digikey. (Mouser part numbers are187-CL10B104KB8NNNCand595-TXU0304PWRfor both boards, plus621-AP2114HA-3.3TRG1and81-GCM32ER71H475KA5Lfor the board with regulator, although I'd get187-CL32B475KBUYNWEinstead of 81-GCM32ER71H475KA5L.)

author: ArdWar
author_rank: Frequent Contributor
timestamp: August 25, 2024, 04:24:29 pm
content: If it's just for quick dirty proof of concept then your method *do* work. Keep in mind that some MCU may draw higher supply current when digital inputs aren't driven close to VDDIO, tho I'm not sure if that's the case with AVR. Been ages since I use them.However I'm not sure if it's wise to use such setup. The last thing I want during development is to debug problems unrelated to core design caused by janky devboard setup.

author: Wilson__
author_rank: Frequent Contributor
timestamp: August 25, 2024, 11:58:09 pm
content: Yes, very true. Best to stay with reliable and proper hardware setup. It was after some time working on 'proper' setup and still missing something (which must be my fault missed some thing, some where in those pages of datasheet)

author: Nominal Animal
author_rank: Super Contributor
timestamp: September 01, 2024, 03:46:26 am
content: I forgot to mention:I always keep someTI SN74LVC1T45DVBat hand, in SOT23-6 package. You can get ten for 6.45€ atMouser, 4.80€ at Digikey, 1.04€ at LCSC (part #C7843). They're about 0.11€ apiece at JLCPCB assembly, if you want to make your own boards with them; it's cheaper than using TI TXUn0m. Many other manufacturers do do the same part, with basically the same specifications. For JLCPCB assembly, they're all extended parts (so there is that fixed additional setup cost of a few dollars), but the cheapest ones right now are the Diodes 74LVC1T45W6-7 for 0.07€ apiece. Of course, these are easy enough to solder by hand, so I recommend getting the boards and the components separately, and soldering them yourself, if you want to minimize the costs.SN74LVC1T45 are one-signal one-directional voltage level translators, where one pin (DIR) selects the direction. Each side has its own VCC determining the signaling voltage level, between 1.65V and 5.5V. The input draws only a couple of microamps. The output can source or sink 24mA when VCC ≥ 3V, 36mA when VCC ≥ 4.5V. Between 3.3V and 5V signaling, it can do over 200 Mbits/s. There is no Schmitt trigger on the inputs, though. The input high threshold is between 0.65×VCC and 0.7×VCC, and input low threshold is between 0.35×VCC and 0.3×VCC.SOT23-6 (or SC-74) has six legs, three on a side, at 0.95mm (0.037") spacing. The epoxy body is under 3mm (0.120") long and under 2mm (0.78") wide. It isjustlarge enough to solder directly to wires. Connect DIR (pin 5) to GND (pin 2) –– center-to-center ––, then the signaling direction is B-to-A, and you connect signal source to B (pin 4), signal receiver to A (pin 3), source soltage level to VCCB (pin 6), and receiver voltage level to VCCA (pin 1), and common ground to GND (pin 2). I like to use a short piece of heatshrink tubing for each leg except GND and DIR, and a longer one over the whole thing after soldering, which helps keep the wires in place. (I recommend choosing the colors for the wires carefully, separate color for each wire, and writing them up somewhere. If you make more than one, use the same color scheme.) Make sure you always connect the ground wire first.These make for a very robust makeshift voltage level translators. 100nF supply bypass capacitors between each VCC and GND are recommended, but for makeshift translators –– for testing, breadboarding and such, before having a proper one –– and for low current draw like SPI, it isn't always necessary.