Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: USB P-FET incorrectly wired? on: November 12, 2010, 12:46:44 am
Quote
This scheme, for example, could not be used to switch 12V like this

To which "this" are you referring to? And, if you don't mind, I'm curious to understand why it cannot be used to switch 12V like you say.

Well, dang. I've actually already prototyped a board with the source and drain switched (my test circuit showed it to be correct, which I now see the flaw). So given my test board, I'm trying to predict what is going to happen if VIN is powered and the USB is plugged in.  I assume it is not desirable if there is a potential difference which allows current to run backwards into my laptop through the +5V line.  I just don't know if that will damage my usb ports or if it will be ok. The +5V output from the converter will most certainly be ~5V maybe slightly less (4.95). My converter is a buck converter so inrush on the output shouldn't be an issue because of the inductor (AFAIK). So I assume that as long as the USB +5V > than the converter +5V output then the potential difference will keep the current from flowing back into my laptop. Inevitably the current will flow back up so I'd like to know what to expect. Do you know if this will damage the usb port?
2  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: USB P-FET incorrectly wired? on: November 11, 2010, 06:29:55 pm
Ahh, I'd forgot about the diode from drain to source.  My test circuit didn't have that.  It just had a raw P-FET.

But wouldn't the reverse work too? Connecting the USBVCC to source and +5V to drain.  The comparator will still turn the transistor on and off based on a voltage at VIN. If the USB is connected and there is no voltage on VIN then the gate will be low which will cause the transistor to turn on.  If there is a voltage at VIN then the gate will be high which would turn off the transistor if USBVCC is +5V.

If reversing the wires on source and drain will still work, what are the advantages of one way or the other? Why did they choose the current setup?

I'm still learning this stuff so please correct me if I'm wrong.
3  Forum 2005-2010 (read only) / Bugs & Suggestions / USB P-FET incorrectly wired? on: November 11, 2010, 05:21:55 pm
I was looking at the schematics of how the power is automatically switched when using an external battery while connected to the USB.  From what I can tell the system is supposed to pinch off the +5V from the USB when the VIN is powered.  But doing some probing I find that it is not what happens. The schematic shows that the p-channel fet to do this switching is wired up backwards.  The USBVCC should be connected to the source and the +5V should be connected to the drain.

This post http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1278665496
also mentions this problem but the bug was never confirmed. It's hard to believe that it is a bug because so many arduino boards have this system. But using a single p-fet and some experimenting clearly show the current system is incorrect.

Can someone else please verify this so it can be corrected for the next version of the arduino board?
4  Forum 2005-2010 (read only) / Interfacing / Re: Arduino as slave only receiving 1st and last byte on: December 28, 2010, 10:16:33 pm
Ok, this may sound stupid, but it appears all my troubles were caused by the time it takes to call Serial.println(), which from my testing shows ~3 ms.  So what was happening was that the master was transmitting all the data, but the slave was catching only bits and pieces whenever it wasn't executing the Serial.println function.
5  Forum 2005-2010 (read only) / Interfacing / Re: Arduino as slave only receiving 1st and last byte on: December 28, 2010, 09:55:58 pm
I'm still having issues, but here's an update. I found that if I send a large amount of data, say 200 bytes each one incrementing, then the slave will receive some bytes in between the first and last.  But only a few of them. They are always the same given the same input set. No obvious pattern.

Currently this code works:
Code:
void lopp(){
      spi_select_slave( 10 );
      for( int i=0; i<10; ++i )
      {
            spi_write_byte( i );
            delay( 3 );
      }
      spi_deselect_slave( 10 );
      delay( 2000 );
}

If I make the delay inside the loop to anything smaller than 3 then i start loosing numbers.  This is true regardless of how fast I configure the SPI clock speed. I must be missing something stupid somewhere.
6  Forum 2005-2010 (read only) / Interfacing / Arduino as slave only receiving 1st and last byte on: December 28, 2010, 08:42:22 pm
I have one Atmega328 as a master and another 328 configured as slave.  I basically have the following code:

Code:
// Master
void loop(){
      spi_select_slave( 10 );
      spi_write_byte( 1 );
      spi_write_byte( 2 );
      spi_write_byte( 3 );
      spi_write_byte( 4 );
      spi_write_byte( 5 );
      spi_deselect_slave( 10 );
      delay( 5000 );
}

// Slave
void loop(){
    unsigned char receivedByte = spi_read_byte();
    Serial.println( receivedByte, DEC );
}


The weird thing is I only get the first and last byte, like so:

Code:
1
5
1
5
1
5
...

If I understand the datasheet correctly, the 328 shouldn't need to do a /SS & SS for each byte.  And I'm certain the spi functions are behaving correctly. The spi functions work great for communicating with a SC16IS740 in slave mode.

