DCMI for f446re ,ov7670

Dependencies:   ILI9341_SPI OV7670_SCCB mbed

Committer:
tmnt
Date:
Sun Nov 20 12:06:27 2016 +0000
Revision:
2:a75d27406b2f
ADD PINMAP

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tmnt0:4e2fae6764b6 1#include "mbed.h"
tmnt0:4e2fae6764b6 2
tmnt0:4e2fae6764b6 3
tmnt0:4e2fae6764b6 4
tmnt0:4e2fae6764b6 5DMA_HandleTypeDef SPIDma;
tmnt0:4e2fae6764b6 6SPI_HandleTypeDef spi1;
tmnt0:4e2fae6764b6 7
tmnt0:4e2fae6764b6 8
tmnt0:4e2fae6764b6 9void spi_Init() {
tmnt0:4e2fae6764b6 10
tmnt0:4e2fae6764b6 11
tmnt0:4e2fae6764b6 12 __DMA2_CLK_ENABLE();
tmnt0:4e2fae6764b6 13 SPIDma.Instance = DMA2_Stream3;
tmnt0:4e2fae6764b6 14 SPIDma.Init.Channel = DMA_CHANNEL_3;
tmnt0:4e2fae6764b6 15 SPIDma.Init.Direction = DMA_MEMORY_TO_PERIPH;
tmnt0:4e2fae6764b6 16 SPIDma.Init.PeriphInc = DMA_PINC_DISABLE;
tmnt0:4e2fae6764b6 17 SPIDma.Init.MemInc = DMA_MINC_ENABLE;
tmnt0:4e2fae6764b6 18 SPIDma.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; // 8 bit
tmnt0:4e2fae6764b6 19 SPIDma.Init.MemDataAlignment = DMA_PDATAALIGN_BYTE; // 8 bit
tmnt0:4e2fae6764b6 20 SPIDma.Init.Mode = DMA_CIRCULAR;
tmnt0:4e2fae6764b6 21 SPIDma.Init.Priority = DMA_PRIORITY_HIGH;
tmnt0:4e2fae6764b6 22 SPIDma.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
tmnt0:4e2fae6764b6 23 HAL_DMA_Init(&SPIDma);
tmnt0:4e2fae6764b6 24
tmnt0:4e2fae6764b6 25 // SPI pin
tmnt0:4e2fae6764b6 26 __GPIOB_CLK_ENABLE();
tmnt0:4e2fae6764b6 27 GPIO_InitTypeDef spipins;
tmnt0:4e2fae6764b6 28 spipins.Pin = GPIO_PIN_5|GPIO_PIN_4|GPIO_PIN_3;
tmnt0:4e2fae6764b6 29 spipins.Mode = GPIO_MODE_AF_PP;
tmnt0:4e2fae6764b6 30 spipins.Pull = GPIO_PULLDOWN;
tmnt0:4e2fae6764b6 31 spipins.Speed = GPIO_SPEED_HIGH;
tmnt0:4e2fae6764b6 32 spipins.Alternate = GPIO_AF5_SPI1;
tmnt0:4e2fae6764b6 33 HAL_GPIO_Init(GPIOB, &spipins);
tmnt0:4e2fae6764b6 34
tmnt0:4e2fae6764b6 35 // SPI
tmnt0:4e2fae6764b6 36 __SPI1_CLK_ENABLE();
tmnt0:4e2fae6764b6 37 spi1.Init.Mode = SPI_MODE_MASTER;
tmnt0:4e2fae6764b6 38 spi1.Init.Direction = SPI_DIRECTION_2LINES;
tmnt0:4e2fae6764b6 39 spi1.Init.DataSize = SPI_DATASIZE_8BIT;
tmnt0:4e2fae6764b6 40 spi1.Init.CLKPolarity= SPI_POLARITY_LOW;//パリティビット無し
tmnt0:4e2fae6764b6 41 spi1.Init.CLKPhase = SPI_PHASE_1EDGE; // transmit only mode 送信のみ
tmnt0:4e2fae6764b6 42 spi1.Init.NSS = SPI_NSS_SOFT;
tmnt0:4e2fae6764b6 43 spi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
tmnt0:4e2fae6764b6 44 spi1.Init.FirstBit = SPI_FIRSTBIT_MSB ;
tmnt0:4e2fae6764b6 45 spi1.Init.CRCPolynomial = 7;
tmnt0:4e2fae6764b6 46
tmnt0:4e2fae6764b6 47 spi1.Instance = SPI1;
tmnt0:4e2fae6764b6 48 spi1.hdmatx = &SPIDma;
tmnt0:4e2fae6764b6 49 HAL_SPI_Init(&spi1);
tmnt0:4e2fae6764b6 50
tmnt0:4e2fae6764b6 51
tmnt0:4e2fae6764b6 52}