Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One-Shot mode not working? #5

Open
PieterBosElectro opened this issue Jan 26, 2023 · 2 comments
Open

One-Shot mode not working? #5

PieterBosElectro opened this issue Jan 26, 2023 · 2 comments

Comments

@PieterBosElectro
Copy link

PieterBosElectro commented Jan 26, 2023

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);
@mnemocron
Copy link
Member

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?

@PieterBosElectro
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants