my arduino is only outputting as much of a negitive number as it can output pins were changed for port f7 for cs the other pins were changed for a arduino micro
//A0-A7 are analog A0 = F7
//LTC2400 24bit ADC Module
//
//Application Demo: 7 digit voltmeter
//24bit ADC IC: LTC2400
//4.096 precision reference: TI REF3040
//
//By coldtears electronics
//
//LTC2400 code is adapted from Martin Nawrath
//Kunsthochschule fuer Medien Koeln
//Academy of Media Arts Cologne
//
#include <Stdio.h>
#include<stdlib.h>//not in other one should run diff kdiff
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
#define LTC_CS 7 // LTC2400 Chip Select Pin on Portb 2 //change pin here arduino or port x pin # 7 if A0
#define LTC_MISO 3 // LTC2400 SDO Select Pin on Portb 4 //changed to 3
#define LTC_SCK 1 // LTC2400 SCK Select Pin on Portb 5 //changed to 1
void setup() {
cbi(PORTB, LTC_SCK); // LTC2400 SCK low //keywords PORTB change if it is PORTA
sbi (DDRF, LTC_CS); // LTC2400 CS HIGH //keywords DDRB change if it is DDRBf
cbi (DDRB, LTC_MISO);
sbi (DDRB, LTC_SCK);
Serial.begin(38400);
// init SPI Hardware
sbi(SPCR, MSTR) ; // SPI master mode
sbi(SPCR, SPR0) ; // SPI speed
sbi(SPCR, SPR1); // SPI speed
sbi(SPCR, SPE); //SPI enable
//Serial.println("LTC2400 ADC Test");
}
float volt;
float v_ref = 4.096; // Reference Voltage, 5.0 Volt for LT1021 or 3.0 for LP2950-3 4.14
//was 4.094 to 4.96 REF3040 (4.096 V)
long int ltw = 0; // ADC Data ling int
int cnt; // counter
byte b0; //
byte sig; // sign bit flag
char st1[20]; // float voltage text
/********************************************************************/
void loop() {
cbi(PORTF, LTC_CS); // LTC2400 CS Low
delayMicroseconds(1);
if (!(PINB & (1 << 4))) { // ADC Converter ready ?
// cli();
ltw = 0;
sig = 0;
b0 = SPI_read(); // read 4 bytes adc raw data with SPI
if ((b0 & 0x20) == 0) sig = 1; // is input negative ?
b0 &= 0x1F; // discard bit 25..31
ltw |= b0;
ltw <<= 8;
b0 = SPI_read();
ltw |= b0;
ltw <<= 8;
b0 = SPI_read();
ltw |= b0;
ltw <<= 8;
b0 = SPI_read();
ltw |= b0;
delayMicroseconds(1);
sbi(PORTF, LTC_CS); // LTC2400 CS Low //changed to F
if (sig) ltw |= 0xf0000000; // if input negative insert sign bit
ltw = ltw / 16; // scale result down , last 4 bits have no information
volt = ltw * v_ref / 16777216; // max scale
char tmp[10];
dtostrf(volt, 6, 6, tmp);
tmp[8] = 'V';
tmp[9] = '\n';
Serial.print(cnt++);
Serial.print("; ");
printFloat(volt, 6); // print voltage as floating number
Serial.println(" ");
}
sbi(PORTF, LTC_CS); // LTC2400 CS hi
delay(20);
}
/********************************************************************/
byte SPI_read()
{
SPDR = 0;
while (!(SPSR & (1 << SPIF))) ; /* Wait for SPI shift out done */
return SPDR;
}
/********************************************************************/
// printFloat from tim / Arduino: Playground
// printFloat prints out the float 'value' rounded to 'places' places
//after the decimal point
void printFloat(float value, int places) {
// this is used to cast digits
int digit;
float tens = 0.1;
int tenscount = 0;
int i;
float tempfloat = value;
// if value is negative, set tempfloat to the abs value
// make sure we round properly. this could use pow from
//<math.h>, but doesn't seem worth the import
// if this rounding step isn't here, the value 54.321 prints as
// calculate rounding term d: 0.5/pow(10,places)
float d = 0.5;
if (value < 0)
d *= -1.0;
// divide by ten for each decimal place
for (i = 0; i < places; i++)
d /= 10.0;
// this small addition, combined with truncation will round our
tempfloat += d;
if (value < 0)
tempfloat *= -1.0;
while ((tens * 10.0) <= tempfloat) {
tens *= 10.0;
tenscount += 1;
}
// write out the negative if needed
if (value < 0)
Serial.print('-');
if (tenscount == 0)
Serial.print(0, DEC);
for (i = 0; i < tenscount; i++) {
digit = (int) (tempfloat / tens);
Serial.print(digit, DEC);
tempfloat = tempfloat - ((float)digit * tens);
tens /= 10.0;
}
// if no places after decimal, stop now and return
if (places <= 0)
return;
// otherwise, write the point and continue on
Serial.print(',');
for (i = 0; i < places; i++) {
tempfloat *= 10.0;
digit = (int) tempfloat;
Serial.print(digit, DEC);
josheeg:
my arduino is only outputting as much of a negitive number as it can output pins were changed for port f7 for cs the other pins were changed for a arduino micro
I don't understand your question.
Please provide an example of the actual output and tell us what it should be.
And tell us what your program is trying to do. A program written mostly with registers is very difficult to figure out.
The output should change because it is mesuring capacitive electrodes a analog to digital converter ltc2400 and there are two tutorials that use the same 24 bit adc. It shows all -4.905 if the reference voltage is that there is some bit manipulation and register stuff that I am guessing is not transfering from the example using a uno and me using a micro.
I will check that the ss pin is a output.
That is why I was going to checkout the spi tutorial for my microcontroller from the arduino examples.
Then what it outputs should be more relevant.
I do not understand what I did not answer.
It measures analog measurements from a capacitive sensor.
The analog to digital converter code is written using registers and not the arduino spi library.
I do not know why I could try a uno but I would have to make jumpers and adapters to do it.
So I do not know the best plan to read the spi port and log it.
I would guess the spi tutorial and spi port example for the micro barometric pressure sensor would probably be a place to start.
josheeg:
I do not understand what I did not answer.
Please provide an example of the actual output and tell us what it should be.
And tell us what your program is trying to do. A program written mostly with registers is very difficult to figure out
In case of confusion, I am asking you to explain how the program code is intended to work.
The analog to digital converter code is written using registers and not the arduino spi library.
Why?
I do not know why I could try a uno but I would have to make jumpers and adapters to do it.
I don't understand why you have raised the question of an Uno. Do you think it might behave differently from a Micro? If so, in what way?
Hi I tried rewriting the code to get something out of the arduino micro running the ltc2400 adc
Using the SPI port
The results were all 0,'s
//LTC2400 24bit ADC Module
//4.096 precision reference: TI REF3040
//by joshua wojnas
//libaries
#include <Stdio.h>
#include<stdlib.h>
// the sensor communicates using SPI, so include the library:
#include <SPI.h>
//constants for pin numbers to be replaced by arduino digital pin
#define LTC_CS A0 // LTC2400 Chip Select
#define LTC_MISO MISO // LTC2400 SDO Select
#define LTC_SCK SCK // LTC2400 SCK Select
#define ARD_SS SS // arduino slave Select
//these are arduino digital pins a0 analog 0 1 is digital pin one on arduino
//used to mask out bits not needed
//Sensor's memory register addresses:
const int PRESSURE = 0x1F; //3 most significant bits of pressure
const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure
const int TEMPERATURE = 0x21; //16 bit temperature reading
const byte READ = 0b11111100; // SCP1000's read command
const byte WRITE = 0b00000010; // SCP1000's write command
//these pins might be the arduino pin number
// pins used for the connection with the sensor
// the other you need are controlled by the SPI library):
const int dataReadyPin = 1; //not used in this application
const int chipSelectPin = A0;//f7 a0
//ref https://electronics.stackexchange.com/questions/67087/analogread0-or-analogreada0
//vareables used in code
byte inByte = 0; // incoming byte from the SPI 8 bit value
unsigned int result = 0; // result to return
float output =0;
void setup() {
// put your setup code here, to run once:
Serial.begin(57600);
// while the serial stream is not open, do nothing:
while (!Serial) ;
//configure spi port
//ltc2400 msb first
/*"out the SDO pin on each falling edge of SCK. This enables
external circuitry to latch the output on the rising edge of
SCK." so SPI_MODE0
*/
SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE0));
// start the SPI library:
SPI.begin();
//the data direction of arduino pins
// initalize the data ready and chip select pins:
// pinMode(dataReadyPin, INPUT);//not used in this application
pinMode(chipSelectPin, OUTPUT);//a0 f7 36 for sensor 1
pinMode(ARD_SS, OUTPUT);//(SS/PCINT0) PB0 RXLED make slave select output to not have arduino slected
//spi.begin sets ss to output
// give the sensor time to set up:
delay(163);//after chip select
}
void loop() {
// put your main code here, to run repeatedly:
delay(163);//after chip select
// take the chip select low to select the device:
digitalWrite(chipSelectPin, LOW);
delay(163);//after chip select
//read 4 bytes from adc ltc2400
// send a value of 0 to read the first byte returned:
result = SPI.transfer(0x00);
// shift the first byte left, then get the second byte:
result = result << 8;
inByte = SPI.transfer(0x00);
result = result << 8;
inByte = SPI.transfer(0x00);
// combine the byte you just got with the previous one:
result = result | inByte;
result = result << 8;
inByte = SPI.transfer(0x00);
// combine the byte you just got with the previous one:
result = result | inByte;
float output = (float)result;//equation to filter bits
Serial.print(result);
//Serial.print(output);
Serial.print(",");
//more sensors
Serial.println("");
//deselect device wait for conversion
digitalWrite(chipSelectPin, HIGH);
}
//result is a unsigned int here they convert it to float after
//shifting and then and ing lower bytes inbyte vareable is used for other transfers.
/*
// convert the temperature to celsius and display it:
float realTemp = (float)tempData / 20.0;
Serial.print("Temp[C]=");
Serial.print(realTemp);
*/
I am still getting nothing after trying to pull bytes of data from my ltc2400 to my arduino micro.
I ordered the ebay ltc2400 adc module and will try it with the example code and my code using a arduino uno.
I do not know what the issue is with this code or hardware.