Author Topic: Simblee Communication with ADS1118  (Read 1119 times)

MRF

  • RFduino Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Simblee Communication with ADS1118
« on: November 10, 2016, 01:44:36 AM »
Hi,

I'm trying to use a Simblee to read out thermocouple values from an ADS1118 ADC.
However, I can't manage to get the communication via SPI right. I get strange/false results all the time. The result is always 32768.

Is there anybody who has experience in working with the ADS1118 and Arduino/RFduino/Simblee ?  :)

My source code is attached.

Code: [Select]
#include <SPI.h>

const int cs1 = 6;  // Chip Select on ADS1118
const int power = 1;  // Power Source for the ADS1118

void setup() {
  Serial.begin(9600);

  pinMode(cs1, OUTPUT);
  digitalWrite(cs1, HIGH);
  pinMode(power, OUTPUT);
  digitalWrite(power, HIGH);
 
  // Set up and start the SPI serial interface
  SPI.setBitOrder(MSBFIRST); // Most significant bit first
  SPI.setClockDivider(SPI_CLOCK_DIV8); // Step down the arduino clock by 8
  SPI.setDataMode(SPI_MODE1); //Serial interface timing
  SPI.begin();
}

void loop()
{
  Serial.println(readRaw());
  delay(1000);
}

/* Allows the caller to read the raw value from the ADS1118 */
int readRaw(void) {
  int rawValue; // Raw value received back from the ADS1118
  byte MSB, LSB; //The most and least significant bits read from the ADS1118
  byte MSBConf=B10001011; // Most Significant Bit configuration register
  //11010001
  byte LSBConf=B11110010; // Least Significant Bit configuration register
  //10000010


  digitalWrite(cs1, LOW);  // activate ChipSelect
  delayMicroseconds(1);   // > 100ns wait
 
  // Read the ADS1118's channel's A0 and A1 as temperature in single-shot mode
  MSB = SPI.transfer(MSBConf);
  LSB = SPI.transfer(LSBConf);
  //SPI.transfer(MSBConf);
  //SPI.transfer(LSBConf);
 
  digitalWrite(cs1, HIGH);

  // Build the raw value from the most and least significant bits
  rawValue = (MSB << 8) | LSB;

  return rawValue;
}
« Last Edit: November 10, 2016, 01:50:46 AM by MRF »

flurin4

  • RFduino Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Simblee Communication with ADS1118
« Reply #1 on: November 30, 2016, 07:08:10 AM »
Hi MSB,

I am not working with the ADS1118, but with the ADS1293 and I am also using SPI.
Are you sure about SPI mode being SPI_MODE1?

What is happening, is that your output is always 2^15 (=32'768).
So basically it returns 0 all the time, except for the first bit, which is 1.

In my system, I got it to work, by adding SPI.startTransaction() and SPI.endTransaction()
Code: [Select]
_______
(In header)
#define BitOrder    MSBFIRST
#define SPIMode    SPI_MODE0
uint8_t chipSelectPin = 6;

_______
(in function)

uint32_t UpperByte = 0;
uint16_t LowerBytes = 0;
// the 0x80 tells the sensor that I want to read (not write), then the 0x50 is the address in the sensor memory
uint8_t readAddress = (0x80 | 0x50);

// Begin Transaction and Select Sensor
SPI.beginTransaction(SPISettings(20000000, BitOrder, SPIMode));
digitalWrite(chipSelectPin, LOW);

// Tell Sensor where to READ information from
SPI.transfer(readAddress);

// Read information for 3 Bytes
// THIS IS A 24bit VALUE
UpperByte = SPI.transfer(0x00);
LowerBytes = ( (uint16_t) SPI.transfer(0x00) << 8) | (uint8_t) SPI.transfer(0x00);

// Deselect Sensor and End Transaction
digitalWrite(chipSelectPin, HIGH);
SPI.endTransaction()

  • Why are you delaying it by 1000ns or 1microsecond? Follow precisely whatever is explained in the datasheet.
  • In such applications, where the actual size of your data is quite relevant, I would suggest to TELL specify what data size to use (int16_t or similar, instead of int/byte/char etc.), as this could work differently on another system!
  • This could maybe explain an error you are getting from bit-shifting your MSB before saving it to rawValue.

gouthampal

  • RFduino Newbie
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Simblee Communication with ADS1118
« Reply #2 on: January 15, 2017, 12:21:13 PM »
Hi, I'm trying to do the same with ldc1101.
Could you specify which spi.h file you are using?
is it the one on rfduino library or is it the default arduino spi.h

tolson

  • Global Moderator
  • *****
  • Posts: 854
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: Simblee Communication with ADS1118
« Reply #3 on: January 15, 2017, 01:53:38 PM »
Simblee SPI library is at...
<Arduino Path to>/Simblee/hardware/Simblee/1.1.0/libraries/SPI


MRF

  • RFduino Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Simblee Communication with ADS1118
« Reply #4 on: January 15, 2017, 11:29:19 PM »
Hello,

I got it working! :)
For everyone with similar Problems with SPI, here is a chunk of my Code, maybe it will help you:

