2016-02-04 01:18 AM
Hi,
I want to use the hardware control of SPI3-NSS pin. I wrote a code for it on the Discovery board with the STM407VG and it works as intended. I use the drivers from the older Discovery bundle, not the STMCube. Upon the command 'SPI_Cmd(SPI3, ENABLE);' the NSS pin goes down as intended, and upon the command 'SPI_Cmd(SPI3, DISABLE);' the NSS pin goes back up, just as it should. But when I download the code to the STM405RG chip which is the target for the Project, nothing happens on the pin. I can't find an errata, does anyone know if the 405RG is defect? Update: I was sure the problem was solved, and edited the post. However, the problem remains: with identical code and using pull-up or no-pull on the target boards make no difference. The code works on the 407 but not on the 405. Here below is the relevant setup code I use. /D/////////////////////////////////////////////////////////////////////////////
// Initilize SPI ///////////////////////////////////////////////////////////////////////////// SPI_InitTypeDef SPI_InitStruct;// Set default values in SPI_InitStruct:
// SPI_InitStruct->SPI_Direction = SPI_Direction_2Lines_FullDuplex; // SPI_InitStruct->SPI_Mode = SPI_Mode_Slave; // SPI_InitStruct->SPI_DataSize = SPI_DataSize_8b; // SPI_InitStruct->SPI_CPOL = SPI_CPOL_Low; // SPI_InitStruct->SPI_CPHA = SPI_CPHA_1Edge; // SPI_InitStruct->SPI_NSS = SPI_NSS_Hard; // SPI_InitStruct->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; // SPI_InitStruct->SPI_FirstBit = SPI_FirstBit_MSB; // SPI_InitStruct->SPI_CRCPolynomial = 7; SPI_StructInit(&SPI_InitStruct);// Customize:
SPI_InitStruct.SPI_Mode = SPI_Mode_Master; #ifdef targetSTMF405RG SPI_InitStruct.SPI_NSS = SPI_NSS_Soft; //workaround for the 405 target #endif SPI_InitStruct.SPI_DataSize = SPI_DataSize_16b; SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;/////////////////////////////////////////////////////////////////////////////
// Initilize GPIO for SPI ///////////////////////////////////////////////////////////////////////////// //GPIO_InitTypeDef GPIO_InitStruct; // Reset GPIO init structure parameters values // GPIO_InitStruct->GPIO_Pin = GPIO_Pin_All; // GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN; // GPIO_InitStruct->GPIO_Speed = GPIO_Speed_2MHz; // GPIO_InitStruct->GPIO_OType = GPIO_OType_PP; // GPIO_InitStruct->GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_StructInit(&GPIO_InitStruct); //GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_12; GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_5; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;GPIO_DeInit(GPIOB);
GPIO_Init(GPIOB, &GPIO_InitStruct);GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; // borde vara PuPd_UP enl Maximkortet #ifdef targetSTMF405RG GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT; //workaround #endif//405 GPIO_DeInit(GPIOA); GPIO_Init(GPIOA, &GPIO_InitStruct); // See datasheet DM00037051.pdf, Table 9 columns AF5 and AF6 for pin mapping #ifdef targetSTMF407VG GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_SPI3); // SPI3_NSS #endif//407 #ifdef targetSTMF405RG GPIO_SetBits(GPIOA, GPIO_Pin_4); #endif//405 GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_AF_SPI3); // SPI3_SCK GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_SPI3); // SPI3_MOSISPI_I2S_DeInit(SPI3);
SPI_Init(SPI3, &SPI_InitStruct); #ifdef targetSTMF407VG SPI_SSOutputCmd(SPI3, ENABLE); #endif//4072016-02-04 02:22 AM
Can you please be more specific, which pin are you talking about (and, is it the same pin on both chips)?
> Upon the command 'SPI_Cmd(SPI3, ENABLE);' the NSS pin goes down as intended, SPI is used as master, I presume. NSS does not go down with setting SPI_CR1.SPE, rather, when SPI starts to transmit (the UM is not very clear on the details, but presumably it is just after the first byte/word has been written into DR, and TXE went low). JW2016-02-04 02:22 AM
Hi PapaD,
There are 2 NSS pins available, which one are you using?Are you configuring the same debug mode (SWD) for both devices?-Mayla-To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2016-02-04 02:31 AM
2016-02-04 02:35 AM
2016-02-04 02:42 AM
Are you sure you have selected the alternate function mode for the NSS pin? Also initialized the SPI to use hardware NSS:
... SPI_InitStructure.SPI_NSS
= SPI_NSS_Hard; ... And you are enabling the SS output handling using the SPI_SSOutputCmd function? ...SPI_SSOutputCmd
(SPI3, ENABLE); ... Read the ''Slave select (NSS) pin management'' section in the reference manual.2016-02-04 02:46 AM
qwer.asdf:
The answer is yes to your questions And as I said, it works on the 407VG target. With the workaround, naturally I do not set up AF for the pin. I posted the relevant part of the code in an update at the first post of this thread. When I debug I check the SPI3 register and there are no differences between targets: Output is enabled, and Master is set.2016-02-04 08:00 AM
So, is it true that in both cases, you transmit through SPI normally (confirmed by oscilloscope), the only difference being that on '407V you see NSS toggling low/high, but on '405 you see NSS always high?
JW2016-02-04 11:46 PM
Jan,
almost correct: The NSS pin is always low on 405RG, confirmed by oscilloscope. At the command 'GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_SPI3);' the NSS pin goes high on the 407 and afterwards it responds at the commands 'SPI_Cmd(SPI3, ENABLE);' where is goes down, and at the commands 'SPI_Cmd(SPI3, DISABLE);' where it goes high. This is how I understood it is supposed to work on the F4 series, by reading a post on this forum by someone from ST. But on the 405RG the pin is always low. I use the '#define tagetSTM405RG' to implement the workaround to get it to toggle on both targets. But the ''right'' code only works on the 407. /D2016-02-05 03:36 AM
> 'GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_SPI3);'
> the NSS pin goes high on the 407
[...] > NSS pin is always low on 405RG, confirmed by oscilloscope. Oh. So, on the '405, if you set A4 as GPIO OUTPUT, set it to high, then change to AF, will it go immediately low, even if SPI is still in after-reset-disabled state? Can you produce a minimal, but complete compilable example exhibiting the problem? You can try to play with these things directly accessing registers in the debugger. JW