Cortex2014.06.05 13:59
STM32F4 SPI 초기화 함수
void SPI0_Init(void)
{
 SPI_InitTypeDef   SPI_InitStructure;
 GPIO_InitTypeDef GPIO_InitStructure;

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
   
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_SPI1);
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_SPI1);
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_SPI1);
 
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_DOWN;

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

 // Set SPI interface
 SPI_InitStructure.SPI_Direction=SPI_Direction_2Lines_FullDuplex;
 SPI_InitStructure.SPI_Mode=SPI_Mode_Master;
 SPI_InitStructure.SPI_DataSize=SPI_DataSize_8b;
 SPI_InitStructure.SPI_CPOL=SPI_CPOL_Low;
 SPI_InitStructure.SPI_CPHA=SPI_CPHA_1Edge;
 SPI_InitStructure.SPI_NSS=SPI_NSS_Soft;
 SPI_InitStructure.SPI_BaudRatePrescaler=SPI_BaudRatePrescaler_64;
 SPI_InitStructure.SPI_FirstBit=SPI_FirstBit_MSB;
 SPI_InitStructure.SPI_CRCPolynomial=7;

 SPI_Init(SPI1,&SPI_InitStructure);
 SPI_Cmd(SPI1,ENABLE);     //Enable  SPI1
}




STM32F4 SPI Wrire 함수
unsigned char SPI0_WriteReadByte(unsigned char Data)
{
    while((SPI1->SR & SPI_I2S_FLAG_TXE) == RESET);
   
    SPI1->DR =  Data;
    while((SPI1->SR & SPI_I2S_FLAG_RXNE) == RESET);
   
    return (SPI1->DR);
}


'Cortex' 카테고리의 다른 글

STM32F4 SPI Communication  (0) 2014.06.05
Posted by EinSteins
C/C++ Programming2014.03.12 17:39

#include <Windows.h> // API 헤더파일


#include <GdiPlus.h> // GdiPlus 라는 bitmap 라이브러리

using namespace Gdiplus;

#pragma comment(lib,"gdiplus")

#ifdef ULONG_PTR

#define ULONG_PTR unsigned long*

#endif;


#define wx GetSystemMetrics(SM_CXSCREEN) // 모니터 해상도 가로 크기

#define wy GetSystemMetrics(SM_CYSCR HDC hDc = CreateCompatibleDC(GetDC(0));


---------


나중에 다시 작성.. ( Continue.. )

'C/C++ Programming' 카테고리의 다른 글

How to Screen Capture in C++ Using Bitmap Library.  (0) 2014.03.12
Test Module  (0) 2013.11.04
첫 보드게임 온라인 제작 프로젝트 START!!  (0) 2013.10.13
함수 포인터 응용 몇가지.  (0) 2013.08.11
C++ Study LOG.  (0) 2013.08.07
C Code Test.  (0) 2013.07.23
Posted by EinSteins