// Enable clock and init GPIO inputs LPC_CCU1->CLK_M3_GPIO_CFG = (1<<1) | (1<<0); //enable clock while (!(LPC_CCU1->CLK_M3_GPIO_STAT & (1<<1))); //stat run //for all pins on port 4 I configure input //... LPC_SCU->SFSP9_0 = (0 << 0) | //Function 0 GPIO (2 << 3) | //Disable pullup and pulldown (1 << 5) | //Fast speed (1 << 6) | //Enable input buffer (1 << 7); //Disable input glitch filter //... LPC_CCU1->CLK_M3_DMA_CFG = (1<<1) | (1<<0); //enable clock while (!(LPC_CCU1->CLK_M3_DMA_STAT & (1<<1))); //check stat run // Reset all channel configuration register LPC_GPDMA->C0CONFIG = 0; LPC_GPDMA->C1CONFIG = 0; LPC_GPDMA->C2CONFIG = 0; LPC_GPDMA->C3CONFIG = 0; LPC_GPDMA->C4CONFIG = 0; LPC_GPDMA->C5CONFIG = 0; LPC_GPDMA->C6CONFIG = 0; LPC_GPDMA->C7CONFIG = 0; // Clear all DMA interrupt and error flag LPC_GPDMA->INTTCCLEAR = 0xFF; //Clear CH0 Count Interrupt flag LPC_GPDMA->INTERRCLR = 0xFF; //Clear CH0 Error Interrupt flag // Clear DMA configure LPC_GPDMA->C0CONTROL = 0x00; LPC_GPDMA->C0CONFIG = 0x00; // Assign Linker List Item value LPC_GPDMA->C0LLI = 0; //Assign source address GPIO on port 4 LPC_GPDMA->C0SRCADDR = (uint32_t) &LPC_GPIO_PORT->PIN[4]; //Assign destination address dest1[256] buffer in SRAM LPC_GPDMA->C0DESTADDR = (uint32_t) dest1; LPC_GPDMA->C0CONTROL = (uint32_t)(256 //transfer size | (0 << 12) //source burst size - 1 | (0 << 15) //destination burst size - 1 | (0 << 18) //source width - 8bit | (0 << 21) //dest width - 8bit | (0 << 24) | (0 << 25) | (0 << 26) //source increment - do not inc | (1 << 27) //destination increment - inc | (0 << 28) | (0 << 29) | (0 << 30) | (1 << 31)); //terminal count interrupt - enabled LPC_GPDMA->CONFIG = 1; //Enable GPDMA Controller while (!(LPC_GPDMA->CONFIG & 1)); //check enable LPC_GPDMA->C0CONFIG = 0 //Channel Disable | ((1 & 0x1f) << 1) //source peripheral - Cap0_2 | (0 << 6) //dest request memory - none | (2 << 11) //flow control - peripheral to memory | (1 << 14) //(14) - mask out error interrupt | (1 << 15) //(15) - mask out terminal count interrupt | (0 << 16) //(16) - no locked transfers | (0 << 18); //(18) - no HALT //Enable GPDMA interrupt NVIC_EnableIRQ(DMA_IRQn); LPC_GPDMA->C0CONFIG |= 1; //Channel Enable //Here i received an interrupt error (LPC_GPDMA->INTERRSTAT=1) and the DMA Channel is disabled |
void CameraFrameInterrupt(void)
{
CameraFrameCount ++;
CameraByteCountSum = CameraByteCount;
CameraByteCount = 0;
if (CameraFrameCount<=10)
{
LPC_TIM1->MCR = 3;//on match reset counter + interrupt
}
}
void TIMER1_IRQHandler (void)
{LPC_TIM1->IR = 1; // clear interrupt flag MR0
if((LPC_GPIO1->FIOPIN&0x100)==0x100){ // Check HREF
CameraBuffer1[CameraByteCount++] = (LPC_GPIO2->FIOPIN);
if (CameraByteCount >=9180)
{
LPC_TIM1->MCR = 2;//on match reset counter + no interrupt
}
}
}
main(void){
//Another configuration
OV7670_Reset();
write_ov7670_reg(0x11,0x98); //pclk=800Khz
camera_QQVGA_RGB565();
write_ov7670_reg(0x0c, 0x04); //scale enable
write_ov7670_reg(0x3e, 0x1b);//PLCK Divider: :0=0x00/ :2=0x19 :4=0x1A :8=0x1B
write_ov7670_reg(0x73, 0xf3);//CLK Divider: :0=0xF0/ :2=0xF1 :4=0xF2 :8=0xF3
write_ov7670_reg(0x72, 0x33);//Picture Divider: Bit4-7=Vertical, Bit0-3=Horizontal :0=0 :2=1 :4=2 :8=3
CameraInit();
while(1)
{
if(CameraFrameCount==11)
{
for (t=0; t<=9120;t++)
{ putch2(CameraBuffer1[t]);
delay(2000); //100us
}
}
}
} |
void CameraStartDma(void)
{
LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) &LPC_GPIO2->FIOPIN;
LPC_GPDMACH0->DMACCDestAddr = (uintptr_t) CameraBuffer1;
LPC_GPDMACH0->DMACCControl = (BlockSize & 0x0FFF)|0x88408000;
LPC_GPDMACH0->DMACCLLI = 0;
LPC_GPDMACH0->DMACCConfig = 0x0000D015;
LPC_GPDMA->DMACIntTCClear = 0x01<<0;
LPC_GPDMA->DMACIntErrClr = 0x01<<0;
LPC_TIM1->IR = 1;/* clear Timer interrupt flag */
}
|
void CameraFrameInterrupt(void)
{
CameraFrameCount ++;
CameraByteCountSum = CameraByteCount;
CameraByteCount = 0;
if (CameraFrameCount < 10)
{
LPC_TIM1->MCR = 3;//on match reset counter + interrupt
}
}
|
volatile unsigned int CameraFrameCount = 0;
volatile unsigned int CameraDMACount = 0;
volatile unsigned int BlockSize = 0x0FFF;
int main(void)
{
//your generic setup function come here
//your serial setup function come here
//your camera setup functons come here
DMA_Init();
CameraInit();
Serial_printString("***LPC Start*** \r");
unsigned int CameraframeDebugCount =0;
while(1)
{
if (CameraframeDebugCount != CameraFrameCount)
{
CameraframeDebugCount = CameraFrameCount;
Serial_printNumber(CameraframeDebugCount);
putch(09); //tab character
Serial_printNumber(CameraDMACount);
putch(09); //tab character
unsigned int t;
for (t=0; t<=10; t++)
{
Serial_printNumber(CameraBuffer1[t + STARTDEBUGATBYTE]);
putch(59); //; character
}
putch(13); //cr character
}
}
}
void CameraDmaTerminalInterrupt(void)
{
CameraDMACount++;
}
void CameraFrameInterrupt(void)
{
CameraFrameCount ++;
CameraStartDma();
}
void CameraStartDma(void)
{
LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) &LPC_GPIO2->FIOPIN;
LPC_GPDMACH0->DMACCDestAddr = (uintptr_t) CameraBuffer1;
LPC_GPDMACH0->DMACCControl = (BlockSize & 0x0FFF)|0x88408000;
LPC_GPDMACH0->DMACCLLI = 0;
}
void CameraInit(void)
{
...
LPC_TIM1->MCR = 2;//on match reset counter + no interrupt
...
}
void DMA_Init( void )
{
/* Enable CLOCK into GPDMA controller */
LPC_SC->PCONP |= (1 << 29);
/* Select secondary function(Timer) in DMA channels */
LPC_SC->DMAREQSEL = 0xFF;
/* Clear DMA channel 0~3 interrupts. */
LPC_GPDMA->DMACIntTCClear = 0x0F;
LPC_GPDMA->DMACIntErrClr = 0x0F;
LPC_GPDMA->DMACConfig = 0x01;/* Enable DMA channels, little endian */
while ( !(LPC_GPDMA->DMACConfig & 0x01) );
NVIC_SetPriority(DMA_IRQn, 30);
NVIC_EnableIRQ(DMA_IRQn);
}
void DMA_IRQHandler(void)
{
uint32_t regVal;
regVal = LPC_GPDMA->DMACIntTCStat;
if ( regVal )
{
LPC_GPDMA->DMACIntTCClear = regVal;
if ( regVal & (0x01<<0) )
{
CameraDmaTerminalInterrupt();
}
}
regVal = LPC_GPDMA->DMACIntErrStat;
if ( regVal )
{
LPC_GPDMA->DMACIntErrClr = regVal;
}
}
|
void CameraInit(void)
{
...
LPC_TIM1->MCR = 0;//no match reset, no interrupt
...
}
|
void CameraFrameInterrupt (void)
{
CameraFrameCount ++;
CameraByteCountSum = LPC_TIM1->TC;
//ResetTimer1
LPC_TIM1->TCR = 3;
LPC_TIM1->TCR = 1;
}
|
i2cCameraWrite(0x11, 0x9d);//1picture/second i2cCameraWrite(0x0c, 0x04); //scale enable i2cCameraWrite(0x3e, 0x1b);//PLCK Divider: :0=0x00/ :2=0x19 :4=0x1A :8=0x1B i2cCameraWrite(0x73, 0xf3);//CLK Divider: :0=0xF0/ :2=0xF1 :4=0xF2 :8=0xF3 i2cCameraWrite(0x72, 0x33);//Picture Divider: Bit4-7=Vertical, Bit0-3=Horizontal :0=0 :2=1 :4=2 :8=3 |