STM32F4Discovery Distorted Image when writing to bmp on fatfs
Hi I have the camera demo for STM32F4Discovery working which can display the image from camera (OV9655) to the LCD (DM-LCD35RT). I also have fatfs for SDIO working. I am writing the image data to a .bmp file on the SD card. This works except the image is distorted (see the different between the LCD image and the created PICBMP image. It looks like the width is incorrect some how.
https://drive.google.com/folderview?id=0B2tRJoqjaZmxSnJzYWdXYVVGQUE&usp=sharing
Flow is DCMI (SnapShot)->DMA->FSMC (on LCD) <- This works correctly then I simply read the data from the LCD and write it to a write, adding a bmp header at the start. Any suggestions as to why the bmp image does not align with the LCD image? Offending code below, in the for loop I suspect:int32_t Capture_Image_TO_Bmp(
void
)
{
int32_t ret = -1;
int32_t i = 0;
int32_t j = 0;
int16_t data_temp = 0;
uint32_t bw = 0;
char
file_str[30] =
''picbmp''
;
FIL file;
/* File object */
/* mount the filesys */
if
(f_mount(&filesys,
''''
, 1) != FR_OK) {
return
-1;
}
Delayms(10);
//sprintf(file_str, ''pic%d.bmp'',pic_counter);
file_str[4] = (
char
)((pic_counter % 10)+48);
file_str[3] = (
char
)(((pic_counter/10) % 10)+48);;
ret = f_open(&file, file_str, FA_WRITE | FA_CREATE_ALWAYS);
if
(ret) {
return
ret;
}
/* write the bmp header */
ret = f_write(&file, bmp_header, 70, &bw);
LCD_SetCursor(0,0);
LCD_WriteRAM_Prepare();
LCD_ReadRAM();
for
(j = 0; j < 240; j++) {
for
(i=0;i<320;i++) {
data_temp = LCD_ReadRAM();
image_buf[i*2+1] = (data_temp&0xff00) >> 8;
image_buf[i*2+0] = data_temp & 0x00ff;
}
ret = f_write(&file, image_buf, 640, &bw);
}
ret = f_close(&file);
f_mount(0,
''''
, 1);
/* statistics the take pictures count */
pic_counter++;
set_pic_count();
return
ret;
}
#fatfs #sdio #sd #dma #stm32f4 #stm32 #discovery