Author Topic: MCP2221 and Arduino questions  (Read 6944 times)

0 Members and 1 Guest are viewing this topic.

Offline Red SquirrelTopic starter

  • Super Contributor
  • ***
  • Posts: 2750
  • Country: ca
MCP2221 and Arduino questions
« on: June 25, 2016, 07:07:48 am »
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.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: MCP2221 and Arduino questions
« Reply #1 on: June 25, 2016, 08:30:21 am »
Quote
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.
The arduino talks standard straight two-wire "async serial."  No protocol involved, just use typical UART settings.

Quote
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.
For the usual 28pin AVRs, the uart is on pins 2 and 3...  (pin 1 is RESET.)

Quote
should they be reversed?  Ex: should the TX pin of the Atmega go to the RX pin of the chip?
yes, probably.  Read the documentation carefully to see if TX means "TX" or "pin that is connected to TX."  (sigh.)
 

Online JPortici

  • Super Contributor
  • ***
  • Posts: 3461
  • Country: it
Re: MCP2221 and Arduino questions
« Reply #2 on: June 25, 2016, 09:14:49 am »
yes, probably.  Read the documentation carefully to see if TX means "TX" or "pin that is connected to TX."  (sigh.)
Ah yes, the endless debate :palm: i 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.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: MCP2221 and Arduino questions
« Reply #3 on: June 25, 2016, 04:56:54 pm »
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 'output

The 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.
 

Offline Red SquirrelTopic starter

  • Super Contributor
  • ***
  • Posts: 2750
  • Country: ca
Re: MCP2221 and Arduino questions
« Reply #4 on: June 25, 2016, 08:32:26 pm »
  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. 
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: MCP2221 and Arduino questions
« Reply #5 on: June 25, 2016, 08:53:00 pm »
  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).

You 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.

Quote

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.


I don't know anything about USB 3.x, as far as I am concerned USB power is 5V and current limited.

Quote


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.


Inadvertently 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.
 

Offline Red SquirrelTopic starter

  • Super Contributor
  • ***
  • Posts: 2750
  • Country: ca
Re: MCP2221 and Arduino questions
« Reply #6 on: June 25, 2016, 10:52:39 pm »
  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).

You 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.


That'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.
« Last Edit: June 25, 2016, 11:57:03 pm by Red Squirrel »
 

Offline Red SquirrelTopic starter

  • Super Contributor
  • ***
  • Posts: 2750
  • Country: ca
Re: MCP2221 and Arduino questions
« Reply #7 on: June 26, 2016, 01:11:48 am »
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. 
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: MCP2221 and Arduino questions
« Reply #8 on: June 26, 2016, 03:03:50 am »

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.

Look 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...
 

Offline Red SquirrelTopic starter

  • Super Contributor
  • ***
  • Posts: 2750
  • Country: ca
Re: MCP2221 and Arduino questions
« Reply #9 on: June 26, 2016, 04:00:48 am »
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: [Select]
falcon ~ # picocom /dev/ttyACM0
picocom v1.7

port is        : /dev/ttyACM0
flowcontrol    : none
baudrate is    : 9600
parity is      : none
databits are   : 8
escape is      : C-a
local echo is  : no
noinit is      : no
noreset is     : no
nolock is      : no
send_cmd is    : sz -vv
receive_cmd is : rz -vv
imap is        :
omap is        :
emap is        : crcrlf,delbs,

Terminal ready

Unknown 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[/url]
-------------------------------------------------------------------------------
help             Show this screen

# test
Unknown command: "test", type help for list of valid commands
# a
Unknown command: "a", type help for list of valid commands
# b
Unknown command: "b", type help for list of valid commands
#
Thanks for using picocom
falcon ~ #
 

Offline newbrain

  • Super Contributor
  • ***
  • Posts: 1719
  • Country: se
Re: MCP2221 and Arduino questions
« Reply #10 on: June 26, 2016, 07:24:10 am »
  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).

You 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.


That'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.
If 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.
Nandemo wa shiranai wa yo, shitteru koto dake.
 

Offline Red SquirrelTopic starter

  • Super Contributor
  • ***
  • Posts: 2750
  • Country: ca
Re: MCP2221 and Arduino questions
« Reply #11 on: June 26, 2016, 10:06:13 pm »
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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf