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 support@ccsinfo.com

How can I read a 16Bit Data register with SPI_READ???

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



Joined: 31 Mar 2004
Posts: 23
Location: Switzerland

View user's profile Send private message

How can I read a 16Bit Data register with SPI_READ???
PostPosted: Fri May 21, 2004 2:06 am     Reply with quote

hi

I'm triyng to read the ADC AD7705, which it has a dataregister from 16 Bits. I'm working with CCS and 18F252.
Here the code:
Code:

long int read_adc_word()
{
   long data,data1;

   output_low(ADC_CS);
   data1 = spi_read(data);
   output_high(ADC_CS);
   return data1;
}


The comand SPI-READ return only 8Bits. I'm beginner in C, can help me anybody???

Aloha, Pablo.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri May 21, 2004 2:30 am     Reply with quote

Try something like:
Code:

long int read_adc_word()
{
   int8 data_low,data_high;
   long data16;

   output_low(ADC_CS);
   data_low = spi_read(0);
   data_high= spi_read(0);
   output_high(ADC_CS);

   data16 = make16(data_high, data_low);
   return data16;
}


I don't know the AD7705, so maybe you have to swap reading the high and low bytes.
neurus



Joined: 31 Mar 2004
Posts: 23
Location: Switzerland

View user's profile Send private message

PostPosted: Fri May 21, 2004 5:21 am     Reply with quote

thanks for your answer.

Aloha Pablo
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