SOLVED - Standalone arduino. Can't get serial to work.

Hi experts!

I'm in trouble here, and I've used countless evenings to get it to work. Someone please advice me.

The setup:

I need the arduino to communicate with another device using a LIN bus. To handle the communication with the LIN bus, I use a LIN bus transceiver; Microchip MCP20041 connected to the Serial tx/rx of the Arduino. I got it all to work quite well, but when I wanted to make the ATMega328 stand-alone, I failed. I have followed the Arduiono Breadboard Tutorial2 excactly (from point 1 to 3), and I know the chip is running my program, as I set up a LED to flash and can see debug output via another Arduino connected via SPI3 (thanks Nick Gammon!).

The problem:

While the ATMega is sitting in the Arduino board everything works as excpected. I can send data through the LIN bus, and receive them again. But when running stand-alone, nothing gets to the bus and nothing is received. I've ruined two chips now, while taking them out the Arduino and putting them in the breadboard (and vice versa) countless times. I've meassured my circuit again and again and double checked my connections. But still no serial data reaches the LIN bus. (I've even tried to replace the LIN receiver)

I have also tried to burn the .hex file directly to the chip, using a programmer.

Here is a picture with the setup "running" in the breadboard. The important connections are:

  • White wire: From MCP2004/pin1 (Rx) to m328p/pin2 (Arduino pin 0/RX)
  • Blue wire: From MCP2004/pin4 (Tx) to m328p/pin3 (Arduino pin 1/TX)
  • Orange wire: From MCP2004/pin2 (CS) to m328p/pin6 (Arduino pin D4)
  • Orange wire: From m328p/pin19 (Arduino pin D13) to green LED.

As mentioned before, the LED blinks as it should. (See code below)

http://lavender.dk/stand-alone.jpg

And here is a picture with the setup running (and working) from the Arduino. I've moved the connections mentioned above to the arduino (except for the LED - which is already connected to pin D13).

http://lavender.dk/In-Arduino.jpg

The minimal code I'm using for test:

//Minimal test to see if Rx/Tx works in stand alone mode.
//
const int chipSelectPin = 4; //starts transmitter in MPC2004 LIN Transceiver.
const int ledPin = 13;        //Led pin
boolean ledIsOn = false;
byte bytesReceived = 0;
unsigned long ledTimer = millis();

void handleLed() 
{
  const long currentMillis = millis();
  if (currentMillis - ledTimer > 1000)
  {
    ledTimer = millis();
    digitalWrite(ledPin, ledIsOn);
    ledIsOn = !ledIsOn;
  }
}


void setup() 
{
  pinMode(ledPin, OUTPUT);
  pinMode(chipSelectPin, OUTPUT);
  
  Serial.begin(9600);
  UCSR0C |= _BV(UPM01); //Even parity
  
  delay(500);
  //Let's fire up the transmitter (CS = high)
  digitalWrite(chipSelectPin, HIGH);
}


void loop() 
{
  //Flash a led to make sure we're running!
  handleLed();
  Serial.print(0x0A); 
  delay(100);
  
}

Testcode using a USB LIN bus transceiver from my PC (C#)

using System;
using System.IO.Ports;

namespace B.Serial
{
    class Program
    {
        static void Main(string[] args)
        {
            SerialPort p = new SerialPort("COM5", 9600, Parity.Even);
            p.DataReceived += (s, e) =>
            {
                var c = p.ReadExisting();
                Console.Write(c);
            };
            p.Open();
            Console.ReadKey();
            p.Close();
        }
    }
}

Can anybody give me som hint about what to check. Is there a secret code, or something I need to enable to get the hardware serial ports to work without the Arduino board?

Thanks for reading so far, and thanks in advance for any comments!

(deleted)

spycatcher2k:
I dont see a crystal or resonator on your board? See here : Arduino - Home

It's hidden underneath an orange wire -- right above the two ceramic caps that are riding the bottom rail.

Chagrin:

spycatcher2k:
I dont see a crystal or resonator on your board? See here : Arduino - Home

It's hidden underneath an orange wire -- right above the two ceramic caps that are riding the bottom rail.

Yep that's true. It's there and it's a 16 MHz crystal. I've tried to replace it as well. Still no difference. The breadboard is setup exactly as the link I provided - and that again is the same setup as in the link spycatcher2k provided.

The only difference between the two pictures is that the IC is moved from the Arduino to the breadboard and the TX, RX and CS wires are moved too. If anybody have any clue I'd be very grateful. I don't even know what to try next.

2 Things:

  1. Do you have a volt meter? When it is in the standalone configuration check the voltages on the 328 and the 2004. You may be loading down the 9 volt battery. Post the voltages that you measure and the points you measured them at.

  2. Can you download a sketch in the standalone configuration? Does the Blinking led program run correctly.

JoeO:
2 Things:

  1. Do you have a volt meter? When it is in the standalone configuration check the voltages on the 328 and the 2004. You may be loading down the 9 volt battery. Post the voltages that you measure and the points you measured them at.

Yes I do.

I suspected the same, so I tried with real 12V lab transformer. Anyway, I'll measure voltage at the arduino and mcp2004 tonight and post the results.

JoeO:
2) Can you download a sketch in the standalone configuration? Does the Blinking led program run correctly.

I haven't been able to download sketches while it's sitting in the breadboard. But I have downloaded the blink.cpp.hex file directly to it via a avr programmer, and it worked great. The LED also blinks when the sketch posted above is running from the breadboard, so I am quite sure that the AVR IC is executing the sketch. It just don't seem to send anything via the serial pins.

Is there perhaps any way one can connect some LEDs to the serial pins to see if there's output there?

Thanks for your comments.

"I suspected the same, so I tried with real 12V lab transformer. Anyway, I'll measure voltage at the arduino and mcp2004 tonight and post the results."
A 12 Volt lab transformer is different than a 12 volt lab DC power supply. You need to use a 12 volt DC power supply.

I don't know about the LEDS.

Yes, measure the voltages and post here. Good luck.

JoeO:
A 12 Volt lab transformer is different than a 12 volt lab DC power supply. You need to use a 12 volt DC power supply.

Ok - I do. English is not my native language, I meant a DC power supply.

JoeO:
Yes, measure the voltages and post here. Good luck.

I've got 4,9 volts on both VCC and AVCC on the arduino. And 12,3 volts on the VBatt on the MCP2004.

I am totally empty for ideas of what to try next :S

Anybody?

The last thing that I can think of is that the reset switch is wired wrong. Does pin 1 of the 328 go from 5 Volts to 0 volts when you press the reset button?

Checked the reset switch and connections - no problem there.

Then I tried connecting the serial pins to the arduino (which was missing the IC), and started the serial monitor up - and It showed the characters the IC was writing to the TX pin!! (I really don't know why I didn't think of doing that ealier?!)

Anyway - at last I double checked the data sheet for the MCP2004 (again!), and I noticed a resistor symbol, unlabeled, between the RX pin and VCC, in the example application. I put in a 10K resistor between the RX and VCC on my breadboard - and BINGO! It worked!!

I'm so happy now :slight_smile: (sad that I spent over a week figuring out - but it's a great feeling that it works now).

Anyway - this must mean, that the arduino somewhere have a pull up on the RX also. I haven't seen this mentioned in any of the documents/sites describing how to make a stand alone arduino.

Thanks for you guys who took your time to help me.

this must mean, that the arduino somewhere have a pull up on the RX also.

It's a side-effect of having the USB/serial chip always connected. If it's not actually transmitting, it will act as a pullup for RX pin of the m328. It has surprised a couple of people...