2013-11-12 04:03 PM
Hello experts,
I'm trying to get SPI with DMA running on my STM32F3board. So I wrote this code after a tutorial and the StdPeriph Lib. To test the SPI parameters I wanted to send a 16 bit value and watch on the bus with a logic analyzer without DMA or interrupt. But nothing happens exept all pins going low after init.Here's the code:/* Enable DMA1 clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);/* Enable SPI1 clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1,ENABLE);/* Enable GPIOE clock for SPI1 CS */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE,ENABLE);/* Enable GPIOA clock other SPI1 */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE); GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_5); GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_5); GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_5);/* Chip select */ GPIO_PinAFConfig(GPIOE, GPIO_PinSource3, GPIO_AF_5);/* Set values for SCK and MOSI pins */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;/* SCK pin configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_Init(GPIOA, &GPIO_InitStructure);/* MOSI pin configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_Init(GPIOA, &GPIO_InitStructure);/* MISO pin configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_Init(GPIOA, &GPIO_InitStructure);/* SPI NSS pin configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_Init(GPIOE, &GPIO_InitStructure);/* SPI configuration */ SPI_I2S_DeInit(SPI1); SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;/* CPOL=0 */ SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;/* CPHA=0 */ SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Hard;/* APB2 = 72 MHz ; 72 MHz:8 < 10 MHz */ SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;/* MSB first */ SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 0;/* Act as SPI master */ SPI_InitStructure.SPI_Mode = SPI_Mode_Master;/* Initialize SPI communication */ SPI_Init(SPI1, &SPI_InitStructure);/* Enable SPI peripheral */ SPI_Cmd(SPI1, ENABLE);/* Enable NSS output for master mode */ SPI_SSOutputCmd(SPI1, ENABLE); SPI_I2S_SendData16(SPI1,StartupBuffer[0]);Thanks for any help!Best regards, Florian2013-11-12 04:59 PM
The configuration of PE3 confuses me, this isn't an SPI/AF pin.
To test I'd probably send data in a loop, spinning on TXE before sending each word.2013-11-14 09:26 AM
Thanks a lot for your fast reply!
That was quite easy. Now I took PA4 pin which is SPI_NSS. Data transmitting is working but the NSS doesn't go high after transmission is complete. picture of logic analyzer is attached and the code is above. Perhaps someone could give me an advice on that, would be very nice! Thanks! /* Enable SPI1 clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1,ENABLE); /* Enable GPIOA clock for SPI1 */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE); /* SPI pin mappings */ GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_5); GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_5); GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_5); /* Chip select */ GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_5); /* Set values for SCK and MOSI pins */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; /* SCK pin configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_Init(GPIOA, &GPIO_InitStructure); /* MOSI pin configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_Init(GPIOA, &GPIO_InitStructure); /* MISO pin configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_Init(GPIOA, &GPIO_InitStructure); /* SPI NSS pin configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_Init(GPIOA, &GPIO_InitStructure); /* SPI configuration */ SPI_I2S_DeInit(SPI1); SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b; /* CPOL=0 */ SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; /* CPHA=0 */ SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Hard; /* APB2 = 72 MHz ; 72 MHz:8 < 10 MHz */ SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8; /* MSB first */ SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 0; /* Act as SPI master */ SPI_InitStructure.SPI_Mode = SPI_Mode_Master; /* Initialize SPI communication */ SPI_Init(SPI1, &SPI_InitStructure); /* Enable NSS output for master mode */ SPI_SSOutputCmd(SPI1, ENABLE); /* Enable SPI peripheral */ SPI_Cmd(SPI1, ENABLE); SPI_I2S_SendData16(SPI1,StartupBuffer[0]); ________________ Attachments : logic_analyzer.png : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0Zm&d=%2Fa%2F0X0000000bae%2FjaWLqiztm3wrY6MMNHbpbavC0oNPIOt7azQB4uC_uCA&asPdf=false2013-11-14 10:51 PM