CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

reading serial data using shift_left

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
morebudwiser



Joined: 17 Oct 2005
Posts: 26

View user's profile Send private message

reading serial data using shift_left
PostPosted: Thu Jan 26, 2006 4:03 am     Reply with quote

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







PostPosted: Thu Jan 26, 2006 4:20 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jan 26, 2006 5:18 am     Reply with quote

many thanks got it working
Ttelmah
Guest







PostPosted: Thu Jan 26, 2006 9:31 am     Reply with quote

Thanks for 'coming back'. :-)

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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