|
|
View previous topic :: View next topic |
Author |
Message |
morebudwiser
Joined: 17 Oct 2005 Posts: 26
|
reading serial data using shift_left |
Posted: Thu Jan 26, 2006 4:03 am |
|
|
hi i am trying to read in the contents of an 8bit [censored] register into a byte and then print the value of the bit i have tried using the code below but the value is always returned as 0 no matter what data has been read in
byte buffer[1]; //store incoming byte in buffer
for(i=0; i<=8; ++i){ // read each bit in a L to H pulse pin A2
// Wait for clock high
while (!input(PIN_A2));
shift_left(buffer,3,input(PIN_A3));
// Wait for clock low
while (input(PIN_A2));
printf (" \n\r byte value %c",buffer); //print value of buffer
} |
|
|
Ttelmah Guest
|
|
Posted: Thu Jan 26, 2006 4:20 am |
|
|
The first thing that leaps out, is the '3' in the shift. This must be changed to '1'. As it currently stands, you are potentially destroying some other variables, and the results could be anything.
The next thing, is that you are executing _9_ shifts. 0,1,2,3,4,5,6,7,8 in the counter. If nine bits are arriving, you need a two byte buffer...
The next thing, is that you print 'buffer', but 'buffer', is the name of an array (admittedly ony one byte). When you access 'buffer', the code will return the address of this array (which is what is wanted for the shift operation), and not it's contents. The printf, needs to access 'buffer[0]', to get the value held _in_ this buffer.
Best Wishes |
|
|
morebudwiser
Joined: 17 Oct 2005 Posts: 26
|
|
Posted: Thu Jan 26, 2006 5:18 am |
|
|
many thanks got it working |
|
|
Ttelmah Guest
|
|
Posted: Thu Jan 26, 2006 9:31 am |
|
|
Thanks for 'coming back'. :-)
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|