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

Having trouble using PIC16F1828 to communicate with ADS1255.
Goto page 1, 2, 3, 4  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
axb1993



Joined: 28 May 2014
Posts: 2

View user's profile Send private message

Having trouble using PIC16F1828 to communicate with ADS1255.
PostPosted: Wed May 28, 2014 8:04 am     Reply with quote

I'm trying to use a PIC16F1828 to talk to a ADS1255 analog-to-digital converter. Programming isn't exactly my forte, so I have mainly been doing this through trial an error. All I need is to be able to read from the status register of the ADS1255 and then I can move on from that point. Any help on this would be greatly appreciated.

http://www.ti.com/lit/ds/symlink/ads1255.pdf
http://ww1.microchip.com/downloads/en/DeviceDoc/40001419E.pdf

Code:
#include <ES_SPI.h>

void main()
{
setup_oscillator(OSC_INTRC);
setup_spi(SPI_MASTER | SPI_L_TO_H);
output_low(PIN_A5);
spi_write(ADS1255_RREG);
spi_write(0x00);
output_high(PIN_A5);
output_low(PIN_A5);
spi_write(ADS1255_RDATA);
output_high(PIN_A5);
}


Code:
#include <16F1829.h>
#device ADC=16
#FUSES INTRC_IO
#use delay(internal = 30000000)
#use SPI(MASTER, DI=PIN_B4, DO=PIN_C7, CLK=PIN_B6,MODE=1, BITS=8, LSB_FIRST)

#define DELAY                   500
#define SPI_MASTER              0x20
#define SPI_L_TO_H              0x10
#define SPI_CLK_DIV_16          0x01
#define ADS1255_RDATA           0x01    //Read Data
#define ADS1255_RDATAC          0x03    //Read Data Continuously
#define ADS1255_SDATAC          0x0f    //Stop Read Data Continuously
#define ADS1255_RREG            0x10    //Read from REG rrr 0001 rrrr (1xh) 0000 nnnn
#define ADS1255_WREG            0x50    //Write to REG rrr 0101 rrrr (5xh) 0000 nnnn
#define ADS1255_SELFCAL         0xf0    //Offset and Gain Self-Calibration
#define ADS1255_SELFOCAL        0xf1    //Offset Self-Calibration
#define ADS1255_SELFGCAL        0xf2    //Gain Self-Calibration
#define ADS1255_SYSOCAL         0xf3    //System Offset Calibration
#define ADS1255_SYSGCAL         0xf4    //System Gain Calibration
#define ADS1255_SYNC            0xfc    //Synchronize the A/D Conversion
#define ADS1255_STANDBY         0xfd    //Begin Standby Mode
#define ADS1255_RESET           0xfe    //Reset to Power-Up Values
#define ADS1255_WAKEUP          0xff    //Completes SYNC and Exits Standby Mode

//ADS1255 REGISTER MAP
#define ADS1255_STATUS          0x00    //STATUS REGISTER (ADDRESS 00h)
#define ADS1255_MUX             0x01    //Input Multiplexer Control Register (Address 01h)
#define ADS1255_ADCON           0x02    //A/D Control Register (Address 02h)
#define ADS1255_DRATE           0x03    //A/D Data Rate (Address 03h)
#define ADS1255_IO              0x04    //GPIO Control Register (Address 04H)
#define ADS1255_OFC0            0x05    //Offset Calibration Byte 0, least significant byte (Address 05h)
#define ADS1255_OFC1            0x06    //Offset Calibration Byte 1 (Address 06h)
#define ADS1255_OFC2            0x07    //Offset Calibration B
[/url]
Ttelmah



Joined: 11 Mar 2010
Posts: 19467

View user's profile Send private message

PostPosted: Wed May 28, 2014 11:18 am     Reply with quote

Several things:

Get rid of LSB first in your SPI setup.
The default for the chip is MSB first, and the chip _requires_ it's configuration data is sent in this order. It has an option to return the data configured LSB first, but the SPI is still handled LSB first, it is just the configuration of the data in the returned word that changes.

Then what clock rates are supported by the internal RC clock?. 30MHz _is not_ one of them..... You can only use rates that are supported by the hardware.

Then you need to be reading the DRDY line from the chip. Sequence is trigger a conversion, wait for DRDY, then read the result. You are not doing this.

Then get rid of the defines for SPI_MASTER etc.. These are specific to the chip, and already defined in the processor include file. You shouldn't define these yourself.
axb1993



Joined: 28 May 2014
Posts: 2

View user's profile Send private message

PostPosted: Wed May 28, 2014 11:59 am     Reply with quote

Thanks for replying.

I changed the LSB setup to MSB. I'm not sure about the internal clock speed, I've changed that numerous times without seeing any obvious changes. And I'm not sure I understand exactly what you mean about reading the DRDY line. I changed my code a little and by using a logic analyzer I was able to read some data from the ADS1255. However I don't think it's what I am looking for since I can change what I write to the device without seeing a difference in data read. Maybe this has something to do with the DRDY?

Code:
#include <ES_SPI.h>

void main()
{
setup_oscillator(OSC_INTRC);
setup_spi(SPI_MASTER | SPI_L_TO_H);

   while(TRUE)    {
     
      output_low(PIN_A5);
      spi_write(0x10);
      spi_write(0x01);
      spi_write(0x00);
      spi_read(0x00);
      output_high(PIN_A5);
      output_low(PIN_A5);
      spi_write(0x01);
      spi_read(0x00);
      spi_read(0x00);
      spi_read(0x00);
      output_high(PIN_A5);
   }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19467

View user's profile Send private message

PostPosted: Thu May 29, 2014 2:03 am     Reply with quote

No guarantees. I've just put this together from the data sheet. It should wait for half a second, force a self calibrate, then loop taking a reading from the chip every half second.
It shows the critical things though - how to use the SPI (you are mixing two ways of using the SPI, and then using the wrong pins for the mode you are trying to use). You also need to get the clock rate into the range supported by the chip - I've used the hardware SPI and ensured this. and finally using DRDY to verify that data _is_ ready before trying to read. Also how to use different length data transfers (since the data is 24bit), and how to convert this into a signed int32.

es_spi.h
Code:

#include <16F1829.h>
#device ADC=16
#FUSES INTRC_IO
#use delay(internal = 32000000)

#define ADS1255_RDATA           0x01    //Read Data
#define ADS1255_RDATAC          0x03    //Read Data Continuously
#define ADS1255_SDATAC          0x0f    //Stop Read Data Continuously
#define ADS1255_RREG            0x10    //Read from REG rrr 0001 rrrr (1xh) 0000 nnnn
#define ADS1255_WREG            0x50    //Write to REG rrr 0101 rrrr (5xh) 0000 nnnn
#define ADS1255_SELFCAL         0xf0    //Offset and Gain Self-Calibration
#define ADS1255_SELFOCAL        0xf1    //Offset Self-Calibration
#define ADS1255_SELFGCAL        0xf2    //Gain Self-Calibration
#define ADS1255_SYSOCAL         0xf3    //System Offset Calibration
#define ADS1255_SYSGCAL         0xf4    //System Gain Calibration
#define ADS1255_SYNC            0xfc    //Synchronize the A/D Conversion
#define ADS1255_STANDBY         0xfd    //Begin Standby Mode
#define ADS1255_RESET           0xfe    //Reset to Power-Up Values
#define ADS1255_WAKEUP          0xff    //Completes SYNC and Exits Standby Mode

//ADS1255 REGISTER MAP
#define ADS1255_STATUS          0x00    //STATUS REGISTER (ADDRESS 00h)
#define ADS1255_MUX             0x01    //Input Multiplexer Control Register (Address 01h)
#define ADS1255_ADCON           0x02    //A/D Control Register (Address 02h)
#define ADS1255_DRATE           0x03    //A/D Data Rate (Address 03h)
#define ADS1255_IO              0x04    //GPIO Control Register (Address 04H)
#define ADS1255_OFC0            0x05    //Offset Calibration Byte 0, least significant byte (Address 05h)
#define ADS1255_OFC1            0x06    //Offset Calibration Byte 1 (Address 06h)
#define ADS1255_OFC2            0x07    //Offset Calibration B


es_spi.c
Code:

#include <ES_SPI.h> //include processor defintition and register names

#use SPI(MASTER, SPI1, MODE=1, BITS=24, baud=2000000, STREAM=ADS) //main data transfer is 24bits
/* Chip needs the following wiring.
PIC   ADS
C0    18    SCL
C1    16    Data in to PIC
C2    17    Data out from PIC
B7    15    Data ready signal from ADS - put this on any pin you want
A7    14    Chip select to ADS

The specified SPI baud rate supported by the chip, is to 550KHz to 2.4Mhz. You need to be inside this.
Hence specifying 2Mhz.
*/
#define DRDY PIN_B7 //see above
#define CS PIN_A5

void write_command(int8 val)
{
   //single command write, leaving the chip still selected
   output_low(CS); //select chip
   spi_xfer(ADS,val,1); //Issue the command
}

signed int32 read_data()
{
   int32 value=0;
   //read 24bit result from chip - page 34 on data sheet
   //First wait for DRDY to drop
   while (input(DRDY)) ;
   //get here when DRDY drops   
   write_command(ADS1255_RDATA); //Issue the read command
   //Now need to read 24bit result
   value=spi_xfer(ADS,0,24); //read 24bits
   //now need to convert 24bit signed to 32bit
   output_high(CS); //deselect chip after read
   if (BIT_TEST(value,23))
      value=value | 0xFF000000;
   else
      value=value & 0x007FFFFF;
   return value;
}   

void write_regs(int8 reg_no, int8 num_bytes, int8 * data_ptr)
{
   //generic function to write to one or more registers on the ADS
   //Command to chip is 0101 reg_num 0000 num_bytes, then the bytes to send
   output_low(CS); //select chip
   reg_no&=0xF; //ensure reg_no is 15 max
   num_bytes&=0xF; //same for number of bytes
   spi_xfer(ADS, 0x50 | reg_no, 1); //send first byte
   spi_xfer(ADS, (num_bytes-1), 1); //number of bytes to write less one
   //Now send the data
   while (num_bytes)
   {
      spi_xfer(ADS, data_ptr[num_bytes--], 1); //send each byte
   }
   output_high(CS); //and deselect
}
 

int8 read_reg(int8 reg_no)
{
   int8 rval;
   //generic read function just for a single register
   output_low(CS); //select chip
   reg_no&=0xF; //ensure reg_no is 15 max   
   spi_xfer(ADS, 0x10 | reg_no, 1); //send first byte
   spi_xfer(ADS, 0, 1); //read one byte
   rval=spi_xfer(ADS,0,1); //Clock data back
   output_high(CS);
   return rval;
}
   
void main()
{
   signed int32 result;
   setup_oscillator(OSC_INTRC|OSC_8MHZ|OSC_PLL_ON); //Shouldn't be needed but here 'in case'

   output_high(CS); //ensure chip select starts high
   //wait for supply to fully stabilise
   delay_ms(500);
   write_command(ADS1255_SELFCAL);
   //self calibrate
   write_command(ADS1255_STANDBY);
   output_high(CS); //and deselect   
   
   //Now the chip is here in 'standby' mode, so to perform a conversion, you have to wake it,
   //then wait for DRDY, before issuing RDATA, and reading the reply.
   do
   {
      write_command(ADS1255_WAKEUP); //issue the wakeup command
      //now wait for DRDY, and read the data
      result=read_data();
      //Now put the chip to sleep
      write_command(ADS1255_STANDBY);
      output_high(CS); //and deselect the chip
      //here you should have a signed int32 reading in 'result'
      delay_ms(500);     
   }
   while (TRUE);
}
olet96



Joined: 09 Jul 2014
Posts: 16

View user's profile Send private message

PostPosted: Wed Jul 09, 2014 10:15 am     Reply with quote

Hi and thank you for the code! We have gotten it to read data however the data doesn't seem to be correct or consistent we have a 2.5 volt reference and are connected to the input with 120 ohm resistors from our weight stone bridge. We are using your code exactly except for the while do section, and we were also unsure why you where oring the value and 0x0FF000000 together. Here is the section of code we changed.

Code:

 do
   {
      write_command(ADS1255_WAKEUP); //issue the wakeup command
      //now wait for DRDY, and read the data
      result=read_data();
      double result2=result*0.000000149011;
      //Now put the chip to sleep
      write_command(ADS1255_STANDBY);
      output_high(CS); //and deselect the chip
      //here you should have a signed int32 reading in 'result'


      printf("DATA:%1.8f\n\r",result2);
     
      delay_ms(500);     
   }
   while (TRUE);
}
temtronic



Joined: 01 Jul 2010
Posts: 9207
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jul 09, 2014 10:55 am     Reply with quote

hmmmm...
We have gotten it to read data however the data doesn't seem to be correct or consistent

For initial test purposes you MUST use a stable, known input to the ADC. Typically 3 or 4 values from a resistor divider from the Vref of 2.5000. This allows you to KNOW what the input is.

Since we don't know your analog circuit, there could be noise, EMI, etc. When discussing 'wrong data', you should post the numbers (expected vs readings). You might even have a 'math' issue. Normally you printout the raw ADC results to confirm the ADC/ analog front end are working corectly THEN do the 'math' to make the numbers 'pretty'.

hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19467

View user's profile Send private message

PostPosted: Wed Jul 09, 2014 11:27 am     Reply with quote

The chip returns a 24bit value.
The PIC does not support this, so it has to be converted to a 32bit value.
For the positive values, (those with bit 23 not set), you can just use the low 23 bits. For those with bit 23 set, you need to set all the high eight bits in the value to convert to 32 bits. This is what the 'OR' does.
Search online for how to convert a signed 24bit number to a signed 32bit number, and you should find basically the same code.

As a separate comment, deselect the chip, _then_ do the multiplication.

The bridge name is Wheatstone. It's the inventors name. Not weight stone.
olet96



