TMNTmaker ! / NUCLEO-F446RE_testDCMI

DCMI for f446re ,ov7670

Dependencies:   ILI9341_SPI OV7670_SCCB mbed

SPI_DMAInit.h

Committer:
tmnt
Date:
5 months ago
Revision:
2:a75d27406b2f

File content as of revision 2:a75d27406b2f:

#include "mbed.h"

 

DMA_HandleTypeDef    SPIDma;
SPI_HandleTypeDef   spi1;


void spi_Init() {
    
    
    __DMA2_CLK_ENABLE();
    SPIDma.Instance = DMA2_Stream3;
    SPIDma.Init.Channel = DMA_CHANNEL_3;
    SPIDma.Init.Direction = DMA_MEMORY_TO_PERIPH;
    SPIDma.Init.PeriphInc = DMA_PINC_DISABLE;
    SPIDma.Init.MemInc = DMA_MINC_ENABLE;
    SPIDma.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;  // 8 bit
    SPIDma.Init.MemDataAlignment = DMA_PDATAALIGN_BYTE;     // 8 bit
    SPIDma.Init.Mode =   DMA_CIRCULAR;
    SPIDma.Init.Priority = DMA_PRIORITY_HIGH;
    SPIDma.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
    HAL_DMA_Init(&SPIDma);
    
    // SPI pin
    __GPIOB_CLK_ENABLE();
    GPIO_InitTypeDef spipins;
    spipins.Pin = GPIO_PIN_5|GPIO_PIN_4|GPIO_PIN_3;
    spipins.Mode = GPIO_MODE_AF_PP;
    spipins.Pull = GPIO_PULLDOWN;
    spipins.Speed = GPIO_SPEED_HIGH;
    spipins.Alternate =  GPIO_AF5_SPI1;
    HAL_GPIO_Init(GPIOB, &spipins);
    
 // SPI
   __SPI1_CLK_ENABLE();
    spi1.Init.Mode = SPI_MODE_MASTER;
    spi1.Init.Direction = SPI_DIRECTION_2LINES;
    spi1.Init.DataSize = SPI_DATASIZE_8BIT;
    spi1.Init.CLKPolarity= SPI_POLARITY_LOW;//パリティビット無し
    spi1.Init.CLKPhase = SPI_PHASE_1EDGE;    // transmit only mode 送信のみ
    spi1.Init.NSS = SPI_NSS_SOFT; 
    spi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; 
    spi1.Init.FirstBit = SPI_FIRSTBIT_MSB ;
    spi1.Init.CRCPolynomial = 7;

    spi1.Instance = SPI1;
    spi1.hdmatx = &SPIDma;
   HAL_SPI_Init(&spi1);
     
    
}