#include "stm32f10x.h" #include "stm32f10x_conf.h" #define BufferSize 32 SPI_InitTypeDef SPI_InitStructure; uint16_t SPI_MASTER_Buffer[BufferSize] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20}; uint16_t TxIdx = 0; //////////////////////////////////////////////////////////////////////////////////////////////////////// //------------------------ RCC konfigurieren ---------------------------------------------------------// //////////////////////////////////////////////////////////////////////////////////////////////////////// void RCC_konfigurieren(void) { RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_SPI1, ENABLE); RCC_ADCCLKConfig(RCC_PCLK2_Div4); /* PCLK2 = HCLK/2 */ RCC_PCLK2Config(RCC_HCLK_Div2); } //////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////// //------------------------ GPIO konfigurieren --------------------------------------------------------// //////////////////////////////////////////////////////////////////////////////////////////////////////// void GPIO_konfigurieren(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Configure SPI_MASTER pins: NSS, SCK and MOSI */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7 | GPIO_Pin_6; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); } //----------------------------------------------------------------------------------------------------// //////////////////////////////////////////////////////////////////////////////////////////////////////// void SPI_Configuration(void) { /* SPI_MASTER configuration ------------------------------------------------------*/ SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;//SPI_Direction_2Lines_FullDuplex; //SPI_Direction_1Line_Tx; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Hard; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 0; SPI_Init(SPI1, &SPI_InitStructure); /* Enable SPI_MASTER NSS output for master mode */ SPI_SSOutputCmd(SPI1, ENABLE); /* Enable SPI_MASTER */ SPI_Cmd(SPI1, ENABLE); } //////////////////////////////////////////////////////////////////////////////////// /////////////////////// M A I N //////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// int main(void) { RCC_konfigurieren(); GPIO_konfigurieren(); SPI_Configuration(); //////////////////////////////////////////////////////////////////////////////////// while(1) { TxIdx=0; while (TxIdx < BufferSize) { while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); /* Send SPI_MASTER data */ SPI_I2S_SendData(SPI1, SPI_MASTER_Buffer[TxIdx++]); } } } ////////////////////////////////////////////////////////////////////////////////////