Joined: 09 Jul 2014
Posts: 16

View user's profile Send private message

PostPosted: Wed Jul 09, 2014 1:21 pm     Reply with quote

Okay so I did an experiment using four different resistor values in place of my strain gauge to test the system and recorded all of the data in an excel sheet and when I ran the program I found the same results as before and also noticed that no matter what resistor value I plugged in the data from the PIC would be the same. Here is the schematic along with the excel sheet and the data from the PIC. Also the data collected was with the 10 ohm resistor in the circuit. I've been looking through the code, and can't seem to find whats wrong. Im not really sure where to go at this point?

In the spreadsheet the measured voltage values were measured with a multimeter.

Excel Sheet
Schematic
PIC Data
temtronic



Joined: 01 Jul 2010
Posts: 9207
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jul 09, 2014 1:44 pm     Reply with quote

hmm... the ADC chip is a 3Volt device, what is the PIC's VDD ?

also I don't see any PIC data....

and you should printout BOTH the RAW data from the device as well as your 'result2' value.


jay
olet96



Joined: 09 Jul 2014
Posts: 16

View user's profile Send private message

PostPosted: Wed Jul 09, 2014 2:45 pm     Reply with quote

The VDD on the PIC is 5 volts and the ADC SPI is 5 volt tolerant. As far as the data I was looking at in the serial monitor goes I was printing the result data not the result2 data and when I was referring to PIC data I just meant the data I was sending to the serial monitor from the PIC. Here is the full schematic and the serial monitor data for both result and result2 result is the DATA and result2 is the DATA2. Also here is the changed code I've been running.
Code:

do
   {
      write_command(ADS1255_WAKEUP); //issue the wakeup command
      //now wait for DRDY, and read the data
      result=read_data();

      //Now put the chip to sleep
      write_command(ADS1255_STANDBY);
      output_high(CS); //and deselect the chip
      //here you should have a signed int32 reading in 'result'
      double result2=result*0.000000149011;

      printf("DATA:%ld\n\r",result);
      printf("DATA2:%1.8f\n\r",result2);     
      delay_ms(500);     
   }
   while (TRUE);
}

Full Schematic
Serial monitor[/code]
temtronic



Joined: 01 Jul 2010
Posts: 9207
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jul 09, 2014 3:34 pm     Reply with quote

SPI tolerant means the ADC will run with 5V on it's pins, it's the data to PIC than can be the problem.
Others who use SPI devices will know but I think SPI pins are ST types , needing 80% VDD to be a logic high. If so 80% of 5V is 4 volts, and your ADC can't output more than say 3.6V.
All this is from memory, I'd have to DL your PICs datasheet to confirm my thinking but it would explain the trouble.
I've never liked the mixed power supply levels for projects, either all 5V or all 3V, as it greatly simplifies 'operational details'.

jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 09, 2014 4:39 pm     Reply with quote

I don't like your trouble-shooting methodology. I don't like your display
of raw data in decimal. It conceals too much. For example,

If I convert the first 5 samples from your decimal values to hex, I get this:
Code:

FD20
D620
D920
F220
E120

