MCP2221 and Arduino questions - Page 1
Forum section: electronics / general

author: Red Squirrel
author_rank: Super Contributor
timestamp: June 25, 2016, 07:07:48 am
content: For background, the MCP2221 is a USB to serial chip so it creates a virtual serial port on the computer, and then I can talk serial using the MCU. I am working on a project that uses an Atmega chip directly but using the Arduino libraries, as it's just easier to find tutorials and code samples for, than straight Atmel. That part works, ex: I have it writing stuff to an LCD and was able to measure pwm on pins etc.I ran into an oddball issue in that when I connect USB only, it seems to pass 3.8v to the rest of the circuit, I did not figure it would even power the micro, and just the USB side of the chip. Only thing I can think of is maybe there is an internal diode or something to prevent backfeeding 5v into the USB through the chip. Now I am scared to also apply 5v to the rest of the circuit as it might backfeed into whatever is generating the 3.8v if it's not a diode and fry something. Interestingly, it is enough to power the arduino, and the little LCD that is part of the project, just more feint.My second question, and it MIGHT be related to lack of voltage, but I'm not sure, is where can I find a good tutorial on how to talk to the MCP2221 with the atmel chip? I tried using the regular Arduino serial commands, but I imagine those are designed for whatever chip the arduino uses, and not for that chip, so unless the protocol they use is standard, it of course won't work. Problem is I can't really find any info on how to talk to the chip so that I can code for it. Any idea where I'd find that?The TX and RX pins of the MCP2221 are connected to the pin 1 and pin 2 of the MCU, which arduino uses for RX and TX. Also, stupid question but should they be reversed? Ex: should the TX pin of the Atmega go to the RX pin of the chip? I'm not sure if they mean "TX in" or "TX out" so that would make a difference.

author: westfw
author_rank: Super Contributor
timestamp: June 25, 2016, 08:30:21 am
content: QuoteThe arduino talks standard straight two-wire "async serial." No protocol involved, just use typical UART settings.QuoteFor the usual 28pin AVRs, the uart is on pins 2 and 3... (pin 1 is RESET.)Quoteyes, probably. Read the documentation carefully to see if TX means "TX" or "pin that is connected to TX." (sigh.)

author: JPortici
author_rank: Super Contributor
timestamp: June 25, 2016, 09:14:49 am
content: Quote from: westfw on June 25, 2016, 08:30:21 amAh yes, the endless debatei also like the fact that usb type A has three sides: the fist time you put it in it doesn't go. you flip it, it doesn't go. you flip it again, it goes.

author: rstofer
author_rank: Super Contributor
timestamp: June 25, 2016, 04:56:54 pm
content: The Arduino library for serial IO just wiggles a pin for output and accepts wiggles on the other. Usually, it is best to use pins connected to a real UART. That's all there is to know as it pertains to the Arduino. You do need to chase down the relationship between TX and RX because that is a mess. Read the datasheets carefully and key in on words like 'input' and 'outputThe MCP2221 datasheet is clear that RX is an input and TX is an output. Now just match it up with the Atmel datasheet.Section 1.6.2.1 details the power configuration for the chip. Like the FTDI chip, it provides 3.3V output to power a uC. Sometimes that is desireable, other times not so much. Read the section and pick your configuration. Basically, the USB port powers the chip. If you don't connect the 3.3V pin, the chip won't power the uC.

author: Red Squirrel
author_rank: Super Contributor
timestamp: June 25, 2016, 08:32:26 pm
content: Can I just omit the power pin on the USB side to avoid this, and will the chip still work by being powered off VDD? I would still connect the USB ground to ensure everything is at the same potential (ex: the communication signal).Basically, I don't want to blow up my computer when the board has +5v applied to it and I plug in the USB. I wonder if the chip is actually negotiating the USB to only supply 3.3v instead. I think that is part of the USB 3.x spec that you can do that. Normally USB is 5v though.As for the rx/rx I meant pin 2 and 3 and not 1 and 2. I will try to reverse them to see what happens.

author: rstofer
author_rank: Super Contributor
timestamp: June 25, 2016, 08:53:00 pm
content: Quote from: Red Squirrel on June 25, 2016, 08:32:26 pmYou can design the system such that power is never taken from the USB cable. See figure 1.5 in the datasheet and notice that the 3.3V source for the device can come from either the USB port or the local system. The thing is, I don't know if you are using a 3.3V uC or not. If you have a 5V uC, use figure 1.4. Figure 1.3 uses USB power. I would encourage you to read the datasheet and follow the yellow brick road.QuoteI don't know anything about USB 3.x, as far as I am concerned USB power is 5V and current limited.QuoteInadvertently connecting two outputs together is seldom successful. Especially if one of them changes. If you want to guess at a configuration, put a 330 Ohm resistor in series with each line. A better strategy is to read the datasheet for the uC because I already gave you the polarity of the MCP2221 pins (but read the datasheet to make sure I got it right, I am getting old and my eyesight isn't what it used to be).BTW. there is every reason to leave the 330 Ohm resistors in series with any signal that goes off board. It will limit the current during a short circuit but, in normal operation, the resistor won't have much of a voltage drop because CMOS parts have very high input impedance.

author: Red Squirrel
author_rank: Super Contributor
timestamp: June 25, 2016, 10:52:39 pm
content: Quote from: rstofer on June 25, 2016, 08:53:00 pmThat's actually how it's setup, I was hoping the USB would not power up anything else on the board, but it seems there is some kind of pass through power. From reading the datasheet it seems there is an internal 3.3v psu used for usb communication, but I really don't know why it would be supplying power out of the VDD too. I don't see any caution note about having the USB and circuit power present at same time though, so I THINK it might be safe, but if the 3.8v I'm getting actually ends up being enough to power the micro, then I may not even need to worry. Under normal conditions the USB won't be connected to anything, it's just there for diagnostic/calibration.Also they show a 3.3v LDO, guessing that means a regulator? I'm actually feeding 5 directly to VDD, is that not correct? It did not blow when I was powering that side of the circuit though... Could have sworn I read elsewhere it took 5v. Right now I have 5v going into VDD, and USB power going into VUSB, but they are not connected. Only the grounds are.

author: Red Squirrel
author_rank: Super Contributor
timestamp: June 26, 2016, 01:11:48 am
content: Ok so to fix the USB weird voltage issue I just opted to not connect VUSB, and it seems to work fine. I connect 5v to the main circuit, and since it's connected to VDD, it will power the USB side of the chip too. The 3.8v (3.3 nominal?) I was getting with it connected to USB made me a little scared to plug in the main 5v, but now I don't get that.I swapped the tx/rx and now I get some junk data in the terminal, but that is probably my code, so I'll play around with it.

author: rstofer
author_rank: Super Contributor
timestamp: June 26, 2016, 03:03:50 am
content: Quote from: Red Squirrel on June 26, 2016, 01:11:48 amLook for a baud rate mismatch usually caused by assuming the wrong frequency for the baud rate divider. At least that's been my painful experience...

author: Red Squirrel
author_rank: Super Contributor
timestamp: June 26, 2016, 04:00:48 am
content: I may have gotten it to work, but there is this weird thing where it sometimes locks up, (not the whole MCU, just the serial comm) and I can't type anything, but I got basic I/O working now. I think it may also be Picocom doing weird stuff, because it's also sending AT commands like if it was a modem.I'm just glad it's this easy, I figured there would be more to it, and that there was still some kind of protocol I had to use to speak "UART" but guess that's a standard so all those chips will use it.Some output from a super basic application:Code:falcon ~ # picocom /dev/ttyACM0picocom v1.7port is : /dev/ttyACM0flowcontrol : nonebaudrate is : 9600parity is : nonedatabits are : 8escape is : C-alocal echo is : nonoinit is : nonoreset is : nonolock is : nosend_cmd is : sz -vvreceive_cmd is : rz -vvimap is :omap is :emap is : crcrlf,delbs,Terminal readyUnknown command: "AT", type help for list of valid commands# help-------------------------------------------------------------------------------Solar Power System [updated June 25 2016] - [url=http://www.iceteks.com]www.iceteks.com-------------------------------------------------------------------------------help Show this screen# testUnknown command: "test", type help for list of valid commands# aUnknown command: "a", type help for list of valid commands# bUnknown command: "b", type help for list of valid commands#Thanks for using picocomfalcon ~ #

author: newbrain
author_rank: Super Contributor
timestamp: June 26, 2016, 07:24:10 am
content: Quote from: Red Squirrel on June 25, 2016, 10:52:39 pmIf by "USB power" you mean the +5V coming from the USB port (red wire), you definitely do not want to connect it to VUSB.VUSB is a 3.3 output, internally connected to the USB line drivers (that work at 3.3V) see figure 1-2 on page 16, forcing it to 5V might damage the chip or, worse, the PC USB port.The fact that you saw a phantom supply of 3.8V is probably due to this:So nothing to really worry about, you can power the MCP2221 from USB and teh rest from another supply.Just make sure to power your circuit before connecting it to USB port.

author: Red Squirrel
author_rank: Super Contributor
timestamp: June 26, 2016, 10:06:13 pm
content: Yeah I had it connected to VUSB originally, honestly not sure why I did, as the intention was that the system had it's own source of power, and not be powered by USB.But now it seems I have it all working now. I'm even thinking I should omit the +5v for the ISP connector too. But at least that's 5v, so it's really just "bridging" the main 5v bus. I imagine in a more professional/commercial setup you'd probably have some form of isolation, but not really needed for my application.