Using CMSIS
Thanks, I found somethings in StdPerif_Driver/src/stm32f4xx_spi.c that I had overlooked.
I have the output send working and TXE event happens., however I still don’t seem to have control over the NSS line.
GPIO_SetBits(SPI1NSS) does not seem to be having any effect.
Can you advise on what I need to look at? Thanks.
void set_as_AF(GPIO_TypeDef* port, uint32_t pin)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = pin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; // push-pull PP or open drain OD
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz; // 2 25 50 100
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(port, &GPIO_InitStructure);
}
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE); // release SPI1 from reset state
GPIO_PinAFConfig(GPIOA,GPIO_Pin_5, GPIO_AF_SPI1); // Connect SPI1 pins to AF5
GPIO_PinAFConfig(GPIOA,GPIO_Pin_7, GPIO_AF_SPI1);
GPIO_PinAFConfig(GPIOA,GPIO_Pin_6, GPIO_AF_SPI1);
GPIO_PinAFConfig(GPIOB,GPIO_Pin_6, GPIO_AF_SPI1);
set_as_AF(GPIOA,GPIO_Pin_5);
set_as_AF(GPIOA,GPIO_Pin_7);
set_as_AF(GPIOA,GPIO_Pin_6);
set_as_AF(GPIOB,GPIO_Pin_6);
SPI_InitTypeDef SPI_InitStruct;
SPI_Cmd(SPI1, DISABLE); // some configs must be done when disabled.
SPI_InitStruct.SPI_Direction=SPI_Direction_2Lines_FullDuplex ;
SPI_InitStruct.SPI_Mode=SPI_Mode_Master;
SPI_InitStruct.SPI_CPOL=SPI_CPOL_High; // SCK=1 s idle
SPI_InitStruct.SPI_CPHA=1; //SPI_CPHA : 2nd transition is data capture edge.
SPI_InitStruct.SPI_NSS=SPI_NSS_Hard; // enable using ext hardware NSS line
SPI_InitStruct.SPI_BaudRatePrescaler=SPI_BaudRatePrescaler_32; // 32,64,128,256
SPI_InitStruct.SPI_FirstBit=SPI_FirstBit_MSB;
SPI_Init(SPI1,&SPI_InitStruct);
SPI1->CR2 |= (uint16_t) SPI_CR2_SSOE; // NSS line as output (the only CR2 reqd is not using INTs)
SPI_Cmd(SPI1, ENABLE);
GPIO_SetBits(GPIOB,GPIO_Pin_6);