<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > STM32直接驅(qū)動ov7670 開發(fā)筆記

          STM32直接驅(qū)動ov7670 開發(fā)筆記

          作者: 時間:2016-11-11 來源:網(wǎng)絡(luò) 收藏
          很久沒更新技術(shù)日志了,最近在調(diào)試OV7670攝像頭,之中遇見了不少的麻煩。什么花屏啦,彩條不正常呀,等等,很多很多。經(jīng)過一周的調(diào)試可算是調(diào)試出來了;期間在網(wǎng)上也查了很多,我想大家都會發(fā)現(xiàn)盡然都不能用,網(wǎng)上配置的寄存器表都是有錯誤的(對于沒有fifo的,有fifo的我沒試過),我花了一天時間認(rèn)認(rèn)真真的把OV7670的英文手冊看了一遍,發(fā)現(xiàn)中文手冊錯的的太多了,就算是英文手冊里有幾個寄存器也沒說清楚,實(shí)驗(yàn)和手冊說的不統(tǒng)一。直接驅(qū)動攝像頭的話STM32可以做到一幀(網(wǎng)上說用DMA方式,我是沒辦法實(shí)現(xiàn)),雖然做出來意義不大,但是可以學(xué)習(xí)攝像頭這方面很多知識。
          經(jīng)過我的調(diào)試發(fā)現(xiàn),要成功的關(guān)鍵:首先是時鐘的初始化,直接驅(qū)動時時鐘設(shè)置和寄存器設(shè)定常理不一樣(這有可能是因?yàn)橹苯域?qū)動太慢的緣故)下面代碼我會詳細(xì)說明;第二個是圖像數(shù)據(jù)的讀取很容易丟失掉第一個字節(jié),(這是很多花屏的原因,很重要很重)最后就會出現(xiàn)反色呀,有規(guī)律的花屏呀,圖像不正常等等(有fifo的肯定就不會有這些情況);第三是增益控制,因?yàn)橹苯域?qū)動速度是相當(dāng)慢的所以得把增益關(guān)掉,如果圖像全是白的,或者很紅有可能就是這原因。第四就是圖像窗口和圖像格式的設(shè)置,下面我把寄存器配置貼出來,注意下面的代碼只適合直接驅(qū)動方式(時鐘由STM32產(chǎn)生)。
          /**********很重要內(nèi)部時鐘分頻如果是直接驅(qū)動必須為0x80(不知道為何 直接使用外部時鐘顏色不對ox40時)原因是數(shù)據(jù)起始讀取不對 (0x40是容易把第一個數(shù)據(jù)丟掉,要特別注意)****/
          {0x11,(0x040|0x00)},
          /********0x3a 和 0x3d *************/
          /***0x3d com13 [1] 0x3a TSLB [3]
          * 1 1 VYUY
          ********************************************/
          {0x3a,0x04},//yuv輸出順序
          {0x3d,0xc2},//110000010 位[6]:UV飽和度標(biāo)準(zhǔn)-UV自動調(diào)整
          /********0X12 AND 0X40*************
          *這兩個決定了輸出圖像的格式
          **********************************/
          {0x12,0x14},//輸出圖片模式為QVGA RGB
          {0X40,0xd0},//輸出數(shù)據(jù)范圍 rgb565使能
          {0x1e,0x17},//水平鏡像/豎直翻轉(zhuǎn)使能 //0x17為正面 37是鏡面
          /****0x17 18 32 0x19 1a 0a *******
          *開窗口的大小設(shè)置
          ***********************************/
          {0x17,0x16},//hstart
          {0x18,0x04},//hstop
          {0x32,0x80},//href
          {0x19,0x02},
          {0x1a,0x7b},//0x7a
          {0x03,0x0a},//幀豎直方向控制 0x0a
          /**********************************/
          {0x0c,0x00},//
          {0x3e,0x00},//pclk分頻
          /***********
          *圖像和測試開關(guān)
          ************************/
          {0x70,0x3a},//測試圖案
          {0x71,0x35},//測試圖案 35
          {0x72,0x11},//dcw控制 設(shè)置亞抽樣率 320*240
          {0x73,0xf0},//dsp縮放時鐘f0 f0
          {0x55,0x00},//亮度控制 0x00最亮 00
          {0x56,0x80},//對比度控制 80
          {0xa2,0x02},//像素始終延遲
          {0x7a,0x20},//伽馬校正
          {0x7b,0x10},
          {0x7c,0x1e},
          {0x7d,0x35},
          {0x7e,0x5a},
          {0x7f,0x69},
          {0x80,0x76},
          {0x81,0x80},
          {0x82,0x88},
          {0x83,0x8f},
          {0x84,0x96},
          {0x85,0xa3},
          {0x86,0xaf},
          {0x87,0xc4},
          {0x88,0xd7},
          {0x89,0xe8},
          {0x13,0xef},//agc/aec/awb使能 條紋濾波
          /*********增益控制********
          *慢速是要關(guān)掉
          *******************************/
          {0x00,0x00},//自動增益控制 ff
          /****曝光值 該寄存器提供[9:2] 07 AEGHH[15:10] 04COM1[1:0]******/
          {0x07,0x00},
          {0x10,0x00},
          {0x04,0x00},
          {0x0d,0x00},//different 0x60 10
          {0x42,0x40},//aec窗口 0x80
          {0x14,0x18},//自動增益限度 固定aec/agc
          {0xa5,0x08},//50Hz條紋濾波器步長限制 0x08
          {0xab,0x08},//60Hz條紋濾波器步長限制 0x08
          {0x24,0x75},//AGC/AEC-穩(wěn)定運(yùn)行區(qū)域(上限)
          {0x25,0x63},//AGC/AEC-穩(wěn)定運(yùn)行區(qū)域(下限)
          {0x26,0xd4},//AGC/AEC快速運(yùn)行區(qū)域
          {0x9f,0x78},
          {0xa0,0x68},
          {0xa1,0x03},
          {0xa6,0xd8},
          {0xa7,0xd8},
          {0xa8,0xf0},
          {0xa9,0x90},
          {0xaa,0x14},
          {0x13,0xe5},//打開agc aec
          {0x0e,0x61},
          {0x0f,0x4b},
          {0x16,0x02},
          {0x21,0x02},
          {0x22,0x91},
          {0x29,0x07},
          {0x33,0x0b},
          {0x35,0x0b},
          {0x37,0x1d},
          {0x38,0x71},
          {0x39,0x2a},
          {0x3c,0x78},
          {0x4d,0x40},
          {0x4e,0x20},
          {0x69,0x00},//固定增益控制
          /*****這個很重要 直接驅(qū)動時不能設(shè)為0x00***/
          {0x6b,0x0a},//pll 內(nèi)部ld0
          {0x74,0x10},
          {0x8d,0x4f},
          {0x8e,0x00},
          {0x8f,0x00},
          {0x90,0x00},
          {0x91,0x00},
          {0x92,0x19},
          {0x96,0x00},
          {0x9a,0x80},
          {0xb0,0x84},
          {0xb1,0x0c},
          {0xb2,0x0e},
          {0xb3,0x82},
          {0xb8,0x0a},
          {0x43,0x0a},
          {0x44,0xf0},
          {0x45,0x34},
          {0x46,0x58},
          {0x47,0x28},
          {0x48,0x3a},
          {0x59,0x88},
          {0x5a,0x88},
          {0x5b,0x44},
          {0x5c,0x67},
          {0x5d,0x49},
          {0x5e,0x0e},
          {0x64,0x04},
          {0x65,0x20},
          {0x66,0x05},
          {0x94,0x04},
          {0x95,0x08},
          {0x6c,0x0a},
          {0x6d,0x55},
          {0x6e,0x11},
          {0x6f,0x9f},//0x9e for advanced AWB
          {0x6a,0x40},
          {0x01,0x40},
          {0x02,0x40},
          {0x13,0xe7},
          {0x4f,0x86},//80/86/8c/93/99
          {0x50,0x86},//80/86/8c/93/99
          {0x51,0x00},//00/00/00/00/00
          {0x52,0x23},//22/23/25/27/28
          {0x53,0x62},//5e/62/67/6c/70
          {0x54,0x86},//80/86/8c/93/99
          {0x58,0x9e},
          {0x41,0x08},
          {0x3f,0x1f},//邊緣增強(qiáng)調(diào)整 位[4:0]:邊緣增強(qiáng)系數(shù)
          {0x75,0x10},//位[4:0]:邊緣增強(qiáng)下限 0x0f
          {0x76,0xc0},//位[4:0]:邊緣增強(qiáng)上限 0x01
          {0x4c,0xff},//噪聲抑制強(qiáng)度
          {0x77,0x01},
          {0x3d,0xc2},//110000010 位[6]:UV飽和度標(biāo)準(zhǔn)-UV自動調(diào)整
          {0x4b,0x09},
          {0xc9,0xf0},//飽和度控制
          {0x41,0x3a},//針對YUV邊緣增強(qiáng)閾值自動調(diào)整 AWB增益使能
          {0x34,0x11},
          {0x3b,0x0a},
          {0xa4,0x88},
          {0x96,0x00},
          {0x97,0x30},
          {0x98,0x20},
          {0x99,0x30},
          {0x9a,0x84},
          {0x9b,0x29},
          {0x9c,0x03},
          {0x9d,0x4b},
          {0x9e,0x3f},
          {0x78,0x04},
          {0x79,0x01},
          {0xc8,0xf0},
          {0x79,0x0f},
          {0xc8,0x00},
          {0x79,0x10},
          {0xc8,0x7e},
          {0x79,0x0a},
          {0xc8,0x80},
          {0x79,0x0b},
          {0xc8,0x01},
          {0x79,0x0c},
          {0xc8,0x0f},
          {0x79,0x0d},
          {0xc8,0x20},
          {0x79,0x09},
          {0xc8,0x80},
          {0x79,0x02},
          {0xc8,0xc0},
          {0x79,0x03},
          {0xc8,0x40},
          {0x79,0x05},
          {0xc8,0x30},
          {0x79,0x26},
          {0x2d,0x00},
          {0x2e,0x00},
          這個配置表一般就可以出圖像了,或許你還出不來的話就得看看你用的STM32是不是fsmc接口驅(qū)動的lcd,如果不是那就99%不行了。有了配置表我在把主函數(shù)貼出來,大家可以改進(jìn)算法,最近也沒時間再改進(jìn)了(因?yàn)槲易罱K的任務(wù)是驅(qū)動CCD所以cmos只是一個過場);想要提高水品還得靠自己。
          主程序(關(guān)鍵代碼):
          void main(void)
          {
          uint32_t PCnt=0;
          static uint8_t Cnt= 0;
          u16 value=0,val1=0,val2=0,REG=0;
          /**************************/
          SysTick_Init();
          TIME2_Init( );
          START_TIME;
          Init_CCD_OV7670( );
          LCD_Init();
          Delay_us(20);
          LCD_REG=R34;
          CCD_EXTI_Init( );
          while(1)
          {
          PCnt = 0;
          Cnt = 1;
          XClock_Init( ); //OV7670 XCLK 開 (我用的是TIM2產(chǎn)生PWM波,開關(guān)只要改變相應(yīng)引腳狀態(tài)就好了)
          while(value & 0x0004) value = GPIOE->IDR; // Vsync=H
          while(~value & 0x0004) value = GPIOE->IDR; // Vsync=L
          XClock_OUT(); //OV7670 XCLK 關(guān)
          /*******直接使用時鐘時要加一個低電平*************
          *不然會把第一個字節(jié)丟掉,產(chǎn)生反色或者是花紋的現(xiàn)象
          *正常數(shù)據(jù) (R G B) (R G B) (R G B )
          *丟失第一字節(jié) (G B R) (G B R) (G B
          ************************************************/
          XCLK_L;
          while(PCnt<76800)
          {
          XCLK_H;
          XCLK_L;
          REG = GPIOE->IDR;
          if(REG&0x0002) // HREF = H 水平信號高時有數(shù)據(jù)
          {
          if(REG&0x0001){ //PCLK = H 再次判斷像素時鐘是不是高
          value = GPIOC->IDR;
          if((Cnt == 1))// 高字節(jié)
          {
          val1=(value<<8);
          Cnt=0;
          }
          else // 低字節(jié)
          {
          val2=(value&0x00ff);
          Cnt = 1;
          LCD_RAM =val1 |val2; //(我用的是fsmc接口所以才可以這樣寫)
          PCnt ++;
          }
          }
          }
          }
          }
          }
          //快的時鐘一定要用定時器的PWM功能,定時器中斷翻轉(zhuǎn)電平是無法實(shí)現(xiàn)的,切記。
          好了就寫這么多,應(yīng)該對大家有幫助。



          關(guān)鍵詞: STM32驅(qū)動ov767

          評論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();