Welcome! Log In Create A New Profile

Advanced

sanguino port manipulation

Posted by Bill Rowe 
sanguino port manipulation
September 29, 2008 01:04PM
trying to use direct port writing on my fine new sanguino. as far as I can tell

PORTB=bbbbbb assigns to sanguino digital pins 7, 6, 5, 4, 3, 2, 1 (high to low)
PORTC=bbbbbb assigns to 23, 22, 21, 20, 19, 18, 17, 16 (also high to low)
BUT
PORTA=bbbbbb assigns to 24, 25, 26, 27, 28, 29, 30, 31 (i.e. reverse bit order)

I don't see any real doc for this anywhere and it doesn't match with what I did guess from a header file. The doc does say that the digital pins 24-31 are assigned to Analog 7 down to 0 (in reverse order) but since this is just software labelling, what the heck is the point of the difference?
Anonymous User
Re: sanguino port manipulation
September 29, 2008 01:40PM
I guess it is a carry over from the Arduino which has the same "analog is reversed compared to digital" numbering convention.
Re: sanguino port manipulation
September 29, 2008 09:42PM
ChristianCooper Wrote:
-------------------------------------------------------
> I guess it is a carry over from the Arduino which
> has the same "analog is reversed compared to
> digital" numbering convention.

I hadn't used port manipulation on the arduino but I've used the analog pins as digital and I don't see that they're reversed. The arduino reference says: "The analog input pins can also be used as digital pins, referred to as numbers 14 (analog input 0) to 19 (analog input 5)."

what am i missing?
Anonymous User
Re: sanguino port manipulation
September 30, 2008 10:59AM
Bill Rowe Wrote:
-------------------------------------------------------
> I hadn't used port manipulation on the arduino but
> I've used the analog pins as digital and I don't
> see that they're reversed. The arduino reference
> says: "The analog input pins can also be used as
> digital pins, referred to as numbers 14 (analog
> input 0) to 19 (analog input 5)."
>
> what am i missing?

Unfoturnately absolutely nothing, I was talking complete nonsense, sorry!

I was remembering my pin planner template (see example below) that I put at the top of my sketches, of course both the analogue and decimal pin identifers are backwards on the bottom edge, not just the analogues... I is a fule.

Looking at the schematic for the Sanguino board (http://www.flickr.com/photos/hoeken/2696504917/sizes/l/) there is no reversal of the physical pins, PA0 == ADC0.

Hopefully Zach will pop along shortly, and have a less useless answer than mine.

My template (and the source of my confusion smiling smiley) is:
// -------------------------------------------------------------------------
// |                               Pin planner                             |
// -------------------------------------------------------------------------
// * Top Edge *
// ------------------------------|#|----------------------------------------
// |13  |12  |11  |10  |9   |8   |#|7   |6   |5   |4   |3   |2   |1   |0   | -- Pin ID
// ------------------------------|#|----------------------------------------
// |13  |12  |PWM2|PMW1|PMW0|8   |#|7   |6   |5   |4   |3   |2   |TX  |RX  | -- Board Label
// ------------------------------|#|----------------------------------------
// |    |    |    |    |    |    |#|    |    |    |    |    |    |TX  |RX  | -- Standard communications
// |    |    |    |    |    |    |#|    |    |    |    |IN1 |IN0 |    |    | -- Interrupts
// |    |    |AO2 |AO1 |AO0 |    |#|    |    |    |    |    |    |    |    | -- Analogue outputs (Primary)
// |    |    |    |    |    |    |#|    |AO5 |AO4 |    |AO3 |    |    |    | -- Analogue outputs (Secondary)
// |DI13|DI12|DI11|DI10|DI9 |DI8 |#|DI7 |DI6 |DI5 |DI4 |DI3 |DI2 |DI1 |DI0 | -- Digital Inputs
// |DO13|DO12|DO11|DO10|DO9 |DO8 |#|DO7 |DO6 |DO5 |DO4 |DO3 |DO2 |DO1 |DO0 | -- Digital Outputs
// |LED*|    |    |    |    |    |#|    |    |    |    |    |    |    |    | -- Notes
// ------------------------------|#|----------------------------------------
// |LED |DO12|DO11|AO1 |AO0 |    |#|    |DI6 |DI5 |DI4 |IN1 |IN0 |TX  |RX  | -- Chosen usage
// ------------------------------|#|----------------------------------------
// 
// * Bottom Edge *
// -------------------------------
// |         Pin planner         |
// -------------------------------
// |14  |15  |16  |17  |18  |19  | -- Pin ID (Digital usage)
// |0   |1   |2   |3   |4   |5   | -- Pin ID (Analog read usage)
// -------------------------------
// |AI0 |AI1 |AI2 |AI3 |AI4 |AI5 | -- Board Label
// -------------------------------
// |AI0 |AI1 |AI2 |AI3 |AI4 |AI5 | -- Analogue inputs
// |    |    |    |    |SDA |SCL | -- I2C Inter board communications
// |DI14|DI15|DI16|DI17|DI18|DI19| -- Digital Inputs
// |DO14|DO15|DO16|DO17|DO18|DO19| -- Digital Outputs
// -------------------------------
// |    |    |    |    |SDA |SCL | -- Chosen usage
// -------------------------------
//
// * LED - Has built in LED on Diecimila
Re: sanguino port manipulation
October 05, 2008 11:16AM
Hi

I have attempted to produce a pinout template for the Sanguino because I cannot read the small print of the silkscreen on the board and was getting very confused.

I have checked it but there is a more than a even chance there are misteaks in it.

I tried to insert it inline in this reply but the forum munged up my formatting so I have attached it as a file

Please check it and let me know any errors.

regards

Patrick
Attachments:
open | download - sanguino_pinout.txt (3.2 KB)
Re: sanguino port manipulation
October 22, 2008 10:09PM
[www.atmel.com]
Datasheet for the atmega644p, the chip behind the Sanguino. Includes pinouts and more software docs than you'll know what to do with.

Edit: If you're using avr-libc, you should note that avr/io.h (iirc) will pull in definitions for the bit offsets for the various pins, so you should never use magic numbers. For example, to set Port D pin 6, you could do PORTD |= (1 << PD6); unless my memory fails me.

Edited 1 time(s). Last edit at 10/23/2008 03:34AM by Ralith.
Sorry, only registered users may post in this forum.

Click here to login