Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Beginner question - Byte out throu pin

Beginner question - Byte out throu pin

2005-11-01 by peter_pohlmann26

Dear Gurus,

Just starting to learn Avr asm and i need some help please.

I want to send out a byte throu a pin on an ATtiny26.
Could someone show me how to do that or send me  a link ? 

Thank you for your help.
Peter

Re: [AVR-Chat] Beginner question - Byte out throu pin

2005-11-01 by Jim Wagner

"A byte through a pin" implies a serial sequence of bits.
You can do this with any serial interface such as a UART,
SPI, or TWI.

A key to this question, and an appropriate answer, is what
it is being sent to. If it is a "terminal device" (such as 
a PC), then asynchronous serial through a UART is, by far,
the best choice. If it is to or from another micro, then
SPI or TWI (I2C) could be the most useful.

Jim


On Tue, 01 Nov 2005 02:02:31 -0000
 "peter_pohlmann26" <peter_pohlmann26@yahoo.com> wrote:
> Dear Gurus,
> 
> Just starting to learn Avr asm and i need some help
> please.
> 
> I want to send out a byte throu a pin on an ATtiny26.
> Could someone show me how to do that or send me  a link ?
> 
> 
> Thank you for your help.
> Peter
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> ------------------------ Yahoo! Groups Sponsor
> --------------------~--> 
> Fair play? Video games influencing politics. Click and
> talk back!
> http://us.click.yahoo.com/T8sf5C/tzNLAA/TtwFAA/dN_tlB/TM
>
--------------------------------------------------------------------~->
> 
> 
>  
> Yahoo! Groups Links
> 
> 
> 
>  
> 
> 

---------------------------------------------------------------
The Think Different Store
http://www.thinkdifferentstore.com/
For All Your Mac Gear
---------------------------------------------------------------

Re: [AVR-Chat] Beginner question - Byte out throu pin

2005-11-01 by erikc

I don't know how much bearing this has on the topic at hand 
other than the fact that it involves excreting bytes through 
a port pin.  But I have found this to be useful for debugging.

As a general rule, one of the first things I do to become 
familiar with programming a new part and to familiarise 
myself with that part's instruction timing issues is to 
write a routine that reads a register or a memory location 
and excretes that value over one or more port pins in a 
special format that allows one to easily view the data on a 
'scope.  This tactic works with any system that has a pin or 
two to spare and does not need any special features.

One pin is designated as "sync" and is used to start the 
'scope sweep.  The other pin is the data, which is sent out 
most significant bit first.

A logic '0' is represented as a narrow pulse and a logic '1' 
is represented as a wide pulse.  The rising edges of the 
pulses are spaced a constant time apart making it easier to 
not only keep the 'scope in sync but also keep the trace 
from jumping around on the screen as the data changes.
   __
_|  |_________________________________________ (sync)

        __      __      ____    __      ____
______| 0|____| 0|____|  1 |__| 0|____|  1 |__ (data)
       0123456701234567012345670123456701234567
       MSB                             LSB

The routine first sends the sync pulse and then the data as 
shown in the "drawing".

If you tinker your 'scope settings, and are only looking at 
one byte or word you can dispense with the sync pulse.

An elaboration of this technique involves commandeering an 
extra pin or two and applying some resistors to make a crude 
DAC.  Here is how I get four traces at a time.

Pin "1" (sync)

Pin "2" ----/\/\/----+  <-- data is sent on this pin
              47K     |
                      o---- (data)
              22K     |
Pin "3" ----/\/\/----o
              10K     |  <-- these two pins set the place
Pin "4" ----/\/\/----+      where the data will be shown.

With "3" and "4" low, the data will be displayed near the 
bottom of the screen, with "3" and "4" high, near the top,
with room for two more traces in the middle.

One deficiency of this technique is that if an interrupt 
occurs, it screws up the display, so it is necessary to 
either disable the interrupts or incorporate the code as 
part of the interrupt service routine.

Here's an overview of how it is done in pseudocode:

