MCP3208 Resolution & SPI Addressing

Hello

I am trying to interface with an MCP3208 (12-bit, 8 channel ADC) over SPI bus. I attach a 0-5V potentiometer to pin 1 (analog input 0) of the MCP3208. I measure with a multimeter that I am getting a range from 0-5Volts.

Datasheet: https://www.microchip.com/en-us/product/MCP3208

I have 2 questions:

  1. I have a problem understanding is the addressing of the SPI bus. When I do this below, everything works great (12-bit resolution):
int MCP3208_Read_SingleCh(byte readAddress)
{
	int Return_Value = 0;
	byte dataMSB = 0;
    byte dataLSB = 0;	
	int CS_Pin = 9;

	readAddress = 0b01100000 | ((readAddress & 0b111) << 2);
	
	SPI.beginTransaction(MCP3208_Set);
	digitalWrite(CS_Pin, LOW);
	SPI.transfer(readAddress);                                 
	dataMSB = SPI.transfer(0x00);  
	dataLSB = SPI.transfer(0x00);                     
	digitalWrite(CS_Pin, HIGH);
	SPI.endTransaction();
	
	//Return_Value = ((dataMSB << 8) | dataLSB);
	Return_Value = (dataMSB << 4) | (dataLSB >> 2);

  return RtnVal;
}

However when I insert a line of code to shift the address over by a bit, my resolution goes to 11-bit.

int MCP3208_Read_SingleCh(byte readAddress)
{
	int Return_Value = 0;
	byte dataMSB = 0;
    byte dataLSB = 0;	
	int CS_Pin = 9;

	readAddress = 0b01100000 | ((readAddress & 0b111) << 2);
	
	/* NEW CODE HERE*/
	readAddress = readAddress >> 1;
	
	SPI.beginTransaction(MCP3208_Set);
	digitalWrite(CS_Pin, LOW);
	SPI.transfer(readAddress);                                 
	dataMSB = SPI.transfer(0x00);  
	dataLSB = SPI.transfer(0x00);                     
	digitalWrite(CS_Pin, HIGH);
	SPI.endTransaction();
	
	//Return_Value = ((dataMSB << 8) | dataLSB);
	Return_Value = (dataMSB << 4) | (dataLSB >> 2);

  return RtnVal;
}

And if I bit shift again (shift by 2), the resolution goes down to 10-bit. Reading the datasheet, I cannot figure out how this addressing works - anyone care to share some knowledge?

  1. Can someone explain how/why we bit-shift the LeastSignificantByte (dataLSB) by 2 bits to the right?

Thank You!!

I'm not familiar with the MCP3208 but...
When you change the readAddress by dividing by 2, what did you expect to happen?

Shifting...
With SPI the processor can only read 8 bits at a time. So how do you get 12 bits?
You split the 12 bits into two 8 bit words, reading each. Now to put them back together you have to look at where the bits are positioned. You will find this in the MCP3208 specification. Now you have to move the bits from what is read to putting them back in numerical order.

You have to look at how the addressing works in chapter 5 of the data sheet.

To simply change the channel, you call this function with a different parameter between 0 and 7.

Simply shifting the whole control byte right once it is built will not do anything useful. It appears it may force the device into differential mode.