cancel
Showing results for 
Search instead for 
Did you mean: 

Can not send data thoughout UART4 when use DCMI

nguyenngocsang1411
Associate II
Posted on January 10, 2016 at 10:56

I use stm32f4 discovery connect with camera OV767 to capture picture and send it to uart4. But when i use DCMI_Cmd(ENABLE); First, i just want send 'A' but i can't. What happening with DCMI or when i use DCMI, i must not use uart.

int main()

{

char buf[50];

Delay_Init();

TFT_Init();

Init_Pin_Out(Pin_D12);

Init_USART(USART3_Pack2,115200);

TFT_Clear(Black);

TFT_Puts(0, 0, ''Test DCMI OV7670'', White, Black);

if(DCMI_OV7670_Init()==0) {TFT_Puts(0, 12, ''Init Done'', White, Black);}

else {TFT_Puts(0, 12, ''Init Fail'', Red, Black);}

LCD_SetCursor(0,0);

LCD_REG = 0x0022;

 

  DMA_Cmd(DMA2_Stream1, ENABLE);

  DCMI_Cmd(ENABLE); 

  DCMI_CaptureCmd(ENABLE);

while(1)

{

//frame_buffer=0x12345678;

//sprintf(buf,''%ld\n'',frame_buffer);

//USART_Puts(UART4_Pack2,buf);

USART_SendData(USART3,'A');

}

}  

If i don't use DCMI_Cmd(ENABLE);  i send 'A' to PC good. However, i use DCMI_Cmd(ENABLE) i can't send data. Please tell me what happening with DCMI or UART

This is code config DCMI

void DCMI_Config(void)

{

  DCMI_InitTypeDef DCMI_InitStructure;

  GPIO_InitTypeDef GPIO_InitStructure;

  DMA_InitTypeDef  DMA_InitStructure;

  NVIC_InitTypeDef NVIC_InitStructure;

  

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC|RCC_AHB1Periph_GPIOE,ENABLE); 

  RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_DCMI, ENABLE);

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOE, GPIO_PinSource0, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOE, GPIO_PinSource1, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOE, GPIO_PinSource4, GPIO_AF_DCMI);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;  

  GPIO_Init(GPIOA, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9;

  GPIO_Init(GPIOB, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7;

  GPIO_Init(GPIOC, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_4;

  GPIO_Init(GPIOE, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

  

  DCMI_InitStructure.DCMI_CaptureMode = DCMI_CaptureMode_Continuous;//DCMI_CaptureMode_SnapShot;//

  DCMI_InitStructure.DCMI_SynchroMode = DCMI_SynchroMode_Hardware;

  DCMI_InitStructure.DCMI_PCKPolarity = DCMI_PCKPolarity_Falling;

  DCMI_InitStructure.DCMI_VSPolarity = DCMI_VSPolarity_High;

  DCMI_InitStructure.DCMI_HSPolarity = DCMI_HSPolarity_High;

  DCMI_InitStructure.DCMI_CaptureRate = DCMI_CaptureRate_All_Frame;

  DCMI_InitStructure.DCMI_ExtendedDataMode = DCMI_ExtendedDataMode_8b;

  DCMI_Init(&DCMI_InitStructure);

  DCMI_ITConfig(DCMI_IT_VSYNC, ENABLE);

  DCMI_ITConfig(DCMI_IT_LINE, ENABLE);

  DCMI_ITConfig(DCMI_IT_FRAME, ENABLE);

  DCMI_ITConfig(DCMI_IT_ERR, ENABLE);

      

  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

  NVIC_InitStructure.NVIC_IRQChannel = DCMI_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;  

  NVIC_Init(&NVIC_InitStructure); 

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);  

DMA_DeInit(DMA2_Stream1);

  DMA_StructInit(&DMA_InitStructure);

  DMA_InitStructure.DMA_Channel = DMA_Channel_1;

  DMA_InitStructure.DMA_PeripheralBaseAddr =  (uint32_t)&DCMI->DR;

  DMA_InitStructure.DMA_Memory0BaseAddr =  FSMC_LCD_ADDRESS;//(uint32_t)&frame_buffer[0];

  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;

  DMA_InitStructure.DMA_BufferSize = 0x01;

  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;

  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;

  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;

  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;

  DMA_InitStructure.DMA_Priority = DMA_Priority_High;

  DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;

  DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;

  DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;

  DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;

  DMA_Init(DMA2_Stream1, &DMA_InitStructure);

}

5 REPLIES 5
mark239955_stm1
Associate II
Posted on January 10, 2016 at 11:56

  1. You're initialising USART3 and transmitting on UART4.
  2. DCMI_D4 and DCMI_D8 can only be mapped on PC10 and PC11, which are shared with UART4 Rx and Tx.  If you're trying to use UART4 on those pins then it will conflict with the DCMI and whichever is initialised last will (probably) work.

stm322399
Senior
Posted on January 10, 2016 at 12:02

Could you be locked into an interrupt loop ?

Is there an evidence that anything else is working after DCMI_Cmd(ENABLE) ? Try TFT prints.

nguyenngocsang1411
Associate II
Posted on January 10, 2016 at 12:59

//frame_buffer=0x12345678;

//sprintf(buf,''%ld\n'',frame_buffer);

//USART_Puts(UART4_Pack2,buf);

USART_SendData(USART3,'A');

i still use USART_SendData(USART3,'A'); for my code. First time, i use uart 4, then i decide use usart 3, i don't know what different between USART and UART. 

dear  i don't understand what you mean, how can i lock interrupts. And i have a question, isn't that data in DCMI->DR  is image data. Can i use it and send to uart. Like example:

uint32_t data;

char buf[20];

buf=DCMI->DR

sprintf(buf,''%lu'',data);

USART_Puts(buf);

stm322399
Senior
Posted on January 10, 2016 at 14:13

A DCMI IRQ is enable, so it is likely the interrupt handler will run sooner or later. The trivial cause of your problem is that the default interrupt handler is an infinite loop that will lock up your application, blocking the UART communication and *anything* else.

Posted on January 10, 2016 at 15:34

You have to wait for TXE before jamming data out.

Don't selectively show code, it provides random context when you don't even know where the problem is.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..