Is this normal behavior for an Atmega 328 configured in slave mode?
7  Forum 2005-2010 (read only) / Interfacing / Re: External power with usb data+/- on: October 22, 2010, 09:49:12 pm
I've been studying the reference designs on the hardware page to see how they handle simultaneous input from VIN and USB.  Looks like they shut off the USB 5V whenever VIN > 3.0 V.  Using my Duemilanove I tested if Serial.print would still transmit on the USB data +/- with the USB +5V disconnected and everything still seems to work ok. I'll verify when I get the board made, but it looks like my original plan is safe.

Btw, I tested this with my laptop plugged in to the wall using a 12V external power source to VIN.
8  Forum 2005-2010 (read only) / Interfacing / External power with usb data+/- on: October 22, 2010, 01:17:13 pm
I am building my own Arduino board for use in a custom project for my car.  The question I have relates to using a power supply for the microcontroller (a Atmega328) while simultaneously outputing signals on the USB Data+/- lines to a laptop.

Here are the devices for this problem: Atmega328, FTDI chip, 12V ->5V Buck converter, laptop computer.

I will use this board in two types of scenarios.

Scenario A (Initial setup and configuration/validation): Connect the USB from the laptop to the USB on the board, draw power from the USB +5V pin.  Communicate to the Atmega328 through the serial->USB hardware (Serial.print(…)). In this setup the 5V buck converter is disconnected.

Scenario B (Debugging/reprogramming): Board is installed in my vehicle.  Draw power from onboard 5V buck converter (which is connecte to the car battery). Connect laptop USB  to board USB so I can transmit/receive Serial.print(…) messages or program. No power is needed from laptop USB, but USB Data+/- is needed.

Scenario A is easy, I know that will work.

But there are some concerns/unknowns for scenario B. My original plan (for scenario B) is to make USB GND the same as the GND on the 5V buck converter.  The Atmega382 and FTDI chip will still be powered by the 5V buck converter, but the USB +5V pin will be disconnected via jumper or slider. This means when the board is installed in the vehicle the USB GND will be the same as the car battery GND.  Will the FTDI be able to output signals to my laptop USB Data+/- with the USB +5V pin disconnected?

For scenario B my car battery, custom arduino board, and laptop battery all will share the same ground.  Will this cause problems?  What about if I decide to plugin my laptop to the wall? Now car battery ground is connected to ground in my home.  I worry about potential differences causing power to flow through my laptop causing my laptop to fry.

Has anyone tried this?
9  Forum 2005-2010 (read only) / Interfacing / Re: Can only send one SPI byte!? on: April 10, 2010, 07:38:02 pm
Wow, I guess that would do it. Yeah I switched the pins and it worked as expected.

This brings up another question.  Since the wifly shield expects pins 10-13 to be used for SPI, can I connect wires from my mega 50-52 to the shield 10-13 WHILE it is stacked onto my mega?  I guess I would need to invert the direction of pins 10-13 match the direction of pins 50-52.  This would essentially be shorting the pins 50-52 to pins 10-13 since stacking the shield will cause the shield pins to match the mega pins. Would this damage the arduino?
10  Forum 2005-2010 (read only) / Interfacing / Can only send one SPI byte!? on: April 10, 2010, 02:14:24 pm
I have an Arduino Mega and a wifly shield.  The wifly shield has a SPI->UART IC which is supposed to be the interface to the wifly.  Right now I'm just trying to get the SPI IC configured correctly.  I've copied the transparent terminal sketch from the "Talking wireless server tutorial".  When I run it the code hangs.

I striped everything down to a bare sketch so you can clearly see the problem:


Code:
char clr = 0;

#define SS   10
#define MOSI 11
#define MISO 12
#define SCLK 13

char spi_transfer( volatile char data )
{
  SPDR = data;
  while( !( SPSR & (1<<SPIF) ) );
  Serial.println( "Completed" );
  return SPDR;
}

void setup()
{
  pinMode( MISO, INPUT  );
  pinMode( MOSI, OUTPUT );
  pinMode( SS,   OUTPUT );
  pinMode( SCLK, OUTPUT );
  
  digitalWrite( SS, HIGH );
  
  SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR1) | (1<<SPR0);
  clr  = SPSR;
  clr  = SPDR;
  delay( 10 );
  
  Serial.begin( 9600 );
  Serial.println( "Initializing SPI..." );
  
  digitalWrite( SS, LOW );
  spi_transfer( 0x00 ); // Dummy data
  spi_transfer( 0x00 ); // Dummy data
  digitalWrite( SS, HIGH );
}

void loop()
{
}

When I run this I only see one "Completed" and the code hangs when trying to send the second byte. The second "Completed" never comes.

Here's a copy from the terminal:

Initializing SPI...
Completed


Is there a problem with my code? Do I have a bad Arduino or peripheral?

Can someone else run this simple code and see if they get the same results?
Pages: [1]