somewhat working ads1015 but results are still raw added an I2C function writeWordWithReg we nnet to think about it's meaning but it's wokring
parent
822af574d4
commit
f28dc3e09c
@ -1,44 +1,48 @@
|
|||||||
void set_bits_range_uint16(uint16_t *value, uint8_t &startBit, uint8_t &stopBit, uint16_t &replace);
|
#include <stdint.h>
|
||||||
void set_bits_range_uint8(uint8_t *value, uint8_t &startBit, uint8_t &stopBit, uint8_t &replace);
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
void throwError( uint16_t error);
|
void throwError( uint16_t error);
|
||||||
|
|
||||||
void set_nth_bit_uint8( uint8_t *value, uint8_t &n);
|
void setBitUint8(uint8_t *value, uint8_t &n);
|
||||||
void set_nth_bit_int8( int8_t *value, uint8_t &n);
|
void setBitInt8(int8_t *value, uint8_t &n);
|
||||||
void set_nth_bit_uint16( uint16_t *value, uint8_t &n);
|
void setBitUint16(uint16_t *value, uint8_t &n);
|
||||||
void set_nth_bit_int16( int16_t *value, uint8_t &n);
|
void setBitInt16(int16_t *value, uint8_t &n);
|
||||||
|
|
||||||
void unset_nth_bit_uint8( uint8_t *value, uint8_t &n);
|
void unsetBitUint8(uint8_t *value, uint8_t &n);
|
||||||
void unset_nth_bit_int8( int8_t *value, uint8_t &n);
|
void unsetBitInt8(int8_t *value, uint8_t &n);
|
||||||
void unset_nth_bit_uint16( uint16_t *value, uint8_t &n);
|
void unsetBitUint16(uint16_t *value, uint8_t &n);
|
||||||
void unset_nth_bit_int16( int16_t *value, uint8_t &n);
|
void unsetBitInt16(int16_t *value, uint8_t &n);
|
||||||
|
|
||||||
void toggle_nth_bit_uint8( uint8_t *value, uint8_t &n);
|
void toggleBitUint8(uint8_t *value, uint8_t &n);
|
||||||
void toggle_nth_bit_int8( int8_t *value, uint8_t &n);
|
void toggleBitInt8(int8_t *value, uint8_t &n);
|
||||||
void toggle_nth_bit_uint16( uint16_t *value, uint8_t &n);
|
void toggleBitUint16(uint16_t *value, uint8_t &n);
|
||||||
void toggle_nth_bit_int16( int16_t *value, uint8_t &n);
|
void toggleBitInt16(int16_t *value, uint8_t &n);
|
||||||
|
|
||||||
void get_nth_bit_uint8( uint8_t *value, uint8_t &n);
|
uint8_t getBitUint8(uint8_t *value, uint8_t &n);
|
||||||
void get_nth_bit_int8( int8_t *value, uint8_t &n);
|
int8_t getBitInt8(int8_t *value, uint8_t &n);
|
||||||
void get_nth_bit_uint16( uint16_t *value, uint8_t &n);
|
uint16_t getBitUint16(uint16_t *value, uint8_t &n);
|
||||||
void get_nth_bit_int16( int16_t *value, uint8_t &n);
|
int16_t getBitInt16(int16_t *value, uint8_t &n);
|
||||||
|
|
||||||
void change_nth_bit_to_x_uint8( uint8_t *value, uint8_t &n, uint8_t &x);
|
void changeBitUint8(uint8_t *value, uint8_t &n, uint8_t &x);
|
||||||
void change_nth_bit_to_x_int8( int8_t *value, uint8_t &n, uint8_t &x);
|
void changeBitInt8(int8_t *value, uint8_t &n, uint8_t &x);
|
||||||
void change_nth_bit_to_x_uint16( uint16_t *value, uint8_t &n, uint8_t &x);
|
void changeBitUint16(uint16_t *value, uint8_t &n, uint8_t &x);
|
||||||
void change_nth_bit_to_x_int16( int16_t *value, uint8_t &n, uint8_t &x);
|
void changeBitInt16(int16_t *value, uint8_t &n, uint8_t &x);
|
||||||
|
|
||||||
void get_n_bits_lsb_uint8( uint8_t *value, uint8_t &bits);
|
uint8_t get_n_bits_lsb_uint8(uint8_t *value, uint8_t &bits);
|
||||||
void get_n_bits_lsb_int8(int8_t *value, uint8_t &bits);
|
int8_t get_n_bits_lsb_int8(int8_t *value, uint8_t &bits);
|
||||||
void get_n_bits_lsb_uint16( uint16_t *value, uint8_t &bits);
|
uint16_t get_n_bits_lsb_uint16(uint16_t *value, uint8_t &bits);
|
||||||
void get_n_bits_lsb_int16( int16_t *value, uint8_t &bits);
|
int16_t get_n_bits_lsb_int16(int16_t *value, uint8_t &bits);
|
||||||
|
|
||||||
void get_n_bits_msb_uint8( uint8_t *value, uint8_t &bits);
|
uint8_t get_n_bits_msb_uint8(uint8_t *value, uint8_t &bits);
|
||||||
void get_n_bits_msb_int8(int8_t *value, uint8_t &bits);
|
int8_t get_n_bits_msb_int8(int8_t *value, uint8_t &bits);
|
||||||
void get_n_bits_msb_uint16( uint16_t *value, uint8_t &bits);
|
uint16_t get_n_bits_msb_uint16(uint16_t *value, uint8_t &bits);
|
||||||
void get_n_bits_msb_int16( int16_t *value, uint8_t &bits);
|
int16_t get_n_bits_msb_int16(int16_t *value, uint8_t &bits);
|
||||||
|
|
||||||
void get_bits_range_uint8( uint8_t *value, uint8_t &startBit, uint8_t &stopBit);
|
uint8_t get_bits_range_uint8(uint8_t *value, uint8_t &startBit, uint8_t &stopBit);
|
||||||
void get_bits_range_int8( int8_t *value, uint8_t &startBit, uint8_t &stopBit);
|
int8_t get_bits_range_int8(int8_t *value, uint8_t &startBit, uint8_t &stopBit);
|
||||||
void get_bits_range_uint16( uint16_t *value, uint8_t &startBit, uint8_t &stopBit);
|
uint16_t get_bits_range_uint16(uint16_t *value, uint8_t &startBit, uint8_t &stopBit);
|
||||||
void get_bits_range_int16( int16_t *value, uint8_t &startBit, uint8_t &stopBit);
|
int16_t get_bits_range_int16(int16_t *value, uint8_t &startBit, uint8_t &stopBit);
|
||||||
|
|
||||||
|
void set_bits_range_uint16(uint16_t *value, uint8_t &startBit, uint8_t &stopBit, uint16_t &replace);
|
||||||
|
void set_bits_range_uint8(uint8_t *value, uint8_t &startBit, uint8_t &stopBit, uint8_t &replace);
|
||||||
|
@ -0,0 +1,105 @@
|
|||||||
|
#include "ads1050.h"
|
||||||
|
|
||||||
|
Ads1015::Ads1015(i2c_ch1_pImpL* i2c,ErrorHandler* err)
|
||||||
|
{
|
||||||
|
i2c_ads1015 = i2c;
|
||||||
|
errorHandling = err;
|
||||||
|
i2cWrite = 1;
|
||||||
|
configuration = ADS1015_CONFIG_RESET;
|
||||||
|
writeConfig();
|
||||||
|
configuration = 0;
|
||||||
|
errorHandling->addNewError(-1,__FILE__,"This mutpilexer mode does not Exist",KILL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ads1015::writeConfig()
|
||||||
|
{
|
||||||
|
std::cout << "To be written conf = "<< unsigned(configuration) << std::endl;
|
||||||
|
i2c_ads1015->writeWordWithReg(ADS1015_I2C_ADRS,ADS1015_REG_CONFIG,configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t Ads1015::getConfig()
|
||||||
|
{
|
||||||
|
configuration = i2c_ads1015->readWord(ADS1015_I2C_ADRS, ADS1015_REG_CONFIG);
|
||||||
|
return configuration;
|
||||||
|
}
|
||||||
|
void Ads1015::setMultiplexer(uint16_t mode)
|
||||||
|
{
|
||||||
|
if(mode <= ADS1015_MUX_AIN3_GND)
|
||||||
|
{
|
||||||
|
bitStart = ADS1015_MUX_BIT_NO;
|
||||||
|
bitEnd = bitStart + ADS1015_MUX_BIT_LEN -1;
|
||||||
|
set_bits_range_uint16(&configuration,bitStart,bitEnd,mode);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
errorHandling->handleError(-1,__FILE__);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ads1015::setGain(uint16_t gain)
|
||||||
|
{
|
||||||
|
if(gain <= ADS1015_GAIN_256)
|
||||||
|
{
|
||||||
|
bitStart = ADS1015_GAIN_BIT_NO;
|
||||||
|
bitEnd = bitStart + ADS1015_GAIN_BIT_LEN -1;
|
||||||
|
set_bits_range_uint16(&configuration,bitStart,bitEnd,gain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ads1015::setOperationMode(uint8_t mode)
|
||||||
|
{
|
||||||
|
if(mode <= ADS1015_MODE_SINGLE)
|
||||||
|
{
|
||||||
|
bitNo = ADS1015_MODE_BIT_NO;
|
||||||
|
changeBitUint16(&configuration,bitNo,mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ads1015::setDataRate(uint8_t rate)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ads1015::setComparatorMode(uint8_t mode)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ads1015::setComparatorPolarity(uint8_t pol)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ads1015::setComparatorLatch(uint8_t latch)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ads1015::setComparatorQueue(uint8_t queue)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t Ads1015::checkConversion()
|
||||||
|
{
|
||||||
|
bitNo = ADS1015_OS_CONVERTING;
|
||||||
|
return getBitUint16(&configuration,bitNo);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int16_t Ads1015::getConversion()
|
||||||
|
{
|
||||||
|
conversion = i2c_ads1015 -> readWord(ADS1015_I2C_ADRS,ADS1015_REG_CONVERSION)>>4;
|
||||||
|
if (conversion > 0x07FF) {
|
||||||
|
// negative number - extend the sign to 16th bit
|
||||||
|
conversion |= 0xF000;
|
||||||
|
}
|
||||||
|
return (int16_t)conversion;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ads1015::startSingleConvertion()
|
||||||
|
{
|
||||||
|
bitNo = ADS1015_OS_BIT_NO;
|
||||||
|
getConfig();
|
||||||
|
setBitUint16(&configuration,bitNo);
|
||||||
|
}
|
Loading…
Reference in new issue