Code: [Select]
#include <SPI.h>         // SPI

// SPI init
SPISettings ADS1118(SPI_CLOCK_DIV4, MSBFIRST, SPI_MODE1);
const int cs1 = 6;  // Chip Select 1

struct myPacket // struct myPacket
{
  uint16_t rawData[4];  // for raw temperature data             4*2 = 8 Byte
  long rawTemp[2];      // for cold junction temperature  2*4 = 8 Byte --> 16 Byte
};
struct myPacket packet; // defines paket so send

// Config Register ADS1118
/* * Bit 15:    1   - Start a single conversion / Always read back as 0 (default)
   * Bit 14-12: 000 - Multiplexer AIN0(Pos.) and AIN1(Neg.)
   * Bit 11-09: 010 - FSR +- 2.048 VDC (default)
   *            101 - FSR +- 0.256 VDC
   * Bit 08:    1   - Power Down & Single shot (default)
   *            0   - Continuous Conversion mode
   * Bit 07-05: 100 - 128 SPS (default)
   *            111 - 860 SPS
   * Bit 04:    0   - ADC Mode (default)
   *            1   - Temperature sensor mode
   * Bit 03:    0   - Pull-up on DOUT disabled
   *            1   - Pull-up on DOUT enabled (default)
   * Bit 02-01: 01  - Valid data / Update config register (default)
   * Bit 00:    1   - Not used / Reserved */

void setup()
{
  SPISettings ADS1118(SPI_CLOCK_DIV4, MSBFIRST, SPI_MODE1); // SPI init
  SPI.begin();                   
  pinMode(cs1, OUTPUT);
  digitalWrite(cs1, HIGH);
  delay(2);
 
  SPI.beginTransaction(ADS1118);  // ADS1118 init
  digitalWrite(cs1, LOW);         // activate ChipSelect
  SPI.transfer(0b10001111);
  SPI.transfer(0b11111010);
  SPI.transfer(0);
  SPI.transfer(0);
  digitalWrite(cs1, HIGH);
  SPI.endTransaction();
  delay(2);
}
   
void loop()
{   
    Simblee_ULPDelay(SECONDS(30));
    readTemp();
}

//-------------------------------------------

float readTemp()
{
  SPI.beginTransaction(ADS1118);
  digitalWrite(cs1, LOW);  // activate ChipSelect
  // intern temperature ( cold junction )
  byte DataMSB = SPI.transfer(0b10001111); 
  byte DataLSB = SPI.transfer(0b11101010);
  byte ConfigMSB = SPI.transfer(0);
  byte ConfigLSB = SPI.transfer(0);
  digitalWrite(cs1, HIGH);
  SPI.endTransaction();
  delay(2);
  // Build the raw value from the most and least significant bits
  word Data = (DataMSB << 8) | DataLSB;
  packet.rawTemp[0] = (Data >> 2) * 31.25;

  SPI.beginTransaction(ADS1118);
  digitalWrite(cs1, LOW);  // activate ChipSelect
  // measure channel A0 und A1 in Single-Shot-Mode
  DataMSB = SPI.transfer(0b10111111);
  DataLSB = SPI.transfer(0b11101010);
  ConfigMSB = SPI.transfer(0);
  ConfigLSB = SPI.transfer(0);
  digitalWrite(cs1, HIGH);
  SPI.endTransaction();
  delay(2);
  // Build the raw value from the most and least significant bits
  packet.rawData[0] = (DataMSB << 8) | DataLSB;

  SPI.beginTransaction(ADS1118);
  digitalWrite(cs1, LOW);  // activate ChipSelect
  // measure channel A2 und A3 in Single-Shot-Mode
  DataMSB = SPI.transfer(0b10001111);
  DataLSB = SPI.transfer(0b11111010);
  ConfigMSB = SPI.transfer(0);
  ConfigLSB = SPI.transfer(0);
  digitalWrite(cs1, HIGH);
  SPI.endTransaction();
  delay(2);
  // Build the raw value from the most and least significant bits
  packet.rawData[1] = (DataMSB << 8) | DataLSB;
}

 

anything