ATTINY85 for Serial Communication at 2400 Baud

hi there

I want to transmit 8-10 byte data at 2400 baud rate to a device. The device reads only at 2400 rate. I am doing this using Arduino Nano sucessfully. The Arduino Nano is connected to Max232 which then transmits data via RS232 port.

I want to do this using ATTINY85 (with or without Crystal) to save cost and components space/size. I have loaded all boards and first tested the ATTINY85 using a simple LED flash sketch. It worked. Later, I burned the bootloader at Internal 8Mhz by the method described on various websites. I then uploaded the sketch :

#include <SoftwareSerial.h>
const int rx=-1;
const int tx=3;
SoftwareSerial mySerial(rx,tx);
void setup()
{
pinMode(tx,OUTPUT);
mySerial.begin(9600);
}
void loop()
{
  mySerial.println("Testing .... ");
  delay(1000);
}

I attached the pin2 of ATTINY85 to a USB-Serial Converter pin RX and tested it on the serial monitor. The output came as “Testing…*)X+#$” … at times normal and at times garbage, not consistent … I then reprogrammed it at 2400 baud but the output never came normal (only garbage).

Later I installed updated libraries of from https://code.google.com/p/arduino-tiny/ and used this code:

#include <TinyDebugSerial.h>
TinyDebugSerial mySerial = TinyDebugSerial();
..
..

but arduino compiler failed to compile it. It always gives error:

“TinyDebugSerial does not name a type”.

But I have learnt that this tinydebugserial is unable to work below 9600 baud rate.

I wanted to know is there any solution with ATTiny85 ? or by using external crystal (of 8Mhz or 16 or 20Mhz)? Or should I shift back to Arduino Nano ?

I am using Arduino software ver 1.0.5.

thanks

External crystal, or tune the internal oscillator so it's accurate enough for serial. The quick and dirty way would be to just nudge osccal a little higher or lower in setup, until you found something that worked - you're clearly close, since it almost worked at 9600 (I think it's a little fast...?)

(You're not trying to send and receive at the same time are you? That breaks all software serial. Something simple like echoing a character you receive as you get it, while potentially receiving more falls afoul of this)

As an aside, a significant portion of them happen to be close enough to 8 mhz without user calibration, just not all of them :/

Thanks ...

Can you please mention the setup code by which you can change the osscal value (internal oscillator)? or how to tune the internal oscillator ? I am not a strong programmer so sorry for that ...

i am using ATTiny only for transmitting data ...

You set the OSCCAL register

I've done things like OSCCAL+=5 in setup to nudge it a bit higher than the factory setting. There also exist tuning sketches, designed to figure out exactly what the best value is for that, so you can just set it to that.

I am to fix it successfully for 2400 baud by setting an appropriate OSSCAL value ...

thanks for that ...

For others, I selected the right OSSCAL value by running this sketch ... When I was able to read the characters correctly, i selected the appropriate OSSCAL value .. i ran this code :

#include 
SoftwareSerial mySerial(-1,3);
int val = 0x64;
void setup()
{
  mySerial.begin(2400); 
  OSSCAL = val; 
}
void loop()
{
 for (var i=0; i<=0xFF; i++)
 {
  OSSCAL=i; 
  mySerial.print("OSSCAL=");
  mySerial.println(i);
  delay(1000);
 }
}