2014-06-03 02:30 AM
Hello
In our project we need the Spi 3 channel to control an Oled display. The display is connected to pins: D6, B3 and B4 so the Spi 3 pins need to be remapped to those pins.The remapping is done in the spi3 init function:void Spi3_Init(void){ GPIO_InitTypeDef GPIO_InitStructure; SPI_InitTypeDef SPI_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3 , ENABLE); ///////////// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_AF_SPI3); GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_SPI3); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_SPI3); /////////////// 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_High; SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI3, &SPI_InitStructure); SPI_Cmd(SPI3, ENABLE); /* Enable the SPI */}After this function is called, we do some basic data sending with this function:while (1){ SPI_I2S_SendData(SPI3, 0x55); Delay_Ms(10);}we did some basic testing with a oscilloscope to check the spi is working but can only see that the clock pin is working. The Mosi pin does nothing. If we make a GPIO pin of the Mosi pin we can toggle the pin.Are there things we have missed? My sincerly2014-06-03 02:51 AM
I know this sounds weird: SPI3 MOSI on PD6 is not an AF_SPI3 (0x06) but 0x05, according the datasheet.
Change your AF config argument with GPIO_AF_SPI1 (or SPI2, SPI4, SPI5, SPI6) or simply 0x05.2014-06-03 06:25 AM
That solved the problem! Thank you for the quick response!