Code MCP3564 -ADC reader

Hello,

I would like to drive a MCP3564 chip wiht my arduino in SPI. But I don’t received signal from input.
See my current code :

void ReadADC_MCP3564 (void)
{
int data;
IOWrite(GPIOA, CS_MCP3564); // Activation du chip select
delay(5);
//SPI.beginTransaction(SPISettings (SPI_CLOCK_DIV128 , MSBFIRST, SPI_MODE0)); //gain control of SPI bus
SPI.transfer(0x00);SPI.transfer(0x00);SPI.transfer(0x00); //adcdata
SPI.transfer(0x00); // config0
SPI.transfer(0x0C); // config1
SPI.transfer(0x8B); // config2
SPI.transfer(0xC0); // config3
SPI.transfer(0x07); // config IRQ
SPI.transfer(0x01); // config MUX
SPI.transfer(0x00); SPI.transfer(0x00); SPI.transfer(0x00);// config SCAN

SPI.transfer(0x00); SPI.transfer(0x00); SPI.transfer(0x00); // config timer
SPI.transfer(0x00);SPI.transfer(0x00);SPI.transfer(0x00); //OFFSETCAL
SPI.transfer(0x80);SPI.transfer(0x00);SPI.transfer(0x00); // GAINCAL
SPI.transfer(0x90); SPI.transfer(0x00); SPI.transfer(0x00); //reservrer 1
SPI.transfer(0x50); //reservrer 2
SPI.transfer(0xA5); // lock
SPI.transfer16(0x000F); //reservrer 3

Serial.println("*********");
for (int i=0; i<24;i++)
{
data = SPI.transfer(0);
Serial.println(data);
}
IOWrite(GPIOA, CS_OFF); // Activation du chip select
delay(5);
// SPI.endTransaction(); //release the SPI bus

}

Thank you
Best Regards

Your post is already a few days old. Did you solve your issue? Here are a few points to get started:

  • the chip select signal should not be set before you configure the SPI module. If your SPI clock signal changes while the SPI module is setup the two modules can get out of sync.
  • do not use delay after the CS is set and before it is cleared, this takes 5ms each time, a SPI write of a byte at 1MHz takes about 10 microseconds, your entire sequence for one byte would take 1000 times longer than necessary
  • Did you check that SPI is working? You can use an oscilloscope, logic analyzer or connect the SPI output to the input to send the data to yourself first. Then write one register and read it back.

Next time I recommend you provide some more information to help people to help you. Read the "How to post .." section at the start of each sub forum section.

  • What exact boards are you using?
  • provide schematic (hand drawn photo taken with your phone is OK)
  • provide a full sketch (limited to an essential test), this will allow somebody to run this on a board very quickly when they have the hardware, sometimes the bug is in the other part of the code
  • Use code tags. Your code should look like this
Example code
  • provide links to datasheets of non-Arduino parts, this will also show you did some checking yourself
  • provide a better error description

Hello,

I am wondering if anyone can share a working code for this chip, I am trying hard but I cannot get an accurate value.
Here my config registers for a single shot reading

const byte Config0= 0b00100011;
const byte Config1= 0b00100100;
const byte Config2= 0b10001011;
const byte Config3= 0b10000000;
const byte ConfigIRQ= 0b01000010;
const byte ConfigMUX= 0b00110010;

Davide

Maybe you can use this library as a starting point.