Ov7670 Camera Drive
===
###### tags: `Microcontroller` `Embedded System`
:::warning
:bulb: Still editing and adding the content.
:::
## Goal
* [ ] Establish communication with OV7670
* [ ] DCMI
* [ ] Uart transmit photo data to PC
* [ ] Show on a screen
## Development
You can read my [developmment article](https://hackmd.io/EUrAmZAxTP2DzLIIrA1sFg), there are problems I have encountered.
### Hardware setup
* STM32Nucleo64_F446RE
* OV7670 without FIFO
* PC
### Pin setup
#### F446RE:

SCCB:
DCMI:
UART: PA2(TX)、PA3(RX)
RCC_MCO: PA8
#### OV7670:

| OV7670| F446RE | OV7670| F446RE |
| -------- | -------- | -------- | -------- |
| 3.3V | 3V3 | GND | GND |
| SCL | PC12 | SDA | PB10 |
| VS | PB7 | HS | PA4 |
| PLK | PA6 | XLK | PA8 |
| D7 | PB9 | D6 | PB8 |
| D5 | PB6 | D4 | PC11 |
| D3 | PC9 | D2 | PC8 |
| D1 | PC7 | D0 | PC6 |
| RET | PB14 | PWDN| PB15 |
### Communication
The first thing to start is to talk to the machine and get its response.
```c
// SCCB
// SCCB is an i2c-like protocal
//
//Read manufacturer ID (High and Low)
*data_write = 0x1c;
HAL_I2C_Master_Transmit(&hi2c2, DevAddress_write, data_write, 2, HAL_MAX_DELAY);// Write regiter address
HAL_I2C_Master_Receive(&hi2c2, DevAddress_read, data_read, 2, HAL_MAX_DELAY);// Receive from that register(Use data_read to catch info)
printf("The manufacturer ID: %d",*data_read);
*data_write = 0x1D;
HAL_I2C_Master_Transmit(&hi2c2, DevAddress_write, data_write, 2, HAL_MAX_DELAY);// Write regiter address
HAL_I2C_Master_Receive(&hi2c2, DevAddress_read, data_read, 2, HAL_MAX_DELAY);// Receive from that register(Use data_read to catch info)
printf("%d\r\n",*data_read);
```
This code is put inside `while(1){......}`. When pushing B1, the camera will return its manufacturer's ID number.

### DCMI
#### Pin connection
8 Pin for Date (DCMI_D[0:7])
1 Pin for Pixel clock (DCMI_PIXCLK)
2 Pin for Synchrnization (DCMI_VSYNC DCMI_HSYNC)