• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Understanding SPI communications for diffrent ADC type in c++ implementation

Thread starter #1
spent many hours to understand how to change ADC MCP3008 SPI communications into the ADC 0832CCN. I need to change this function:

//this works for ADC MCP 3008
double Mcp3008Spi::read( uint8_t channel , bool differential )
{
if( channel > 7 )
{
std::cerr << "Incorrect channel number (allowed 0-7)." << std::endl;

return 0.0 / 0.0; // NaN
}

if( this->handle == -1 )
return 0.0 / 0.0; // NaN

uint8_t buffer[ 3 ];

// http://www.hertaville.com/files/uploads/2013/07/gg4.png
buffer[ 0 ] = 1;
buffer[ 1 ] = ( differential ? 0 : ( 1 << 7 ) ) | ( channel << 4 );
buffer[ 2 ] = 0;

if( this->transfer( buffer, 3 ) )
{
uint16_t hi = ( buffer[ 1 ] << 8 ) & 0x0300;
uint16_t lo = ( buffer[ 2 ] << 0 ) & 0x00FF;

uint16_t value = hi | lo;

return 100.0 * ( (double)value / 1023.0 );
}

return 0.0 / 0.0; // NaN
}


with transmition datasheet looking like that
https://postimg.org/image/cbgplvrjt/
and in ADC 0832CCN the transmition datasheet looking like that
https://postimg.org/image/yr4qowws9/
https://postimg.org/image/klyxn3nqx/
Unfortunatlly the procesor address space and bit opearions is black magic for me. If anyone can explain me how to understand that or show me how to read the neccesary transmition ?
 

EE World Online Articles

Loading

 
Top