I'm using MCP3464(8-single channels) for getting the digital count via the SPI. Now in this I have configured the first 2 channels(CH0 and CH1) for getting the digital output, and the setup is providing current to the channels via a 4-20mA Jig (created from the Hardware team in my Office and it has conversion current to voltage conversion cards added to it and the count will go from 0.6V to 3V - I have checking the voltage detection via the Multimeter and it is being received on the ADC channel pins) - even if i switch off the Jig I'm just getting the same 3 values as mentioned in the title in random order and no changing of the current from the jig is making a difference.
-> Here's the code that I'm working on Right now (Using 16-bit data output right now)
int16_t Analog_ADDOn_SPI_Write(uint8_t regAddr, uint8_t data)
{
uint8_t databuff[2] = {0};
int16_t ret = ERROR_VAL;
databuff[0] = (((MCP3464_DEV_ID & 0x03) << 6) | ((regAddr & 0x0F ) << 2) | (MCP3464_WRITE & 0x03) << 0);
databuff[1] = data;
pthread_mutex_lock(&SPIbus_mutex);
SPIBus_ChipSelect(eAnalogAddOn, ENABLE);
ret = SPIBus_Write(databuff,2);
SPIBus_ChipSelect(eAnalogAddOn, DISABLE);
pthread_mutex_unlock(&SPIbus_mutex);
DEBUG_LOGPRINT("\r\n WRITE - ADDRESS 0x%x, 0th and 1st byte 0x%x 0x%x \r\n", regAddr, databuff[0], databuff[1]);
return ret;
}
int16_t Analog_ADDOn_SPI_Read(uint8_t regAddr, uint8_t* received_rx_value)
{
int16_t ret = ERROR_VAL;
float voltage = 0.0;
// --------------- 16-bits Code ---------------
int16_t adc16 = 0x00; // Output of the ADC will be signed, so use 'int' instead of 'uint'
uint16_t length = 3;
uint8_t tx[3] = {0}, rx[3] = {0};
tx[0] = (((MCP3464_DEV_ID & 0x03) << 6) | ((regAddr & 0x0F) << 2) | (MCP3464_INCREMENTAL_READ & 0x03) << 0);
tx[1] = 0x00; // sending dummy bytes for clock pulses
tx[2] = 0x00; // for Config3 - 16 bits - 0x80 - only tx0 to tx2 and for Config3 - 32 bits - 0x90 - tx0 to tx4
Analog_ADDOn_SPI_Write(MCP3464_MUX, 0x08); // here channel0 - 0x08 and channel1 - 0x18
usleep(2000);
pthread_mutex_lock(&SPIbus_mutex);
SPIBus_ChipSelect(eAnalogAddOn, ENABLE);
ret = SPIBus_Read(tx, rx, length);
SPIBus_ChipSelect(eAnalogAddOn, DISABLE);
pthread_mutex_unlock(&SPIbus_mutex);
adc16 = (rx[1] << 8) | (rx[2] << 0);
DEBUG_LOGPRINT("\r\n ===== The Value in the 16-bit ADC Variable(Decimal) = %d, (Hexa) - 0x%x and RX Array is 0x%x 0x%x 0x%x ===== \r\n", adc16, adc16, rx[0], rx[1], rx[2]); // Use '(unsigned)adc16' for uint8 or uint16 and use %d as a format specifier.
DEBUG_PRINT("\r\n");
return ret;
}
void init_Analog_AddOn(void)
{
DEBUG_PRINT("\r\n ========== Inside the init_Analog_Addon() function ========== \r\n");
Analog_ADDOn_SPI_Write(MCP3464_CONFIG0, 0xF3); // changed from 0x33 to 0xF2(standby mode)
usleep(20000);
Analog_ADDOn_SPI_Write(MCP3464_CONFIG1, 0x0C); // changed from 0x0C to 0x24
usleep(20000);
Analog_ADDOn_SPI_Write(MCP3464_CONFIG2, 0x8B); // from 0x8B to 0x97
usleep(20000);
Analog_ADDOn_SPI_Write(MCP3464_CONFIG3, 0xC0); // 0xC3 - 16-bit, 0xD3 - 32-bit
usleep(20000);
Analog_ADDOn_SPI_Write(MCP3464_IRQ, 0x0F); // will always be 0x0C or 0x0D
usleep(20000);
}
First I am calling the init function and then I'm giving current via my Jig and reading output from the channel0 or channel1. But not getting the required values.
Also sometime getting 0x13, 0x15, 0x17 for the status byte after sending the initial config commands, any help is appreciated, thank you.