Hi,
Can somebody please help me understand how to program using the SPI library on MCP6S21. I'm using the Arduino Duemilanove(Atmega328) with the software ver 0019.
The MCP6S21 is 8-PDIP from microchip programmable gain amplifier (PGA) using SPI: SCK, SI, CS (only 3 pins - input only).
I've tried over and over again to simply write a program that changes the amplifier gain to X2 but with no success at all. The MCP6S21 basically programmed through the SPI interface using 16-bit words. link to DATASHEET: http://ww1.microchip.com/downloads/en/DeviceDoc/21117a.pdf
From what I see in the datasheet it supposed to be very simple but I've tried many variations of programs like the arduino examples: DigitalPotControl, BarometricPressureSensor or even something more close: Arduino Playground - MCP3208
so far nothing worked.
I'm new to SPI and if someone can shade a light for me I'll be very grateful...
Best if you post some simple code of what you have tried and we can see if there is anything that we can spot that is wrong.
I would advise pull up resistors of 4K7 on both the data and clock and remember that the I2C is on analogue pins 4 & 5 and not the digital ones. (and on the mega they are different again)
void setup() {
// set CS as an output:
pinMode (CS, OUTPUT);
// initialize SPI:
SPI.begin();
SPI.setBitOrder(MSBFIRST); // MSB first bit order
SPI.setDataMode(SPI_MODE0); //SPI Mode 0
SPI.setClockDivider(SPI_CLOCK_DIV4); // 16MHZ/4 = 4MHZ
// take the SS pin low to select the chip:
digitalWrite(CS,LOW);
// send in the address and value via SPI:
SPI.transfer(B01000000); // Instruction Register set to "write to register"
SPI.transfer(B00000001); // Gain Register set to "Gain of +2"
// take the SS pin high to de-select the chip:
digitalWrite(CS,HIGH);
SPI.end();
}
I've tried what u suggested:
SPI.setClockDivider(SPI_CLOCK_DIV16);
or
SPI.setClockDivider(SPI_CLOCK_DIV32);
even
SPI.setClockDivider(SPI_CLOCK_DIV64);
or changing CS to high in the beginning,
but nothing changed a thing . I am still reading on the output wire the same voltage in the CH0 (input) , meaning x1 gain and not x2.
maybe there is a problem with the SPI library ?
I've found out what was wrong: the problem was in my circuit..
I used VSS<0 and I missed that it must be: |VDD-VSS|<7v
as mention in the datasheet...
Now it's working great and it's a very precise gain amp.