Unreliable initialisation of the CH201

By huntchrgmailcom , 22 April 2021

Hi there,

I've provided an implementation of chirp_bsp.h i.e. a board support package functions to interface Chirp SonicLib, for the Nordic nRF52840-DK. I'm having difficultly initialising the CH-201 I've got hooked up. I'm unsure of what the condition is, but sometimes the initialisation works, sometimes it doesn't. I can consistently reproduce the initialisation problem after leaving the DK unpowered for some time (like overnight).

In essence, the I2C interface (known as TWI in the Nordic world) is stating that the program address (0x45) is bad. The program pin appears to be high. However, *sometimes* all is well, which leads me to think that the wiring side of things is ok.

Here's what the nRF52 logs report:

<info> app_timer: RTC: initialized.
<info> TWIM: Function: nrfx_twim_init, error code: NRF_SUCCESS.
<info> TWIM: Instance enabled: 0.
<info> TWIM: Transfer type: XFER_TX.
<info> TWIM: Transfer buffers length: primary: 3, secondary: 0.
<debug> TWIM: Primary buffer data:
<debug> TWIM: 85 FC FF |...
<debug> TWIM: Secondary buffer data:
<debug> TWIM: |
<debug> TWIM: TWIM: Event: NRF_TWIM_EVENT_ERROR.
<debug> TWIM: TWIM: Event: NRF_TWIM_EVENT_STOPPED.
<warning> TWIM: Function: nrfx_twim_xfer, error code: NRF_ERROR_DRV_TWI_ERR_ANACK.
<info> TWIM: Transfer type: XFER_TX.
<info> TWIM: Transfer buffers length: primary: 2, secondary: 0.
<debug> TWIM: Primary buffer data:
<debug> TWIM: C2 40 |.@
<debug> TWIM: Secondary buffer data:
<debug> TWIM: |
<debug> TWIM: TWIM: Event: NRF_TWIM_EVENT_ERROR.
<debug> TWIM: TWIM: Event: NRF_TWIM_EVENT_STOPPED.
<warning> TWIM: Function: nrfx_twim_xfer, error code: NRF_ERROR_DRV_TWI_ERR_ANACK.
<info> TWIM: Transfer type: XFER_TX.
<info> TWIM: Transfer buffers length: primary: 2, secondary: 0.
<debug> TWIM: Primary buffer data:
<debug> TWIM: C2 11 |..
<debug> TWIM: Secondary buffer data:
<debug> TWIM: |
<debug> TWIM: TWIM: Event: NRF_TWIM_EVENT_ERROR.
<debug> TWIM: TWIM: Event: NRF_TWIM_EVENT_STOPPED.
<warning> TWIM: Function: nrfx_twim_xfer, error code: NRF_ERROR_DRV_TWI_ERR_ANACK.
<info> TWIM: Transfer type: XFER_TX.
<info> TWIM: Transfer buffers length: primary: 1, secondary: 0.
<debug> TWIM: Primary buffer data:
<debug> TWIM: 00 |.
<debug> TWIM: Secondary buffer data:
<debug> TWIM: |
<debug> TWIM: TWIM: Event: NRF_TWIM_EVENT_ERROR.
<debug> TWIM: TWIM: Event: NRF_TWIM_EVENT_STOPPED.
<warning> TWIM: Function: nrfx_twim_xfer, error code: NRF_ERROR_DRV_TWI_ERR_ANACK.
<error> app: ERROR 3 [NRF_ERROR_INTERNAL] at ../../../main.c:46
PC at: 0x000072FD
<error> app: End of error report

Any ideas?

huntchrgmailcom

4 years 11 months ago

For further info, I've distilled the code into a smaller example which is similar to the "find_sensors" function in the sample chbsp_chirp_samg55.c file. I now call this code having setting up the nRF52840-DK's clocks and GPIO. I get the same result i.e. the ANACK.

    ret_code_t err_code;

nrfx_gpiote_out_config_t program_pin_config = NRFX_GPIOTE_CONFIG_OUT_SIMPLE(false);
nrfx_gpiote_out_config_t reset_pin_config = NRFX_GPIOTE_CONFIG_OUT_SIMPLE(true);
nrfx_gpiote_pin_t program_pin = NRF_GPIO_PIN_MAP(1, 3);
nrfx_gpiote_pin_t reset_pin = NRF_GPIO_PIN_MAP(1, 1);

uint8_t sig_bytes[2];

err_code = nrfx_gpiote_out_init(reset_pin, &reset_pin_config);
APP_ERROR_CHECK(err_code);

err_code = nrfx_gpiote_out_init(program_pin, &program_pin_config);
APP_ERROR_CHECK(err_code);

nrfx_gpiote_out_set(program_pin);
sig_bytes[0] = 0;
sig_bytes[1] = 0;
err_code = nrfx_twim_rx(&m_twi, CH_I2C_ADDR_PROG, sig_bytes, 2);
APP_ERROR_CHECK(err_code);
if ((sig_bytes[0] == CH_SIG_BYTE_0) && (sig_bytes[1] == CH_SIG_BYTE_1))
{
NRF_LOG_INFO("Chirp sensor 0 found");
}
else
{
NRF_LOG_INFO("Chirp sensor 0 not found");
}
nrfx_gpiote_out_clear(program_pin);

phpbb Post ID
38980

arulkumar107gmailcom

4 years 9 months ago

Hi huntc,
I'm also facing same issue right now, did you figured it out. If you help me also with the solution.

phpbb Post ID
39057
phpbb Topic ID
38977