Microcontroller › 8051 › Query about MCP3201 and 8051 communication – program is given › after many research in your
after many research in your program find out error……
remove rotation of bit in stored result at 15…..or make simple routine like
//Routine for spi data read from mcp3201.
unsigned int Get_ADC_Sample(void)
{
unsigned int TempCount;
unsigned int Temp_Data=0;
SPI_CS_PIN=1;
for(TempCount=0;TempCount<16;TempCount++) //counter for 16 databits
{
SPI_CLK_PIN=0;
SPI_CS_PIN=0;
SPI_CLK_PIN=1;
if(TempCount!=15)
Temp_Data=Temp_Data<<1;
if(SPI_DATA_PIN==1)
{Temp_Data = Temp_Data | 0x01;}
}
SPI_CS_PIN=1; //keep high when not doing the conversion.
Temp_Data &=0x0fff; //mask upper 4 bits.
return Temp_Data;
}