mcp3564 icon indicating copy to clipboard operation
mcp3564 copied to clipboard

One-Shot mode not working?

Open PieterBosElectro opened this issue 2 years ago • 2 comments

I have the MCP3561 ADC but i only got i working with MCP3561_CONFIG3_CONV_MODE_CONTINUOUS command. When i try MCP3561_CONFIG3_CONV_MODE_ONE_SHOT_STANDBY i got 1 value but i can not get another one. Probably have the wrong settings but i have no idea wat i did wrong.

My config

```cmd[0]  = MCP3561_CONFIG0_WRITE;
cmd[1]  = MCP3561_CONFIG0_CLK_SEL_EXT;   // clock selection
cmd[1] |= MCP3561_CONFIG0_ADC_MODE_CONV; // standby or converting
cmd[1] |= MCP3561_CONFIG0_CS_SEL_NONE;   // input current
_MCP3561_write(hspi, cmd, 2);

cmd[0]  = MCP3561_CONFIG1_WRITE;
cmd[1]  = MCP3561_CONFIG1_OSR_20480;      // over sampling rate MCP3561_CONFIG1_OSR_20480
cmd[1] |= MCP3561_CONFIG1_AMCLK_DIV8;    // sampling clock prescaler
_MCP3561_write(hspi, cmd, 2);

cmd[0]  = MCP3561_CONFIG2_WRITE;
cmd[1]  = MCP3561_CONFIG2_BOOST_x1;   // Boost
cmd[1] |= MCP3561_CONFIG2_GAIN_x1;    // Gain
cmd[1] |= MCP3561_CONFIG2_AZ_MUX_ON; // offset cancellation algorithm
cmd[1] += 3; // last two bytes must always be 11
_MCP3561_write(hspi, cmd, 2);

cmd[0]  = MCP3561_CONFIG3_WRITE;
cmd[1]  = MCP3561_CONFIG3_CONV_MODE_ONE_SHOT_STANDBY; // conversion mode
//cmd[1]  = MCP3561_CONFIG3_CONV_MODE_CONTINUOUS; // conversion mode
cmd[1] |= MCP3561_CONFIG3_DATA_FORMAT_32BIT_CHID_SGN;    // SPI output data format, (32 and 24 bit available)
cmd[1] |= MCP3561_CONFIG3_CRCCOM_OFF;           // CRC
cmd[1] |= MCP3561_CONFIG3_GAINCAL_OFF;          // gain calibration
cmd[1] |= MCP3561_CONFIG3_OFFCAL_ON;           // offset calibration
_MCP3561_write(hspi, cmd, 2);

cmd[0]  = MCP3561_IRQ_WRITE;
cmd[1]  = MCP3561_IRQ_MODE_IRQ_HIGH;  // IRQ default pin state
cmd[1] |= MCP3561_IRQ_FASTCMD_ON;     // fast commands
cmd[1] |= MCP3561_IRQ_STP_ON;         // start of conversion IRQ
_MCP3561_write(hspi, cmd, 2);


cmd[0]  = MCP3561_MUX_WRITE;
cmd[1]  = (MCP3561_MUX_CH_AGND << 4) | MCP3561_MUX_CH0;

_MCP3561_write(hspi, cmd, 2);

PieterBosElectro avatar Jan 26 '23 12:01 PieterBosElectro

Hi, it's been a while since I last used the lib. And I only ever used the continuous mode (read: the one-shot mode is untested). Right now I don't have the time or the hardware to debug this. If you manage to get it working and it is a flaw of the lib, feel free to send a pull request.

My only idea currently:

  • Do you need to trigger a new conversion from standby mode?

mnemocron avatar Jan 26 '23 14:01 mnemocron

Hi, it's been a while since I last used the lib. And I only ever used the continuous mode (read: the one-shot mode is untested). Right now I don't have the time or the hardware to debug this. If you manage to get it working and it is a flaw of the lib, feel free to send a pull request.

My only idea currently:

  • Do you need to trigger a new conversion from standby mode?

Thanks for your reply. I trigger the conversion with a button of something else. So i dont know where the issue is. I will look into the following solutions:

Triggering with button and ISR

Reading IRQ? I dont see an interrupt. I do see it with the continuous mode. I do see the SPI command for ADC conversion

Getting the ADC out of a possible standby?

I will keep you updated

PieterBosElectro avatar Jan 26 '23 15:01 PieterBosElectro