That's disturbing. It looks like 12-bit signed data, left-justified in a 16-bit
word. Not what would I expect from a 24-bit signed output device.

I would get rid of the whole Wheatstone bridge/ strain gauge apparatus
and peg the differential inputs with 0v and 5v (Ain0 and Ain1), and then
reverse them (5v and 0v on Ain0 and Ain1). Then run some conversions
and make sure you're getting the correct 24-bit results for those input voltages.

I would get rid of the floating point math entirely, until I nailed down the
correct operation of the device.

Also you are doing stuff like this (below), where you are declaring a
variable in the middle of code. That might work in C++, but CCS doesn't
explicitly say you can do it. You should declare variables at the beginning
of a function in CCS. Read this description:
http://stackoverflow.com/questions/8474100/where-you-can-and-cannot-declare-new-variables-in-c
CCS is not specified as C99 compatible. So you can't (safely) put
variable declarations in the middle of a block.
Quote:
do
{
write_command(ADS1255_WAKEUP); //issue the wakeup command
//now wait for DRDY, and read the data
result=read_data();

//Now put the chip to sleep
write_command(ADS1255_STANDBY);
output_high(CS); //and deselect the chip
//here you should have a signed int32 reading in 'result'
double result2=result*0.000000149011;




This part below in main() is potentially a problem. Selfcal takes a
specified time (dependent upon PGA and data rate) to complete.
You can put in a fixed delay or you can poll DRDY to check for completion.
You don't have that in your code. According to the ads1255 data sheet,
Quote:
The standby mode shuts down all of the analog circuitry
and most of the digital features.

It's possible that you are prematurely halting the Selfcal process before
it completes. I mean, if all analog circuits are shut down, how can it
do the Selfcal process ? So this part of the code should be looked at.

With the default data rate of 30,000 and the default PGA of 1, and a
clkin of 7.68 MHz, the calibration delay is 417us. So, you might just
try a fixed delay of 500us after sending the Selfcal command.
Or make it 1 ms, to be safe.
Quote:

void main()
{
signed int32 result;
setup_oscillator(OSC_INTRC|OSC_8MHZ|OSC_PLL_ON); //Shouldn't be needed but here 'in case'

output_high(CS); //ensure chip select starts high
//wait for supply to fully stabilise
delay_ms(500);
write_command(ADS1255_SELFCAL);
//self calibrate
write_command(ADS1255_STANDBY);
output_high(CS); //and deselect


--------------------------------------------
*** Important ***

Re-reading this thread, I just caught Temtronics point about SPI interface
voltage levels. You said this:
Quote:
The VDD on the PIC is 5 volts

That's a fail with the 3.3v digital interface on the ADS chip. The ADS chip
puts out a 3.3v signal which goes to the MISO pin on the PIC. But the
PIC, running SPI hardware at a +5v Vdd, requires a Vih of +4v on the
MISO pin. So it's not going to work. This is likely the major problem with
your project. It's probably why your data looks funky.

One solution is to run the SPI in software mode. Add FORCE_SW to the
#use spi() statement. Then the MISO pin becomes a TTL input pin
with a Vih requirement of +2.0v, and it works fine with the 3.3v signal
coming from the ADS chip. The 5v signals going from the PIC to the
ADS chip are OK, because the ADS chip's SPI interface is 5v tolerant.
Ttelmah



Joined: 11 Mar 2010
Posts: 19467

View user's profile Send private message

PostPosted: Thu Jul 10, 2014 2:03 am     Reply with quote

Yes.

'5v tolerant', means a pin on a low voltage device, can stand being driven by a 5v device without damage. It does not mean it can drive an input on a 5v device....

However one thing not asked, is why you are running the PIC off 5v?.
The PIC you are using supports operation up to 32MHz off 2.5v or higher. Your interface would suddenly become easy, if the PIC is running at 3.3v as well....
There are 3.3v versions of the MAX232 (Max 3232), so the whole circuit only needs one supply.
olet96



Joined: 09 Jul 2014
Posts: 16

View user's profile Send private message

PostPosted: Thu Jul 10, 2014 9:42 am     Reply with quote

I have changed my PIC VDD to 3.3v and also eliminated the Wheatstone Bridge by removing R4 and R5 and soldered wires to the inputs of the chip. I then was able to apply 0v and +3.3v to AIN0 and AIN1. In the code I added a 1ms delay after SELFCAL and removed the declared variable in the do while all together and began printing RAW DATA directly after it was red from the ADC. I then ran the code and switched the inputs from 0v-3.3v, 3.3v-0v, and 0v-0v and noticed I was getting some kind of change in the data but it didn't seem consistent and also only the 4 LSBs seemed to change.

Code:

#include <SPI.h> //include processor definition and register names

#use SPI(MASTER, SPI1, MODE=1, BITS=24, baud=2000000, STREAM=ADS) //main data transfer is 24bits
/* Chip needs the following wiring.
PIC   ADS
C0    18    SCL
C1    16    Data in to PIC
C2    17    Data out from PIC
B7    15    Data ready signal from ADS - put this on any pin you want
A7    14    Chip select to ADS

The specified SPI baud rate supported by the chip, is to 550KHz to 2.4Mhz. You need to be inside this.
Hence specifying 2Mhz.
*/
#define DRDY PIN_A4 //see above
#define CS PIN_A5

void write_command(int8 val)
{
   //single command write, leaving the chip still selected
   output_low(CS); //select chip
   spi_xfer(ADS,val,1); //Issue the command
}

signed int32 read_data()
{
   int32 value=0;
   //read 24bit result from chip - page 34 on data sheet
   //First wait for DRDY to drop
   while (input(DRDY)) ;
   //get here when DRDY drops   
   write_command(ADS1255_RDATA); //Issue the read command
   //Now need to read 24bit result
   value=spi_xfer(ADS,0,24); //read 24bits
   //now need to convert 24bit signed to 32bit
   output_high(CS); //deselect chip after read
   printf("RAW DATA: 0x%08lx \n\r",value);
   if (BIT_TEST(value,23))
      value=value | 0xFF000000;
   else
      value=value & 0x007FFFFF;
     //value=value/0.00000014;
   return value;
   
}   

void write_regs(int8 reg_no, int8 num_bytes, int8 * data_ptr)
{
   //generic function to write to one or more registers on the ADS
   //Command to chip is 0101 reg_num 0000 num_bytes, then the bytes to send
   output_low(CS); //select chip
   reg_no&=0xF; //ensure reg_no is 15 max
   num_bytes&=0xF; //same for number of bytes
   spi_xfer(ADS, 0x50 | reg_no, 1); //send first byte
   spi_xfer(ADS, (num_bytes-1), 1); //number of bytes to write less one
   //Now send the data
   while (num_bytes)
   {
      spi_xfer(ADS, data_ptr[num_bytes--], 1); //send each byte
   }
   output_high(CS); //and deselect
}
 

int8 read_reg(int8 reg_no)
{
   int8 rval;
   //generic read function just for a single register
   output_low(CS); //select chip
   reg_no&=0xF; //ensure reg_no is 15 max   
   spi_xfer(ADS, 0x10 | reg_no, 1); //send first byte
   spi_xfer(ADS, 0, 1); //read one byte
   rval=spi_xfer(ADS,0,1); //Clock data back
   output_high(CS);
   return rval;
}
   
void main()
{  //double result2;
   signed int32 result;
   //setup_oscillator(OSC_INTRC|OSC_8MHZ|OSC_PLL_ON); //Shouldn't be needed but here 'in case'

   output_high(CS); //ensure chip select starts high
   //wait for supply to fully stabilise
   delay_ms(500);
   write_command(ADS1255_SELFCAL);
   delay_ms(1);
   //self calibrate
   write_command(ADS1255_STANDBY);
   output_high(CS); //and deselect
   
 
   
   //Now the chip is here in 'standby' mode, so to perform a conversion, you have to wake it,
   //then wait for DRDY, before issuing RDATA, and reading the reply.
   do
   {
      write_command(ADS1255_WAKEUP); //issue the wakeup command
      //now wait for DRDY, and read the data
      //delay_ms(1);
      result=read_data();

      //Now put the chip to sleep
      write_command(ADS1255_STANDBY);
      output_high(CS); //and deselect the chip
      //here you should have a signed int32 reading in 'result'
       //result2=result*0.000000149011;

      //printf("DATA:%lX\n\r",result);
      //printf("DATA2:%lX\n\r",result2);     
      delay_ms(500);     
   }
   while (TRUE);
}


here is some of the values I have been getting from the serial monitor.

Code:

AIN0 at 3.3V, AIN1 at 0v.       

                                                                                                                                                                                                             
     RAW DATA: 0x6700e2ff                                                                                                                                                                                           
     RAW DATA: 0x6700e7ff                                                                                                                                                                                         
     RAW DATA: 0x6700d5ff                                                                                                                                                                                         
     RAW DATA: 0x6700e3ff                                                                                                                                                                                         
     RAW DATA: 0x6700f5ff                                                                                                                                                                                         
     RAW DATA: 0x6700feff                                                                                                                                                                                         
     RAW DATA: 0x6700d3ff                                                                                                                                                                                         
     RAW DATA: 0x6700ccff                                                                                                                                                                                         
     RAW DATA: 0x6700f4ff                                                                                                                                                                                         
     RAW DATA: 0x6700eaff                                                                                                                                                                                         
     RAW DATA: 0x6700feff                                                                                                                                                                                         
     RAW DATA: 0x6700eeff                                                                                                                                                                                         
     RAW DATA: 0x6700d2ff                                                                                                                                                                                         
     RAW DATA: 0x6700f0ff                                                                                                                                                                                         
     RAW DATA: 0x6700d3ff                                                                                                                                                                                         
     RAW DATA: 0x6700f1ff                                                                                                                                                                                         
     RAW DATA: 0x6700cfff                                                                                                                                                                                         
     RAW DATA: 0x6700f6ff

AIN0 at 0V, AIN1 at 3.3V


     RAW DATA: 0x6700c7ab                                                                                                                                                                                         
     RAW DATA: 0x6700f0ab                                                                                                                                                                                         
     RAW DATA: 0x6700f9ab                                                                                                                                                                                         
     RAW DATA: 0x6700c7ab                                                                                                                                                                                         
     RAW DATA: 0x6700d5ab                                                                                                                                                                                         
     RAW DATA: 0x6700edab                                                                                                                                                                                         
     RAW DATA: 0x6700f7ab                                                                                                                                                                                         
     RAW DATA: 0x6700feab                                                                                                                                                                                         
     RAW DATA: 0x6700f6ab                                                                                                                                                                                         
     RAW DATA: 0x6700deab                                                                                                                                                                                         
     RAW DATA: 0x6700fbab                                                                                                                                                                                         
     RAW DATA: 0x6700d0ab                                                                                                                                                                                         
     RAW DATA: 0x6700d3ab                                                                                                                                                                                         
     RAW DATA: 0x6700eaab                                                                                                                                                                                         
     RAW DATA: 0x6700efab                                                                                                                                                                                         
     RAW DATA: 0x6700e4ab                                                                                                                                                                                         
     RAW DATA: 0x6700edab                                                                                                                                                                                         
     RAW DATA: 0x6700f4ab

AIN0 at 0v, AIN1 at 0v

     RAW DATA: 0x6700de00                                                                                                                                                                                         
     RAW DATA: 0x6700f100                                                                                                                                                                                         
     RAW DATA: 0x6700e100                                                                                                                                                                                         
     RAW DATA: 0x6700fa00                                                                                                                                                                                         
     RAW DATA: 0x6700f500                                                                                                                                                                                         
     RAW DATA: 0x6700f000                                                                                                                                                                                         
     RAW DATA: 0x6700f800                                                                                                                                                                                         
     RAW DATA: 0x6700f600                                                                                                                                                                                         
     RAW DATA: 0x6700fe00                                                                                                                                                                                         
     RAW DATA: 0x6700ef00                                                                                                                                                                                         
     RAW DATA: 0x6700e300                                                                                                                                                                                         
     RAW DATA: 0x6700e900                                                                                                                                                                                         
     RAW DATA: 0x6700f900                                                                                                                                                                                         
     RAW DATA: 0x6700ef00                                                                                                                                                                                         
     RAW DATA: 0x6700ea00                                                                                                                                                                                         
     RAW DATA: 0x6700fc00                                                                                                                                                                                         
     RAW DATA: 0x6700ed00                                                                                                                                                                                         
     RAW DATA: 0x6700f600


 
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 10, 2014 10:15 am     Reply with quote

Can you post your CCS compiler version ? The version is given at the
top of the .LST file. It will be a number such as 5.026, or 4.141, etc.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3, 4  Next
Page 1 of 4

 
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