Pages: [1]   Go Down
Author Topic: Coding Question: Making a ShiftIn  (Read 447 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 81
everywhen
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 81
everywhen
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Pages: [1]   Go Up
Jump to: