Pages: [1] 2   Go Down
Author Topic: Sanguino - blink doesn't work  (Read 1900 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just assembled (soldered) a Sanguino. I added the suggested extra stuff to boards.txt.

The thing powers up, I can upload a sketch to it, no worries. A sketch with Serial.print in it (see below) works in the sense that it uploads, and displays "Hi there" in the monitor. In fact it is a modified "blink" sketch.

Code:
void setup() {                
  pinMode(13, OUTPUT);
  Serial.begin (115200);
  Serial.println ("Hi there");
}

void loop() {
  digitalWrite(13, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // set the LED off
  delay(1000);              // wait for a second
}

But, a LED plugged into the port identified as D13 doesn't blink. And for completeness, by trial-and-error I found it actually blinks when plugged into D5.

So, clearly some defines are wrong in the way they work with digitalWrite. Presumably bit masks to map ports to digital pin numbers.

Now I admit I didn't do the complete installation, because the Sanguino site mentions this:

Quote
Copy all the folders in sanguino-software-1.x/libraries/ to arduino-0012/hardware/libraries/ overwriting the existing libraries.

Since I am up to Arduino 0022 I'm reluctant to throw away around 10 versions just to get the Sanguino digital ports to work.

Has anyone got some minimalist patches or suggested downloads that just correct the digital port assignment for the atmega644P (as used by the Sanguino) that would get it working without altering behaviour for my other boards, like the Uno and Mega? Thanks!
« Last Edit: April 20, 2011, 11:58:14 pm by Nick Gammon » Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 178
Posts: 12288
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I found it actually blinks when plugged into D5

By "D5" do you mean "port D bit 5" (I think Atmel uses the label "PD5") or do you mean "Arduino digital pin 5"?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

From the diagram below, which was in pins_arduino.c supplied in the Sanguino downloads, it works in D5 (PB5, pin 6) but not in D13 (PD5, pin 19). The working pin is processor pin 6, which a visual inspection seems to indicate that is directly connected to the 6th edge connector pin (ie. pin 1 is D0, pin 2 is D1, etc.). See schematic attached.

Code:
// ATMEL ATMEGA644P / SANGUINO
//
//                   +---\/---+
//  INT0 (D 0) PB0  1|        |40  PA0 (AI 0 / D31)
//  INT1 (D 1) PB1  2|        |39  PA1 (AI 1 / D30)
//  INT2 (D 2) PB2  3|        |38  PA2 (AI 2 / D29)
//   PWM (D 3) PB3  4|        |37  PA3 (AI 3 / D28)
//   PWM (D 4) PB4  5|        |36  PA4 (AI 4 / D27)
//  MOSI (D 5) PB5  6|        |35  PA5 (AI 5 / D26)
//  MISO (D 6) PB6  7|        |34  PA6 (AI 6 / D25)
//   SCK (D 7) PB7  8|        |33  PA7 (AI 7 / D24)
//             RST  9|        |32  AREF
//             VCC 10|        |31  GND
//             GND 11|        |30  AVCC
//           XTAL2 12|        |29  PC7 (D 23)
//           XTAL1 13|        |28  PC6 (D 22)
//  RX0 (D 8)  PD0 14|        |27  PC5 (D 21) TDI
//  TX0 (D 9)  PD1 15|        |26  PC4 (D 20) TDO
//  RX1 (D 10) PD2 16|        |25  PC3 (D 19) TMS
//  TX1 (D 11) PD3 17|        |24  PC2 (D 18) TCK
//  PWM (D 12) PD4 18|        |23  PC1 (D 17) SDA
//  PWM (D 13) PD5 19|        |22  PC0 (D 16) SCL
//  PWM (D 14) PD6 20|        |21  PD7 (D 15) PWM
//                   +--------+


* Sanguino_Schematic.jpg (227.92 KB, 1024x548 - viewed 18 times.)
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In the image below, the pin circled in red, and labelled 5 on the board (really processor pin 6) works, the pin circled in green, and labelled 13 does not work.


* Sanguino_Picture.png (180.58 KB, 463x198 - viewed 26 times.)
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Another view of the pinouts:


* Sanguino_pinouts.jpg (99.16 KB, 352x500 - viewed 28 times.)
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 178
Posts: 12288
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


"pins_arduino.c" looks fine.  The DDR, PIN, and PORT addresses are all below 256.  The slots for pin 13 look fine.  Huh.  Looks like we have a mystery on our hands. 

First, a quick sanity check.  Do you have the Sanguino selected on the Tools / Board menu?

Try this for blinking pin 13...

Code:
void setup( void )
{
  DDRD |= _BV(5);
}

void loop( void )
{
  PORTD |=   _BV(5);
  delay( 1000 );
  PORTD &= ~ _BV(5);
  delay( 1000 );
}



This is a note to myself in case the test above works.  Just ignore it...

        uint8_t timer = digitalPinToTimer(pin);
        uint8_t bit = digitalPinToBitMask(pin);
        uint8_t port = digitalPinToPort(pin);
        volatile uint8_t *out;
        out = portOutputRegister(port);

#define PD 4

digital_pin_to_port_PGM
PD

digital_pin_to_bit_mask_PGM
_BV(5)
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6381
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I admit I didn't do the complete installation
Exactly which parts did you do?
PB5 (D5 on Sanguino) would be D13 on a regular ATmega328-based Arduino, so it looks like you don't have the Sanguino pin definitions installed correctly.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First, a quick sanity check.  Do you have the Sanguino selected on the Tools / Board menu?

Yes. smiley-wink

Try this for blinking pin 13...

Code:
void setup( void )
{
  DDRD |= _BV(5);
}

void loop( void )
{
  PORTD |=   _BV(5);
  delay( 1000 );
  PORTD &= ~ _BV(5);
  delay( 1000 );
}

That blinks the correct pin. I don't really doubt the pin can be made to blink, and I thank you for showing me in a couple of lines of code how to do it, but I wonder if there isn't some problem with the Sanguino with reference to the defines in the standard libraries.

Now I think a perfectly acceptable response would be "ah, but we don't support the Sanguino - work it out yourself" and I would sigh and rewrite various low-level routines.

I suppose what I am asking is, has anyone done this already, to save me the time in doing it?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Exactly which parts did you do?
PB5 (D5 on Sanguino) would be D13 on a regular ATmega328-based Arduino, so it looks like you don't have the Sanguino pin definitions installed correctly.

I appended the contents of boards.txt into my main boards.txt file, as instructed, so it would add Sanguino to my "boards" menu, and program it correctly.

But I baulked at replacing files in my 0022 installation with ones which were for 0012 Arduino (replacing, not adding) as a quick "diff" showed major changes had happened.

I don't really like instructions to "replace these files" when the files are dated 2008, and the files I am replacing are dated 2010. I assume that the Sanguino files are rather old, and while that might make the Sanguino work, it might also stop my Arduino or Mega from working as well.

Quote
... so it looks like you don't have the Sanguino pin definitions installed correctly.

Well, someone hasn't got them defined correctly. I didn't write this stuff, you know.

I don't mind if you say "we don't support the Sanguino, sorry", that's fine. But if you also say "these diffs will make it work" that would be helpful, if such diffs exist.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6381
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, the "cores" directory is supposed to get an additional subdirectory "sanguino" of the sanguino core files, including the pin definitions and what not, so it doesn't directly replace anything.  Then the sanguino boards are supposed to pick up the different core files, somehow (and I'm not quite seeing how, since the sanguino add-on to boards.txt says to use the arduino core.)

And I think that change since 12/18 have made it much easier to add new platforms like sanguino, but I'm not sure exactly how.  (I really need to find my sanguino board.  It's around here somewhere.)
Logged

SouthEast UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just tried this on a home brewed Sanguino with all the Sanguino core files copied to the sketchbook/hardware/Sanguino directory (I'm using Linux) and everything works exactly as it should. D13 blinks
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds like we are getting a bit closer then.

I went to the "downloads" link as instructed and grabbed the file "Sanguino-0018r2_1_4.zip" which was labelled "0018 hardware folder with unaimed's modified files" and dated June 2010. There didn't seem to be any other software downloads (the other ones were Gerber files for the board etc.).

Now their instructions are:

Quote
  1. Copy sanguino-software-1.x/cores/sanguino to arduino-0012/hardware/cores/sanguino
   2. Copy sanguino-software-1.x/bootloaders/atmega644p to arduino-0012/hardware/bootloaders/atmega644p
   3. Copy all the folders in sanguino-software-1.x/libraries/ to arduino-0012/hardware/libraries/ overwriting the existing libraries.

First problem. There is no directory "/cores/sanguino" in the download. It is "/cores/arduino" (see screenshot). So I didn't want to replace all the arduino files with sanguino ones.

I copied the bootloader, no problems, that was just a new file. I fixed up the boards.txt file, no problems there.

I didn't do step 3 because I didn't want to "overwriting ... existing libraries.". And more importantly, as you can see from the screenshot, there is no libraries directory anyway.

This is on a Mac, by the way (although the Windows instructions look virtually identical).




* Sanguino_dir_structure.png (64.52 KB, 837x349 - viewed 15 times.)
« Last Edit: April 20, 2011, 11:50:10 pm by Nick Gammon » Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 178
Posts: 12288
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
That blinks the correct pin.

Excellent!

Quote
I don't really doubt the pin can be made to blink, and I thank you for showing me in a couple of lines of code how to do it, but I wonder if there isn't some problem with the Sanguino with reference to the defines in the standard libraries.

I have never used a Sanguino so I don't know if the reference material is accurate.  I had you run the test in case you didn't get replies from someone who has used a Sanguino; someone who could verify that the reference material is accurate.  In other words, I wanted to make certain we were starting with accurate information.

Quote
But I baulked at replacing files in my 0022 installation with ones which were for 0012 Arduino (replacing, not adding) as a quick "diff" showed major changes had happened.

You made the right choice!  It is absolutely not necessary to replace the Arduino core files.

I'll give you instructions based on the layout of the Tiny Core.  You should be able to install the Sanguino core by using different directory names.  I'll use "{Sketch}" to refer to the Sketch directory on your computer.

1. I suggest undoing everything you've done so far.  Ensure the Arduino IDE is not running.  Start by removing the Sanguino entries from the original "boards.txt".

You can and should put third party core files in the {Sketch}\hardware\ directory.  Under that directory I have a "tiny" directory where the Tiny Core belongs.  I'll use the directory name "sanguino".  

2. Create the directory...  {Sketch}\hardware\sanguino\

In my "tiny" directory I have a "boards.txt" file and a "programmers.txt".  For the Sanguino, you will not be adding any new programmers but I suggest creating an empty file just in case the IDE needs to be appeased.  Later you can try deleting the file.

3. Create an empty text file...  {Sketch}\hardware\sanguino\programmers.txt

The Sanguino boards.txt file includes entries for the AdaBoot bootloader on the 168 and 328 processors.  You won't need those for the Sanguino and I suggest leaving them out.

4. Put the following contents into this file...  {Sketch}\hardware\sanguino\boards.txt

Code:
ADABoot644P.name=Sanguino - ADABoot loader w/ATmega644p
ADABoot644P.upload.protocol=stk500
ADABoot644P.upload.maximum_size=63488
ADABoot644P.upload.speed=38400

ADABoot644P.bootloader.low_fuses=0xFF
ADABoot644P.bootloader.high_fuses=0xDC
ADABoot644P.bootloader.extended_fuses=0xFD
ADABoot644P.bootloader.path=ADABootloader
ADABoot644P.bootloader.file=ADABoot_644p.hex
ADABoot644P.bootloader.unlock_bits=0x3F
ADABoot644P.bootloader.lock_bits=0x0F

ADABoot644P.build.mcu=atmega644p
ADABoot644P.build.f_cpu=16000000L
ADABoot644P.build.core=sanguino
ADABoot644P.verbose=false

5. Create the directory...  {Sketch}\hardware\sanguino\cores\

6. Create the directory...  {Sketch}\hardware\sanguino\cores\sanguino\

7. Copy the core files (HardwareSerial.cpp, HardwareSerial.h, Makefile, etcetera) into the directory created above...  {Sketch}\hardware\sanguino\cores\sanguino\

8. Create the directory...  {Sketch}\hardware\sanguino\bootloaders\

9. Create the directory...  {Sketch}\hardware\sanguino\bootloaders\ADABootloader\

10.  Copy the bootloader files (ADABoot_644p.hex, etcetera) into the directory created above...  {Sketch}\hardware\sanguino\bootloaders\ADABootloader\


That should do it.  The Tools menu should now have a "Sanguino - ADABoot loader w/ATmega644p" entry and hopefully works correctly.
« Last Edit: April 20, 2011, 09:10:08 pm by Coding Badly » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you so much. That works perfectly! I have to say your instructions differ substantially from those on the Sanguino web site, and yours work!

I've saved what you said for next time I get a different sort of board.

One query, you said:

Quote
Copy the bootloader files (ADABoot_644p.hex, etcetera) into the directory created above...  {Sketch}\hardware\sanguino\bootloaders\ADABootloader\

But the supplied bootloader files are actually:

Code:
ATmegaBOOT.c
ATmegaBOOT_324P.hex
ATmegaBOOT_644.hex
ATmegaBOOT_644P.hex
Makefile
README.txt

Does that mean the bootloader directory and/or the boards.txt file should be modified to suit the file names?
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6381
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I have to say your instructions differ substantially from those on the Sanguino web site, and yours work!
Thanks, CodingBadly.  The reason that the instructions are so different is that the Arduino authors have done a substantial amount of work to make it EASIER to install non-standard hardware.  (You'll notice that you no longer need to modify the "system install" of the arduino environment, for example.  Everything can now but done in the particular user's home directory.)
Logged

Pages: [1] 2   Go Up
Jump to: