Go Down

Topic: Coding Question: Making a ShiftIn (Read 599 times) previous topic - next topic

Shadyman

Hey folks.

How would I go about coding something like a"ShiftIn" function? I have a "clock in" and a "data in", and I want to print the results to the serial port.

Thanks in advance!  ;D

yerg2k

Well, I didn't look around but heres one I wrote for a project of mine.

int shiftIn() {
 int cwt;
 cwt=0;
 bitmask=128;
 while (bitmask >= 1) {
   digitalWrite(shtClk, HIGH);
   cwt = cwt + bitmask * digitalRead(shtData);
   digitalWrite(shtClk, LOW);
   bitmask=bitmask/2;
 }
 return(cwt);
}

That is for MSB first, other end changes data on rising edge of the clock.

Shadyman

Hmm.. Isn't the Clock an input too?  :-/

yerg2k

Sorry, the code there is for having the microcontroller do the clocking. I've never had the need to use an external clock.

I might check to see if i2c could be used, since the avr's support this. Or, perhaps you could attach an interrupt. What are you trying to interface to?

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy