wait till a input pin is high

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hallo,

i have (i think) a small problem to do a simple job in the program. i just don't see it.

 

i want a byte shift out the AVR on a output pin (serieel), in cooperation whit a clock puls on a input pin.

i isolate a bit out of the byte, but before i can shift him to the output pin i have to wait till the clock pulse is high.

and that waiting is the problem, i just don't see how to do this frown


#include <avr/io.h>

int main(void)
{
     while (1)
    {
		for (j=0;j<8;j++)
		{
			if ((byte & 0x80)==0x80)
// I HAVE TO WAIT HERE TILL THE CLOKPULSE IS HIGH *********************************8
			{
				PORTB |= (1 << PINB4); // make B4 1
			}
			else
			{
				PORTB &= ~(1 << PINB4); // make B4 0
			}

			byte = (byte <<1);

		}

    }
}

 

Last Edited: Mon. Jun 24, 2019 - 06:56 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What port pin is the "clock" signal coming in on?

How clean is the signal, in other words, do you need to debounce the clock input?

 

Jim

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

Last Edited: Mon. Jun 24, 2019 - 06:19 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i don't need a debounce, the clock is comming from another AVR. on pin B3.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok,so you will have code that looks similar to this:

 

while((PINB & PB3)  ==  0) ; //wait here while clock is low

{

     //now clock is high

}

while((PINB & PB3) > 0); //wait here while clock is high

{

     //now clock is low

}

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

Last Edited: Mon. Jun 24, 2019 - 07:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The important fact is that you use the PINB register to read the input status of the various pins in PortB. You use PORTB register to set an output pin high or low, or to turn the pull-up on or off for an input. Reading PORTB for an input pin just tells you the status of the pull-up resistor on or off!

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes,..... the while function will do the job, thanks.

 

jim also thanks for the info yes

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, time for the dumb question...or two...

I don't know which AVR you are using, so I am gonna use the Mega328 as its pretty popular, but most AVRs have the same characteristics

 

Since this is synchronous communications, WHY are you making your life so difficult?  Unless this is a school assignment and your teacher is requiring your life to be difficult.

 

The AVR has not one, but TWO SYNCHRONUS data transfer engines on it

 

The SPI engine

 

The USART engine (running in synchronous mode)

 

Either one can be the source of the clock(master), or in your case where the clock come from someplace else a slave.

 

The datasheet tells all.

 

So why, why, oh why make your life so difficult?

 

East Coast Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just one small correction in the above: By:

while((PINB & PB3)  ==  0) ; //wait here while clock is low

Jim really meant:

while((PINB & (1 << PB3))  ==  0) ; //wait here while clock is low

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:

Ok, time for the dumb question...or two...USART engine (running in synchronous mode)

So why, why, oh why make your life so difficult?

East Coast Jim

 

this is a small part of a big project, i think i need the USART & SPI later for some other things.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What AVR are you using?

 

SPI can operate as one of several 'slaves' if you know how to use it properly.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

atmega32

its a little bit complicated, but i gonna use this program for testing a another prog in a atmega 128.

later the bits are comming from a "scanner" (IR transmitter/receiver) that have as output a 300 bits bittrain.

but for testing the program in the 128 it is not easy to use this scanner, so i gonna simulate this bit train whit the atmega32.

there i want to put in a look-up table the bytes that normal coming from the scanner, and these bytes i have to shift out of the atmega32.