AnsweredAssumed Answered

Initialize SPI1 problem

Question asked by gluko.lim on Mar 15, 2012
Latest reply on Mar 16, 2012 by mozra
Hi,
I am using STM32F100CBT6B for my development. my hardware engineer had created a custom board, so I am not using the eval board.


My software will communite wil a LCD controller using SPI port. Previously I am using SPI2 and everything works fine. Now, we need to change from SPI2 to SPI1. I had already made all necessary changes, but I am still getting no output from MOSI and SCK pins.


Here I am attaching my code for SPI1 initialization, do I missed out anything?










SPI_InitTypeDef   SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;


RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_SPI1, ENABLE);


// Deinitializes the SPI1
SPI_DeInit(SPI1);


// Release reset of SPI1
RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, DISABLE);


// Configure SPI1_CLK and SPI1_MOSI pins
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_7;
GPIO_Init(GPIOA, &GPIO_InitStructure);


GPIO_PinRemapConfig(GPIO_Remap_SPI1,DISABLE);


// SPI init
SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;
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_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure);
    
// Enable SPI1
SPI_Cmd(SPI1, ENABLE);


while(1)
{
     SPI_SendData(SPI1, 0xAB);
     delayms(200);
     SPI_SendData(SPI1, 0xCD);
     delayms(200);
}

Outcomes