Understanding SPI communications for diffrent ADC type in cpp implementation

Thread Starter

Expiredmind

Joined Jan 19, 2017
1
I 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
Code:
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


and in ADC 0832CCN the transmition datasheet looking like that



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 ?
 
Top