SlashDevin / NeoSWSerial

Efficient alternative to SoftwareSerial with attachInterrupt for RX chars, simultaneous RX & TX
169 stars 42 forks source link

31250 baud rate with 8 Mhz CPU #36

Open josephernest opened 4 years ago

josephernest commented 4 years ago

Currently the code doesn't allow 31250 with 8 Mhz CPU. What is it so @jarosz ?

I tested to remove the CPU speed test in

((baudRate == 31250) && (F_CPU == 16000000L)) ||

and

case 31250:
    if (F_CPU > 12000000L) {

and it compiles, but indeed, the output is not good.

Would there be a way to make 31250 work for ATtiny45 at 8 Mhz?

Thanks a lot, and congratulations again for this great project @SlashDevin @jarosz.


PS: I also tested to use the ATtiny45 at 16 Mhz, but then

#if F_CPU == 16000000L
  #define TCNTX TCNT0
  #define PCI_FLAG_REGISTER PCIFR

generates an error. I tried replacing PCIFR by GIFR and TCNT0 by TCNT1 like in the next lines for ATtiny45, but no success.

PS2: I also tried, when using 8 Mhz CPU, to divide by 2 these constants, but without success:

static const uint8_t TICKS_PER_BIT_31250 = 8;
static const uint8_t BITS_PER_TICK_31250_Q10 = 128;
jarosz commented 4 years ago

Would there be a way to make 31250 work for ATtiny45 at 8 Mhz?

I don't know. I've made my MIDI projects only with ATmega32U4 and ESP8266. See my comment: https://github.com/SlashDevin/NeoSWSerial/pull/13#commitcomment-35478778