SoftwareSerial with ATTiny84 using ATtiny library

Okay, with both new copies of TinyISP and TinyDebugKnockBang, Knock-Bang is working on the Mega2560 going to a tiny84 @1MHz. I will continue reviewing and testing with various tinys and speeds.

hiduino:
Ok, I know you said serial relay was note to yourself. But I tried anyway and was able to get it to work with a Mega2560 and tiny84. I made two changes to the code.

That actually uses SoftwareSerial for the relay. Would you prefer one of the other USARTs like Serial1?

hiduino:
Okay, with both new copies of TinyISP and TinyDebugKnockBang, Knock-Bang is working on the Mega2560 going to a tiny84 @1MHz. I will continue reviewing and testing with various tinys and speeds.

Excellent. Thank you.

Yes, I noticed that. But isn't why you are using SoftwareSerial because you can direct it to the MISO pin? If you use the USART then you would have to wire additional connections from the target? SoftwareSerial seems to be working okay, what would be the benefits of using a USART? More speed options? Better accuracy?

I'm having trouble getting KnockBang to work on my Mega2560 (not tried serial yet). What I did:

Download latest TinyDebugKnockBang directory from github, put it in ~/sketchbook/libraries/
Download latest TinyISP directory from github, put it in ~/sketchbook/

Rename TinyISP.pde to TinyISP.ino
Added const to this line:

__attribute__ ((used)) char Copyright[] PROGMEM = "blah"

otherwise I got the error:

TinyISP.ino:101:42: error: variable ‘Copyright’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’

Made sure #include <SoftwareSerial.h> was commented out with //

Added these lines to _TinyISP_BuildOptions.h:

#define RELAY_KNOCK_BANG_ENABLED 1
#define RELAY_SERIAL_ENABLED 0

Uploaded TinyISP.ino to Mega as usual (removed cap on reset/GND, uploaded, put it back, tried with and without 220ohm resistor on MISO)

Uploaded demo program from here to ATtiny85 (using arduino-tiny 0017 core, 8MHz internal clock, also tried 1MHz)

Opened serial monitor, changed to 19200 baud, waited.... just got a kind of a square character like [], at 9600 baud i get nothing at all

sej7278:
Opened serial monitor, changed to 19200 baud, waited.... just got a kind of a square character like [], at 9600 baud i get nothing at all

On the Mega2560, you have to wait about 10 seconds for the bootloader to timeout after opening Serial Monitor. You need to watch the "L" LED for the heartbeat pulse before type the "!" character to enter Monitor mode. When you are done with Monitor mode, don't forget to exit by typing "!" again, to put it back in ISP mode. You need to keep Serial Monitor at 19200 baud for this.

hiduino:

sej7278:
Opened serial monitor, changed to 19200 baud, waited.... just got a kind of a square character like [], at 9600 baud i get nothing at all

On the Mega2560, you have to wait about 10 seconds for the bootloader to timeout after opening Serial Monitor. You need to watch the "L" LED for the heartbeat pulse before type the "!" character to enter Monitor mode. When you are done with Monitor mode, don't forget to exit by typing "!" again, to put it back in ISP mode. You need to keep Serial Monitor at 19200 baud for this.

ah, didn't realise you had to enter ! for knockbang mode, now i'm getting:

--- Knock-Bang fault: 11 ---

also 4 and 13.....

hiduino:
On the Mega2560, you have to wait about 10 seconds for the bootloader to timeout after opening Serial Monitor.

You're not using a capacitor to disable auto-reset?

When you are done with Monitor mode, don't forget to exit by typing "!" again, to put it back in ISP mode.

Out of habit, I exit Monitor when I finish but doing that should not actually be necessary. There is code in TinyISP that automatically switches from Monitor to Programmer.

sej7278:
Uploaded demo program from here to ATtiny85 (using arduino-tiny 0017 core, 8MHz internal clock, also tried 1MHz)

Did you remember to Burn Bootloader so the target is actually running at the correct speed?

hiduino:

[quote author=Coding Badly link=topic=123388.msg1279986#msg1279986 date=1371359028]
That actually uses SoftwareSerial for the relay. Would you prefer one of the other USARTs like Serial1?

Yes, I noticed that. But isn't why you are using SoftwareSerial because you can direct it to the MISO pin?[/quote]

The first version of TinyISP was made for the m328 processor when Knock-Bang did not exist. Serial was the only way to send debugging information. At that point it made sense to use SoftwareSerial with MISO as the RX pin.

The new idea is to use Knock-Bang for debugging and Serial for data. As I port TinyISP to other processors I have always used a USART if I could.

If you use the USART then you would have to wire additional connections from the target?

Well, one extra connection.

SoftwareSerial seems to be working okay, what would be the benefits of using a USART? More speed options? Better accuracy?

Yes and yes.

With the new interrupt driven Serial, there is also a high probability of dropped data. Using a USART for Serial Relay eliminates that problem.

Yes, I didn't think I needed to disable auto-reset for Serial Monitor mode, but I guess that makes sense. (After all I did not have to disable auto-reset for ISP programming.)

Okay, I didn't know about that, Great feature!
So when I exit Monitor mode, it keeps on running after I close Serial Monitor, until I try an upload using programmer or burnbootloader?

yes.

The fault codes are here... TinyISP/KnockBangReceiver.cpp at master · Coding-Badly/TinyISP · GitHub

0x11 is fault_timeout_knock which occurs when the pin-change interrupt fires, a knock is detected, but the knock duration is (way) too long. Loose wire, target at the wrong speed (running at 1 MHz; sketch built for 8 MHz), or the programmer is running significantly faster than 16 MHz.

0x04 is fault_no_knock which occurs when the pin-change interrupt fires and no knock is detected. Loose wire, target at the wrong speed (running at 8 MHz; sketch built for 1 MHz), or side-effect of a previous failure.

0x13 is fault_timeout_sample_0 which occurs when the first timing mark is not detected. Loose wire, target running at the wrong speed, or side-effect of a previous failure.

hiduino:
Yes, I didn't think I needed to disable auto-reset for Serial Monitor mode, but I guess that makes sense. (After all I did not have to disable auto-reset for ISP programming.)

Wow. You are actually able to program a target with a 10 second bootloader time-out?

Your experience will be greatly improved by disabling auto-reset!

Thanks.

So when I exit Monitor mode, it keeps on running after I close Serial Monitor, until I try an upload using programmer or burnbootloader?

Correct.

[quote author=Coding Badly link=topic=123388.msg1282070#msg1282070 date=1371500979]
0x11 is fault_timeout_knock which occurs when the pin-change interrupt fires, a knock is detected, but the knock duration is (way) too long. Loose wire, target at the wrong speed (running at 1 MHz; sketch built for 8 MHz), or the programmer is running significantly faster than 16 MHz.

0x04 is fault_no_knock which occurs when the pin-change interrupt fires and no knock is detected. Loose wire, target at the wrong speed (running at 8 MHz; sketch built for 1 MHz), or side-effect of a previous failure.

0x13 is fault_timeout_sample_0 which occurs when the first timing mark is not detected. Loose wire, target running at the wrong speed, or side-effect of a previous failure.[/quote]

my bootloader/sketch speeds match and i doubt there's a loose wire as they work fine for ArduinoISP and TinyISP. (i assume you mean 50-53?) and the Mega2560r3 is running at stock 16MHz. do you think i need to use tinytuner or edit the fuses somehow?

as far as wiring goes, we are just using MISO/MOSI/SCK/RESET with a USB cable from mega to pc as you would for ISP'ing, and not TX/RX with a USB UART or something?

When burning bootloader or Upload using programmer, the IDE appears to be using the stk500v1 protocol (for Arduino as ISP) which avoids invoking the auto-reset on the Mega2560 board.

But I guess I will still need to disable auto-reset for Serial Monitor use. This could be avoided also if the Mega2560 bootloader did something similar to Optiboot, where it will skip out of bootloader if the wrong baud rate is detected?

sej7278:
as far as wiring goes, we are just using MISO/MOSI/SCK/RESET with a USB cable from mega to pc as you would for ISP'ing

Anything extra connected to MISO? LED? SPI device?

I often use a LED to make sure the sketch running at the expected clock rate.

Try this:

#include <TinyDebugKnockBang.h>

int led = 3;

void setup( void )
{
  Debug.begin( 250000 );
  pinMode(led, OUTPUT);
}

void loop( void )
{
  digitalWrite(led, HIGH); 
  delay(1000);              
  digitalWrite(led, LOW);   
  delay(1000); 

  Debug.println( F( "Caitlin! " ) );
//  delay( 1000 );
}

yes that's it - i've got a resistor and led coming out of pin 6 on the tiny, if i remove them, knockbang works!

however if i'm doing anything useful in my sketch (some counting, analogWrite, random, delay....) knockbang seems to sit there doing nothing, gets stuck at monitor startin.....

sej7278:
however if i'm doing anything useful in my sketch (some counting, analogWrite, random, delay....) knockbang seems to sit there doing nothing, gets stuck at monitor startin.....

Are you asking for helping? Or did you just need a whine to vent some frustration?