spi_get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK) sometimes fails to go true

  1. Where did you get the camera module(s)?
  2. Model number of the product(s)?

Arducam Mini Module Camera Shield with OV2640 2 Megapixels, i.e.
https://www.amazon.com/dp/B012UXNDOY

  1. What hardware/platform were you working on?

AtSAMV71 with MCC / Harmony libraries.

  1. Instructions you have followed. (link/manual/etc.)

I’ve ported the low-level functions of the tflmicro example and have carefully read over ArduCAM Camera Shield Series SPI Camera Software Application Note Rev 3.0, Feb 2018

  1. Problems you were having?

The code runs fine for a while, capturing consecutive images in YUV422 96 x 96 format. But after a indeterminte amount of tie (sometimes 5 seconds, sometimes 5 minutes), spi_read_bit(ARDUCHIP_TRIG, CAP_DONE_MASK) continually returns zero, as if the camera did not complete its capture. As a result, my program hangs waiting for the camera to report capture complete.

  1. The dmesg log from your hardware?

I see no dmesg here! :slightly_smiling_face:

  1. Troubleshooting attempts you’ve made?
  • Examined SPI signals with a multi-channel scope – they look solid.
  • Tried different SPI clock rates between 0.5 MHz and 3MHz. (Note: I want to fetch frames as quickly as possible, so faster SPI rates are preferable.)
  • Inserted delays between consecutive calls to spi_read_bit(ARDUCHIP_TRIG, CAP_DONE_MASK)
  • Inserted a delay after performing a burst read from the FIFO
  1. What help do you need?

I apologize for the paraphrased code, but do you see any errors in the following loop? My intent is to start capturing a frame, wait for the frame to complete, read the data from the fifo and immediately start capturing another frame:

while(1) {
    flush_fifo();
    start_capture();
    while (!spi_get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK)) {
        asm("nop");
    }
    if (read_fifo_length() != sizeof(user_buf)) {
        error();
    }
    // Note: On this hardware, spi_read_bytes() writes BURST_FIFO_READ followed by 
    // sizeof(user_buf) zeros as it reads MISO bytes into user_buf, holding CS low for the
    // entire transaction.  At any rate, it fetches the correct data.
    spi_read_bytes(BURST_FIFO_READ, user_buf, sizeof(user_buf));
    print_frame_rate();
}

As mentioned, it runs for a while, but then spi_get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK) fails to go true.

Do you have suggestions on how to diagnose this, or changes I should make to the code? (The code was lifted more or less directly from the tflmicro code example.)

I may have solved this: I added a delay between asserting (lowering) SPI CSn and starting the clock. It now appears to read the completion status reliably.

This does beg the question: where are the specifications for timing requirements for SPI communication, including maximum clock rate, chip select setup time, etc? That would save quite a lot of guesswork and needless experimentation.