i´m using the arduino as an isp to program my attiny84 20pu for midi purposes.
now during the first midi program i've run into an error:
the MIDI baudrate is set at 31.25 k
but the supporting libs only allow me to program the in 9**,6k, 38,4k** and 115,2k baudrate.
my question is how to set the serial baudrate of the attiny to 31,25k note: i have been succefull in programming the attiny and this question is purely code based i've used this tutorial for programming the attiny : http://www.instructables.com/id/Program-an-ATtiny-with-Arduino/
not entirly, but when im trying to compile my code with the Serial.begin(31250);
i get this error:
In member function 'void TinyDebugSerial::begin(long int)',
inlined from 'void setup()' at basis.ino:44:
C:\Program Files (x86)\Arduino\hardware\tiny\cores\tiny/TinyDebugSerial.h:694: error: call to 'TinyDebugSerialBadBaud' declared with attribute error: Serial (TinyDebugSerial) supports three baud rates: 9600, 38400, or 115200
daatse:
not entirly, but when im trying to compile my code with the Serial.begin(31250);
i get this error:
In member function 'void TinyDebugSerial::begin(long int)',
inlined from 'void setup()' at basis.ino:44:
C:\Program Files (x86)\Arduino\hardware\tiny\cores\tiny/TinyDebugSerial.h:694: error: call to 'TinyDebugSerialBadBaud' declared with attribute error: Serial (TinyDebugSerial) supports three baud rates: 9600, 38400, or 115200
.
Ok, I didn't know "supporting libs" meant "TinyDebugSerial".
Looks like you're going to have to go in and hack the source code for TinyDebugSerial to support another baud rate.
I'm now trying to use the softwareserial library which as i found out with the link above. it still doesn't work but at least the baud-rate is accepted and the proper pins can be set...
one drawback is the amount of space the library uses on the attiny's flash, but there can be ways around that
If you want two way comms with custom baud rate and a similar interface as the standard Serial command, you can extract the TinySoftwareSerial from here:
There are some downsides:
(1) it is half duplex - you cannot send and receive at the same time, but then all software serial codes are.
(2) there are fixed pins: TX=PA1, RX=PA2
(3) its integrated into the ATTinyCore, so if you want to use it in another core then a tiny bit of mod will be required (just add a couple of lines to the header file).
(4) as with all serial, if you are using the internal oscillator you will need to tune it to get accurate baud rates.
thank you very much for your help im going to give that lib a spin,
(1) it is half duplex - you cannot send and receive at the same time, but then all software serial codes are.
thats fine because i don't need to be able to do that anyway
(2) there are fixed pins: TX=PA1, RX=PA2
isn't this changable ?
(3) its integrated into the ATTinyCore, so if you want to use it in another core then a tiny bit of mod will be required (just add a couple of lines to the header file).
(4) as with all serial, if you are using the internal oscillator you will need to tune it to get accurate baud rates.
i am using the internal osc, of 8mhz, so how would i tune this the right way
You will need to add these lines to the very top of the TinySoftwareSerial.h file if you are not using it as part of the core.
/*
Where to put the software serial? (AVR Pin Bits and Registers)
*/
//WARNING, if using software, TX is on AIN0, RX is on AIN1. Comparator is favoured to use its interrupt for the RX pin.
#define USE_SOFTWARE_SERIAL 1
//Please define the port on which the analog comparator is found.
#define ANALOG_COMP_DDR DDRA
#define ANALOG_COMP_PORT PORTA
#define ANALOG_COMP_PIN PINA
#define ANALOG_COMP_AIN0_BIT 1
#define ANALOG_COMP_AIN1_BIT 2