ArduCAM / PICO_SPI_CAM

BSD Zero Clause License
36 stars 12 forks source link

Issue with retriving images from OV2640 and Pico #6

Closed Edenane closed 2 years ago

Edenane commented 2 years ago

Hi, When retreiving images using the HostApp and they are small, there are no issues retreiving the images. However, if the requested resolution is 1024x768 the images are about 90% of the time have corruption issues:

corruption1 corruption2

Any idea what could be causing this? It's attached to a OV2640.

Edenane commented 2 years ago

I solved this by reading byte by byte from the SPI rather than all at once, so I changed this function:

uint8_t read_fifo_burst(ArduCAM myCAM)
{
  int i , count;
  int length = myCAM.read_fifo_length();
  uint8_t * imageBuf =(uint8_t *) malloc(length*sizeof(uint8_t));
  i = 0 ;
  myCAM.CS_LOW();
  myCAM.set_fifo_burst();//Set fifo burst mode
  spi_read_blocking(SPI_PORT, BURST_FIFO_READ,imageBuf, length);
  myCAM.CS_HIGH();
  SerialUsb(imageBuf, length);
  free(imageBuf);
  return 1;
}

to

uint8_t read_fifo_burst(ArduCAM myCAM)
{
  int i;
  int length = myCAM.read_fifo_length();
  uint8_t VAL;
  myCAM.CS_LOW();
  myCAM.set_fifo_burst();//Set fifo burst mode
  for (i = 0; i < length; i++){
    spi_read_blocking(SPI_PORT, BURST_FIFO_READ,&VAL, 1);
    sleep_us(12);
    SerialUsb(&VAL, 1);
  }
  return 1;

This does slow down retriving the images but worked every time.