Continue to Site

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.

  • 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

Status
Not open for further replies.

expiredmind

New Member
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 ];

// **broken link removed**
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
**broken link removed**
and in ADC 0832CCN the transmition datasheet looking like that
**broken link removed**
**broken link removed**
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 ?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top