Pages: [1] 2 3 ... 14   Go Down
Author Topic: SoftwareSerial with ATTiny84 using ATtiny library  (Read 48789 times)
0 Members and 2 Guests are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I'm flashing an ATTiny84 using my Arduino Uno and everything works except the SoftwareSerial. I'm using the 8MHz internal clock (not calibrated but low baud rates would be fine since the interface will only be used for debugging). With some baud rates, the Arduino serial interface on my Mac receives some gibberish data and with others nothing at all. The TX led on the Arduino blinks when data is being sent btw.

Here's the important part of my code:
Code:
#include <SoftwareSerial.h>
// Definitions
#define rxPin 2
#define txPin 3

byte pwm = 0;

SoftwareSerial mySerial(rxPin, txPin);

void setup()
{
  // Pin Setup
  pwm = 0;
  mySerial.begin(9600);
}
 
void loop()
{
  /*
    calculates pwm
  */
  mySerial.print(pwm, DEC);
  mySerial.println();
  delay(1000);
}

Can anybody help? Would be greatly appreciated!
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
This couldn't be your ad.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried the same thing with an ATTiny85 and for some reason it does only work when VCC is not connected. I haven't tried it with an 84 yet, but I guess it's not that much different. Hope that helps.
Logged

There is no blueprint for life, blueprints are for architects!

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 210
Posts: 13030
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

...low baud rates would be fine since the interface will only be used for debugging...

Then I suggest using TinyDebugSerial in the Tiny Core.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

...low baud rates would be fine since the interface will only be used for debugging...

Then I suggest using TinyDebugSerial in the Tiny Core.

I tried the TinyDebugSerial, same problem.

I tried the same thing with an ATTiny85 and for some reason it does only work when VCC is not connected. I haven't tried it with an 84 yet, but I guess it's not that much different. Hope that helps.
What do you mean by not connecting VCC? Two different power supplies for the two microcontrollers? Because at the moment the AtTiny receives power from the Arduino 5V rail.
Logged

Denmark
Offline Offline
Edison Member
*
Karma: 36
Posts: 1084
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe you need the updated version mentioned in this thread:

http://arduino.cc/forum/index.php/topic,109081.15.html
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
This couldn't be your ad.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I used an ATTiny85 to send serial data and an Arduino Uno to receive it. First I got some strange gibberish too until I pulled the ATTiny's VCC out by accident. Without VCC on the ATTiny it sent what I wanted, after reconnecting VCC it was gibberish again. There were no pins except Tx, Rx and GND connected.

EDIT: Don't do this, a 100nf capacitor between the signal line and GND should do the trick.
« Last Edit: December 19, 2012, 07:42:11 am by MontySylver » Logged

There is no blueprint for life, blueprints are for architects!

Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe you need the updated version mentioned in this thread:

http://arduino.cc/forum/index.php/topic,109081.15.html
I used the current version (15) which should work as well, shouldn't it? But I switched back to http://hlt.media.mit.edu/?p=1695 after it didn't work.

I used an ATTiny85 to send serial data and an Arduino Uno to receive it. First I got some strange gibberish too until I pulled the ATTiny's VCC out by accident. Without VCC on the ATTiny it sent what I wanted, after reconnecting VCC it was gibberish again. There were no pins except Tx, Rx and GND connected.
Not sure how this is supposed to work without power but just to test everything I tried it as well and the AtTiny stopped transmitting after pulling out the VCC cable.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
This couldn't be your ad.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just tried it with some more stuff connected, it seems that the whole disconnecting VCC thing only works when the ATTiny does only transmit serial data and nothing else is supposed to happen in the sketch. Reading serial data works as it should.
Logged

There is no blueprint for life, blueprints are for architects!

Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Arduino must get it's power from somewhere else in your setup, otherwise it wouldn't work. Could you post a picture/schematic?

The data I'm receiving ist 0xFF every time if that helps someone to help me. I used a Processing sketch to display the actual binary data because the Arduino serial monitor only prints this character: ÿ
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Coding Badly
Now I'm using your library again.
It doesn't seem to matter if I just use the standard
Code:
Serial.begin(9600);
//and so on...

or if I use
Code:
#include <TinyDebugSerial.h>
TinyDebugSerial mySerial = TinyDebugSerial();
mySerial.begin(9600);
//and so on...

the output is always 0xFF with 2.5secs delay in between which I defined to check if it would be far off the expected value
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 210
Posts: 13030
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
With some baud rates, the Arduino serial interface on my Mac receives some gibberish data and with others nothing at all. The TX led on the Arduino blinks when data is being sent btw.

Are you using your Arduino as a serial converter?
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 210
Posts: 13030
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Not sure how this is supposed to work without power...

It won't.

Quote
...but just to test everything I tried it as well and the AtTiny stopped transmitting after pulling out the VCC cable.

Don't do that again.  It violates the specifications (meaning it could damage the processor).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, I'm just trying to use the Arduino board as a serial interface because I don't have a separate one. The 84's TX pin goes to the RX pin on the Arduino Uno R3 board which makes the TX led blink on the Arduino board. I also connected a 10µF cap between RESET and GND on the Arduino and leave the 4 pins used for programming the 84 connected during testing. The only thing I change during programming is disconnecting the 84's serial line temporarily.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Not sure how this is supposed to work without power...

It won't.

That's what they taught me in EE smiley-wink
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 210
Posts: 13030
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No, I'm just trying to use the Arduino board as a serial interface because I don't have a separate one.

That is what I was trying to ask.  Got it.

Quote
The 84's TX pin goes to the RX pin on the Arduino Uno R3 board which makes the TX led blink on the Arduino board.

I think that's correct.

Quote
I also connected a 10µF cap between RESET and GND on the Arduino

The Arduino processor has to be removed (not recommended) or forced into reset (recommended).  Remove the 10µF capacitor.  Connect a jumper between RESET and GND.  (Actually, you can probably leave the capacitor in place.)

As you've discovered, the Arduino processor interferes with serial communications.  In addition, unless the Arduino processor is essentially removed from the circuit, it is possible to damage one or both processors (some current limiting resistors will protect both sides).


If you are interested, I have a version of the ArduinoISP sketch that makes what you are trying to do much simpler.
Logged

Pages: [1] 2 3 ... 14   Go Up
Jump to: