Pages: 1 ... 8 9 [10] 11 12 ... 14   Go Down
Author Topic: SoftwareSerial with ATTiny84 using ATtiny library  (Read 48854 times)
0 Members and 1 Guest are viewing this topic.
Wahiawa, Hawaii
Offline Offline
God Member
*****
Karma: 31
Posts: 640
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I found some commented out lines in KnockBangReceiver.cpp, "Skip the Hello"?  What was this for?

When I put back the commented out code I was able to get KnockBang to work on the Mega2560 and Uno to some tinys.

Code:
--- Monitor starting ---
KnockBang-Testing...
KnockBang-Testing...
KnockBang-Testing...

--- Monitor stopped ---

Logged

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

Does TinyDebugKnockBang need to be updated also?

Yes.  Sorry about that.  TinyISP and TinyDebugKnockBang are paired and I made a change to the Knock-Bang protocol...
Logged

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

I found some commented out lines in KnockBangReceiver.cpp, "Skip the Hello"?  What was this for?

The protocol goes like this...

MISO is held high by the internal pull-up resistors on both sides.  When the transmitter (the ATtiny processor) wants to send data it sinks MISO low and holds it low for a few microseconds.  This triggers a pin-change interrupt on the receiver.  The receiver checks MISO to ensure there was not a false positive then waits for MISO to float high.  The transmitter changes MISO back to an input w/ pull-up allowing it to float high.  That sequence is the "knock".

The receiver then pulls MISO low for a few microseconds.  Upon noticing MISO go low the transmitter prepares to send data; it waits for MISO to float high.  The reciever changes MISO back to an input w/ pull-up allowing it to float high.  That sequence is the "hello".

Once MISO floats high, the transmitter proceeds to output data at ~3us per bit followed by a termination string.  That sequence is the "bang".

I dropped the "hello".  It solves a problem that does not exist.

Quote
When I put back the commented out code I was able to get KnockBang to work on the Mega2560 and Uno to some tinys.

Excellent.  Updating TinyDebugKnockBang should get the whole thing working.  Until you have all the kinks worked out I suggest adding a series resistor (220 to 1000 ohms) on MISO.  With the "hello" in the protocol on one side but not on the other there is a slight possibility of a short-circuit through the two processors.
Logged

Wahiawa, Hawaii
Offline Offline
God Member
*****
Karma: 31
Posts: 640
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Excellent.  Updating TinyDebugKnockBang should get the whole thing working.  Until you have all the kinks worked out I suggest adding a series resistor (220 to 1000 ohms) on MISO.  With the "hello" in the protocol on one side but not on the other there is a slight possibility of a short-circuit through the two processors.

Opps, I hope my avrs are still okay. smiley-eek

So with the new protocol on both sides, this short-circuit issue is prevented?

Will you have your updated TinyDebugKnockBang on Git also?  I checked but the last update was a year ago.

Logged

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

Excellent.  Updating TinyDebugKnockBang should get the whole thing working.  Until you have all the kinks worked out I suggest adding a series resistor (220 to 1000 ohms) on MISO.
Opps, I hope my avrs are still okay. smiley-eek

The resistors are generally a good idea especially when testing software.   However, I made a mistake with this...

Quote
With the "hello" in the protocol on one side but not on the other there is a slight possibility of a short-circuit through the two processors.

At one point I had a version of TinyDebugKnockBang that skipped the "hello".  That version was never published.  TinyDebugKnockBang always waits the 6us.  I did not drop the "hello"; I made it optional.  I apologize for the mistake and the unnecessary concern.

Quote
Will you have your updated TinyDebugKnockBang on Git also?  I checked but the last update was a year ago.

Something weird is going on with Github.  I did a pull and the versions match but browsing they do not match.  (The code of interest is here... https://github.com/Coding-Badly/TinyDebugKnockBang/blob/master/TinyDebugKnockBang.cpp#L475).  bbailout2 was moved...

Code:
   // For six microseconds check for Hello
  ".if %[_6us_hst] < 3"                               "\n\t"
    "sbis  %[pin], %[bit]"                            "\n\t"
    "rjmp  L%=bgothello"                              "\n\t"
    "sbis  %[pin], %[bit]"                            "\n\t"
    "rjmp  L%=bgothello"                              "\n\t"
    "sbic  %[pin], %[bit]"                            "\n\t"
    "rjmp  L%=bbailout2"                              "\n\t"
  ".else"                                             "\n\t"
    "ldi   %[d], %[_6us_hst]"                         "\n\t"  //  1  1
  "L%=bwaitforhello:"  "\n\t"
    "sbis  %[pin], %[bit]"                            "\n\t"  //  1  2 2 1
    "rjmp  L%=bgothello"                              "\n\t"  //  2  - - 2
    "dec   %[d]"                                      "\n\t"  //     1 1
    "brne  L%=bwaitforhello"                          "\n\t"  //     2 2
    "rjmp  L%=bbailout2"                              "\n\t"
  ".endif"                                            "\n\t"

  "L%=bgothello:"                                     "\n\t"
    // Putting bbailout2 here instead of with bbailout1 makes the Hello optional
  "L%=bbailout2:"                                     "\n\t"

Logged

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


Got it.  Please get a fresh copy of TinyDebugKnockBang and try again.
Logged

Wahiawa, Hawaii
Offline Offline
God Member
*****
Karma: 31
Posts: 640
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

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

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?
Logged

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

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.
Logged

Wahiawa, Hawaii
Offline Offline
God Member
*****
Karma: 31
Posts: 640
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?  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?

Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

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

otherwise I got the error:

Code:
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:

Code:
#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
« Last Edit: June 17, 2013, 03:42:03 am by sej7278 » Logged

Wahiawa, Hawaii
Offline Offline
God Member
*****
Karma: 31
Posts: 640
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.....
« Last Edit: June 17, 2013, 05:58:27 am by sej7278 » Logged

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

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?

Quote
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.
Logged

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

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?
Logged

Pages: 1 ... 8 9 [10] 11 12 ... 14   Go Up
Jump to: