It's nucleo f4 DMA trandfer for ov7670&ILI9341.

Dependencies:   mbed ILI9341_SPI OV7670_SCCB

Committer:
tmnt
Date:
Sun Nov 20 11:30:49 2016 +0000
Revision:
7:2ed3ce710cc2
i

Who changed what in which revision?

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