| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| neurus 
 
 
 Joined: 31 Mar 2004
 Posts: 23
 Location: Switzerland
 
 
			    
 
 | 
			
				| How can I read a 16Bit Data register with SPI_READ??? |  
				|  Posted: Fri May 21, 2004 2:06 am |   |  
				| 
 |  
				| 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
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Fri May 21, 2004 2:30 am |   |  
				| 
 |  
				| 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
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Fri May 21, 2004 5:21 am |   |  
				| 
 |  
				| thanks for your answer. 
 Aloha Pablo
 |  | 
	
		|  | 
	
		|  |