2015-09-11 12:52 AM
Hello everybody,
I have a problem in initialization of SPI3 in STM32f I know that the pins of SPI3 are together with JTAG pins, and i've found on the internet how to disable the JTAG pins, but it still does not work. Here is the code:void W5500_SPI_LowLevel_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
GPIO_PinRemapConfig(GPIO_Remap_SWJ_NoJTRST, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
/*!< W5500_SPI_CS_GPIO, W5500_SPI_MOSI_GPIO, W5500_SPI_MISO_GPIO
and W5500_SPI_SCK_GPIO Periph clock enable */
RCC_APB2PeriphClockCmd(W5500_SPI_MOSI_GPIO_CLK | W5500_SPI_MISO_GPIO_CLK | W5500_SPI_SCK_GPIO_CLK, ENABLE);
/*!< W5500_SPI Periph clock enable */
RCC_APB1PeriphClockCmd(W5500_SPI_CLK, ENABLE);
/*!< Configure W5500_SPI pins: SCK */
GPIO_InitStructure.GPIO_Pin = W5500_SPI_SCK_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(W5500_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
/*!< Configure W5500_SPI pins: MOSI */
GPIO_InitStructure.GPIO_Pin = W5500_SPI_MOSI_PIN;
GPIO_Init(W5500_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
/*!< Configure W5500_SPI pins: MISO */
GPIO_InitStructure.GPIO_Pin = W5500_SPI_MISO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(W5500_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
/*!< SPI configuration */
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_2Edge;
// ## NEEEEEEEEEEEEEEEEEEEEED SPI init code modified for SD Card Recognize (SPI mode 0)
//SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
//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(W5500_SPI, &SPI_InitStructure);
/*!< Enable the W5500_SPI */
SPI_Cmd(W5500_SPI, ENABLE);
}
Please tell me what's wrong in my code.
Thank you in advance.
#stm32f103 #jtag #spi3
2015-09-11 03:56 AM
Hi dmitri.calugari.001,
I think that the AFIO clock isn't enabled in your code. You have to add:RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
Then, check the values you provided for:
- W5500_SPI_MOSI_GPIO_CLK
- W5500_SPI_MISO_GPIO_CLK - W5500_SPI_SCK_GPIO_CLK -W5500_SPI_SCK_PIN
-W5500_SPI_MOSI_PIN
-W5500_SPI_MISO_PIN
-W5500_SPI_MISO_GPIO_PORT
-W5500_SPI_MOSI_GPIO_PORT
-W5500_SPI_SPI_GPIO_PORT
-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.
2015-09-11 04:54 AM
Mayla,
thanks for the answer, I've added the line like you have recomended, but it still does not work.The things are defined so:
#define W5500_SPI SPI3
#define W5500_SPI_CLK RCC_APB1Periph_SPI3
#define W5500_SPI_SCK_PIN GPIO_Pin_3 /* PB.3 */
#define W5500_SPI_SCK_GPIO_PORT GPIOB /* GPIOB */
#define W5500_SPI_SCK_GPIO_CLK RCC_APB2Periph_GPIOB
#define W5500_SPI_MISO_PIN GPIO_Pin_4 /* PB.4 */
#define W5500_SPI_MISO_GPIO_PORT GPIOB /* GPIOB */
#define W5500_SPI_MISO_GPIO_CLK RCC_APB2Periph_GPIOB
#define W5500_SPI_MOSI_PIN GPIO_Pin_5 /* PB.5 */
#define W5500_SPI_MOSI_GPIO_PORT GPIOB /* GPIOB */
#define W5500_SPI_MOSI_GPIO_CLK RCC_APB2Periph_GPIOB
2015-09-11 07:05 AM
Does it work if you put this line before the call of GPIO_PinRemapConfig:
RCC_APB2PeriphClockCmd(W5500_SPI_MOSI_GPIO_CLK | W5500_SPI_MISO_GPIO_CLK |\
W5500_SPI_SCK_GPIO_CLK | RCC_APB2Periph_AFIO, ENABLE);
-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.
2015-09-13 09:53 PM
2015-09-13 10:23 PM
... and i have connected the lines to the logic analyser, and it looks so:
(I am sending the 0xAA byte in cycle)2015-09-15 02:36 AM
What version of std are you using?
Try those pins as output and just toggle them to see on the scoop if the hw is ok.2015-09-18 04:54 AM
2015-09-18 04:55 AM
2015-09-18 04:58 AM
Everything is ok now, i have changed the prescaller to 256 and it runs very well.
Thank you for your help.