DECLARE counter: BYTE;
DECLARE data: BYTE;  (* what you want to send *)
DECLARE data_pin (* whatever you want it to be *)
DECLARE sync_pin (* likewise *)
PROCEDURE SendByte();
BEGIN
	counter := 8; (* for a byte, 16 for a word *)
	Set( data_pin, LOW);

	Set( sync_pin, HIGH);
	Wait( 1);
	Set( sync_pin, LOW);  (* initiate 'scope trace *)

	REPEAT
		data := data << 1;
		(* presumes MSB ends up in carry *)

		IF (carry set)
		THEN (* long pulse *)
			Set( data_pin, HIGH);
			Wait( 2);
			Set( data_pin, LOW);
		ELSE (* short pulse *)
			Set( data_pin, HIGH);
			Wait( 1);
			Set( data_pin, LOW);
			Wait( 1);
		END; (*if*)
		Wait( 1);

		counter := counter - 1;
	UNTIL counter = 0;
END SendByte;

Tinker the  timing so that the "THEN" part executes in 
exactly the same number of cycles as the "ELSE" part.


erikc


Jim Wagner wrote:
Show quoted textHide quoted text
> "A byte through a pin" implies a serial sequence of bits.
> You can do this with any serial interface such as a UART,
> SPI, or TWI.
> 
> A key to this question, and an appropriate answer, is what
> it is being sent to. If it is a "terminal device" (such as 
> a PC), then asynchronous serial through a UART is, by far,
> the best choice. If it is to or from another micro, then
> SPI or TWI (I2C) could be the most useful.
> 
> Jim
> 
> 
> On Tue, 01 Nov 2005 02:02:31 -0000
>  "peter_pohlmann26" <peter_pohlmann26@yahoo.com> wrote:
> 
>>Dear Gurus,
>>
>>Just starting to learn Avr asm and i need some help
>>please.
>>
>>I want to send out a byte throu a pin on an ATtiny26.
>>Could someone show me how to do that or send me  a link ?
>>
>>
>>Thank you for your help.
>>Peter

Re: [AVR-Chat] Beginner question - Byte out throu pin

2005-11-02 by Peter Pohlmann

THank you for all the help.
Aslways good to ask the gurus :)
Last night i got it. there is a command ror and rol that will shift the byte..
together with the carry flag i got the idea.. Works nice now.
Thanks again.,
Peter

erikc wrote:
Show quoted textHide quoted text
I don't know how much bearing this has on the topic at hand
other than the fact that it involves excreting bytes through
a port pin. But I have found this to be useful for debugging.

As a general rule, one of the first things I do to become
familiar with programming a new part and to familiarise
myself with that part's instruction timing issues is to
write a routine that reads a register or a memory location
and excretes that value over one or more port pins in a
special format that allows one to easily view the data on a
'scope. This tactic works with any system that has a pin or
two to spare and does not need any special features.

One pin is designated as "sync" and is used to start the
'scope sweep. The other pin is the data, which is sent out
most significant bit first.

A logic '0' is represented as a narrow pulse and a logic '1'
is represented as a wide pulse. The rising edges of the
pulses are spaced a constant time apart making it easier to
not only keep the 'scope in sync but also keep the trace
from jumping around on the screen as the data changes.
__
_| |_________________________________________ (sync)

__ __ ____ __ ____
______| 0|____| 0|____| 1 |__| 0|____| 1 |__ (data)
0123456701234567012345670123456701234567
MSB LSB

The routine first sends the sync pulse and then the data as
shown in the "drawing".

If you tinker your 'scope settings, and are only looking at
one byte or word you can dispense with the sync pulse.

An elaboration of this technique involves commandeering an
extra pin or two and applying some resistors to make a crude
DAC. Here is how I get four traces at a time.

Pin "1" (sync)

Pin "2" ----/\/\/----+ <-- data is sent on this pin
47K |
o---- (data)
22K |
Pin "3" ----/\/\/----o
10K | <-- these two pins set the place
Pin "4" ----/\/\/----+ where the data will be shown.

With "3" and "4" low, the data will be displayed near the
bottom of the screen, with "3" and "4" high, near the top,
with room for two more traces in the middle.

One deficiency of this technique is that if an interrupt
occurs, it screws up the display, so it is necessary to
either disable the interrupts or incorporate the code as
part of the interrupt service routine.

Here's an overview of how it is done in pseudocode:

DECLARE counter: BYTE;
DECLARE data: BYTE; (* what you want to send *)
DECLARE data_pin (* whatever you want it to be *)
DECLARE sync_pin (* likewise *)
PROCEDURE SendByte();
BEGIN
counter := 8; (* for a byte, 16 for a word *)
Set( data_pin, LOW);

Set( sync_pin, HIGH);
Wait( 1);
Set( sync_pin, LOW); (* initiate 'scope trace *)

REPEAT
data := data << 1;
(* presumes MSB ends up in carry *)

IF (carry set)
THEN (* long pulse *)
Set( data_pin, HIGH);
Wait( 2);
Set( data_pin, LOW);
ELSE (* short pulse *)
Set( data_pin, HIGH);
Wait( 1);
Set( data_pin, LOW);
Wait( 1);
END; (*if*)
Wait( 1);

counter := counter - 1;
UNTIL counter = 0;
END SendByte;

Tinker the timing so that the "THEN" part executes in
exactly the same number of cycles as the "ELSE" part.


erikc


Jim Wagner wrote:
> "A byte through a pin" implies a serial sequence of bits.
> You can do this with any serial interface such as a UART,
> SPI, or TWI.
>
> A key to this question, and an appropriate answer, is what
> it is being sent to. If it is a "terminal device" (such as
> a PC), then asynchronous serial through a UART is, by far,
> the best choice. If it is to or from another micro, then
> SPI or TWI (I2C) could be the most useful.
>
> Jim
>
>
> On Tue, 01 Nov 2005 02:02:31 -0000
> "peter_pohlmann26" wrote:
>
>>Dear Gurus,
>>
>>Just starting to learn Avr asm and i need some help
>>please.
>>
>>I want to send out a byte throu a pin on an ATtiny26.
>>Could someone show me how to do that or send me a link ?
>>
>>
>>Thank you for your help.
>>Peter

Yahoo! FareChase - Search multiple travel sites in one click.

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.