2013-06-02 06:52 AM
Hi community,
for a few days i try to use the SPI1 on the F4Discovery board. I use the PA5-PA7 pins on AF5. But after my init the code does nothing? What is wrong in my init function? #define Open_SPI_MISO_PIN GPIO_Pin_6 #define Open_SPI_MOSI_PIN GPIO_Pin_7 #define Open_SPI_SCK_PIN GPIO_Pin_5 #define Open_SPI_GPIO_PORT GPIOA #define Open_SPI_GPIO_CLK RCC_AHB1Periph_GPIOA #define Open_SPI_CLK RCC_APB2Periph_SPI1 #define Open_SPI_MISO_SOURCE GPIO_PinSource6 #define Open_SPI_MOSI_SOURCE GPIO_PinSource7 #define Open_SPI_SCK_SOURCE GPIO_PinSource5 #define Open_SPI_MISO_AF GPIO_AF_SPI1 #define Open_SPI_MOSI_AF GPIO_AF_SPI1 #define Open_SPI_SCK_AF GPIO_AF_SPI1 #define Open_SPI_MISO_GPIO_PORT GPIOA #define Open_SPI_MOSI_GPIO_PORT GPIOA #define Open_SPI_SCK_GPIO_PORT GPIOA #define Open_SPI SPI1 void SPI_BusInit(void) { GPIO_InitTypeDef GPIO_InitStructure; SPI_InitTypeDef SPI_InitStructure; //NVIC_InitTypeDef NVIC_InitStructure; //========================================================================================= // Enable GPIO clock //----------------------------------------------------------------------------------------- RCC_AHB1PeriphClockCmd(Open_SPI_GPIO_CLK, ENABLE); //========================================================================================= // Enable SPI clock //----------------------------------------------------------------------------------------- RCC_APB2PeriphClockCmd(Open_SPI_CLK, ENABLE); //========================================================================================= // Configure SPI GPIO //----------------------------------------------------------------------------------------- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = Open_SPI_MISO_PIN | Open_SPI_MOSI_PIN | Open_SPI_SCK_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(Open_SPI_GPIO_PORT, &GPIO_InitStructure); //========================================================================================= //GPIO Alternate functions configuration //----------------------------------------------------------------------------------------- GPIO_PinAFConfig(Open_SPI_MISO_GPIO_PORT, Open_SPI_MISO_SOURCE, Open_SPI_MISO_AF); GPIO_PinAFConfig(Open_SPI_MOSI_GPIO_PORT, Open_SPI_MOSI_SOURCE, Open_SPI_MOSI_AF); GPIO_PinAFConfig(Open_SPI_SCK_GPIO_PORT, Open_SPI_SCK_SOURCE, Open_SPI_SCK_AF); //========================================================================================= // Configure SPI AF //----------------------------------------------------------------------------------------- //SPI_I2S_DeInit(SPI1); SPI_StructInit(&SPI_InitStructure); SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32; // 328kHz //SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; //SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; //SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft | SPI_NSSInternalSoft_Set; SPI_Init(Open_SPI, &SPI_InitStructure); //SPI_CalculateCRC(Open_SPI, DISABLE); SPI_Cmd(Open_SPI, ENABLE);2013-06-02 01:30 PM
> But after my init the code does nothing?
What code? And what is ''does nothing''? JW2013-06-03 01:33 AM
After I init the SPI and write with SPI1->DR = test; the SPI interface doesnt transmit the data. I dont use events or flags I only want to send one data byte...
2013-06-03 03:16 AM
Works here as expected - goes all the way through to __NOP()
Post your code. JW #include ''stm32f4xx.h'' #include ''stm32f4xx_gpio.h'' #include ''stm32f4xx_rcc.h'' #include ''stm32f4xx_spi.h'' #include ''stm32f4xx_syscfg.h'' #include ''misc.h'' #define Open_SPI_MISO_PIN GPIO_Pin_6 #define Open_SPI_MOSI_PIN GPIO_Pin_7 #define Open_SPI_SCK_PIN GPIO_Pin_5 #define Open_SPI_GPIO_PORT GPIOA #define Open_SPI_GPIO_CLK RCC_AHB1Periph_GPIOA #define Open_SPI_CLK RCC_APB2Periph_SPI1 #define Open_SPI_MISO_SOURCE GPIO_PinSource6 #define Open_SPI_MOSI_SOURCE GPIO_PinSource7 #define Open_SPI_SCK_SOURCE GPIO_PinSource5 #define Open_SPI_MISO_AF GPIO_AF_SPI1 #define Open_SPI_MOSI_AF GPIO_AF_SPI1 #define Open_SPI_SCK_AF GPIO_AF_SPI1 #define Open_SPI_MISO_GPIO_PORT GPIOA #define Open_SPI_MOSI_GPIO_PORT GPIOA #define Open_SPI_SCK_GPIO_PORT GPIOA #define Open_SPI SPI1 static void SPI_BusInit(void) { GPIO_InitTypeDef GPIO_InitStructure; SPI_InitTypeDef SPI_InitStructure; //NVIC_InitTypeDef NVIC_InitStructure; //========================================================================================= // Enable GPIO clock //----------------------------------------------------------------------------------------- RCC_AHB1PeriphClockCmd(Open_SPI_GPIO_CLK, ENABLE); //========================================================================================= // Enable SPI clock //----------------------------------------------------------------------------------------- RCC_APB2PeriphClockCmd(Open_SPI_CLK, ENABLE); //========================================================================================= // Configure SPI GPIO //----------------------------------------------------------------------------------------- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = Open_SPI_MISO_PIN | Open_SPI_MOSI_PIN | Open_SPI_SCK_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(Open_SPI_GPIO_PORT, &GPIO_InitStructure); //========================================================================================= //GPIO Alternate functions configuration //----------------------------------------------------------------------------------------- GPIO_PinAFConfig(Open_SPI_MISO_GPIO_PORT, Open_SPI_MISO_SOURCE, Open_SPI_MISO_AF); GPIO_PinAFConfig(Open_SPI_MOSI_GPIO_PORT, Open_SPI_MOSI_SOURCE, Open_SPI_MOSI_AF); GPIO_PinAFConfig(Open_SPI_SCK_GPIO_PORT, Open_SPI_SCK_SOURCE, Open_SPI_SCK_AF); //========================================================================================= // Configure SPI AF //----------------------------------------------------------------------------------------- //SPI_I2S_DeInit(SPI1); SPI_StructInit(&SPI_InitStructure); SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32; // 328kHz //SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; //SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; //SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft | SPI_NSSInternalSoft_Set; SPI_Init(Open_SPI, &SPI_InitStructure); //SPI_CalculateCRC(Open_SPI, DISABLE); SPI_Cmd(Open_SPI, ENABLE); } int main(void) { SPI_BusInit(); SPI1->DR = 0x1234; while (!(SPI1->SR & SPI_SR_TXE)); while(1) { __NOP(); }; }