cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F446, SPI3 MOSI (PC1) doesn't work

deliancourt
Associate II
Posted on July 07, 2015 at 17:14

Hello everybody,

I face to a weird problem and any help could be decisive 🙂 (and I will be grateful of course) I transfer a project which implement USB, I²C and SPI from STM32F407 to STM32F446 but I am unable to do work SPI3. Clock work well, but I have no signal on MOSI pin (PC1). For test this I send in an infinity loop the byte 0xAA

uint8_t dataWriteEnable[1] = {0xAA};
while (1)
{
dataWriteEnable[0]=HAL_SPI_Transmit(&SpiHandle,dataWriteEnable,1,200);
}

My hardware initialisation is below (

SPIx_SCK_GPIO_CLK_ENABLE(),MOSI and MISO...corresponding to GPIOC)

:

void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)
{
GPIO_InitTypeDef GPIO_InitStruct;
if (hspi->Instance == SPIx)
{
/*##-1- Enable peripherals and GPIO Clocks #################################*/
/* Enable GPIO TX/RX clock */
SPIx_SCK_GPIO_CLK_ENABLE();
SPIx_MISO_GPIO_CLK_ENABLE();
SPIx_MOSI_GPIO_CLK_ENABLE();
/* Enable SPI clock */
//SPIx_CLK_ENABLE();
/*##-2- Configure peripheral GPIO ##########################################*/
/* SPI mosi GPIO pin configuration */
GPIO_InitStruct.Pin = GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI3;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
//SPI CS GPIOC13 as chip select (output push pull)
GPIO_InitStruct.Pin = SPIx_CS_PIN;
GPIO_InitStruct.Pull = GPIO_PULLUP;//GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 
HAL_GPIO_Init(SPIx_CS_GPIO_PORT, &GPIO_InitStruct);
//CS = 1
HAL_GPIO_WritePin(SPIx_CS_GPIO_PORT, SPIx_CS_PIN,GPIO_PIN_SET);
//W is on Port G
GPIO_InitStruct.Pin = SPIx_W_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(SPIx_W_PORT, &GPIO_InitStruct);
//w=1 (write enable)
HAL_GPIO_WritePin(SPIx_W_PORT, SPIx_W_PIN,GPIO_PIN_SET);
//hold is on Port I
GPIO_InitStruct.Pin = SPIx_HOLD_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
HAL_GPIO_Init(SPIx_HOLD_PORT, &GPIO_InitStruct);
HAL_GPIO_WritePin(SPIx_HOLD_PORT, SPIx_HOLD_PIN,GPIO_PIN_SET);
}
}

and my SPI inititalisation is :

int8_t configSPI(SPI_HandleTypeDef *hspi, uint32_t BaudRatePrescaler)
{
/*---------------Configure the SPI peripheral---------------------------*/
/*---------------CPOL and CPHA must have the same value-----------------*/
HAL_SPI_DeInit(hspi);
/* Set the SPI parameters */
SpiHandle.Instance = SPIx;
SpiHandle.Init.Mode = SPI_MODE_MASTER;
SpiHandle.Init.BaudRatePrescaler = BaudRatePrescaler;
SpiHandle.Init.Direction = SPI_DIRECTION_2LINES;
SpiHandle.Init.CLKPhase = SPI_PHASE_1EDGE;
SpiHandle.Init.CLKPolarity = SPI_POLARITY_LOW;
SpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
SpiHandle.Init.CRCPolynomial = 7;
SpiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
SpiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;
SpiHandle.Init.NSS = SPI_NSS_SOFT;
SpiHandle.Init.TIMode = SPI_TIMODE_DISABLED;
if(HAL_SPI_Init(hspi) != HAL_OK)
{
/* Initialization Error */
return HAL_ERROR;
}
return HAL_OK;
}

I really don't see why that does not work anymore.
8 REPLIES 8
Posted on July 07, 2015 at 17:53

Toggling the pin ''manually'', when in GPIO Output mode, works?

JW
Posted on July 07, 2015 at 18:07

For the non-dyslexic the OP is complaining about the

http://www.st.com/web/en/resource/technical/document/datasheet/DM00141306.pdf

PC1 should be SPI3_MOSI via AF5, according to the data sheet.

Knowing nothing about your board design, verify PC1 doesn't clash with something at a board level, and like Jan suggests toggle it as a GPIO to confirm it goes high/low as expected.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on July 07, 2015 at 18:13

> For the non-dyslexic the OP is complaining about the

http://www.st.com/web/en/resource/technical/document/datasheet/DM00141306.pdf

There's the correct number of fours and sixs in the original post to assemble the correct part number with some effort... :p

deliancourt
Associate II
Posted on July 08, 2015 at 10:38

Oups apologize me, this is corrected. 

Yes, if I toogle ''manually'' PC1 it's work (in output push pull mode).

Posted on July 08, 2015 at 10:50

I'd try all AFs (starting with AF6) regardless of what is written in the datasheet. I'd also try to output MOSI on all other pins, just to check the problem is not rooted elsewhere. Then, I'd pester ST - after all it is a brand new chip, you might have stumbled upon a silicon bug.

JW

deliancourt
Associate II
Posted on July 08, 2015 at 11:15

Thanks,

I have test PC12 on AF6 and that have not change anything. I will try other AF5 function to see if the problem come from this. I use stm32f407xx.h header on this project even when target is 446 (I have add or change some lines for corresponding with the SPI3 AF5 for example). 

When I try CubeMX generated project that seems work, but if I copy configuration on my actual that not work anymore.

 

deliancourt
Associate II
Posted on July 08, 2015 at 14:10

In fact STMCubeMx project doesn't work. PC1 (MOSI) is always in logical state 0 whereas PC10 and 11 are in logical state 1 when no transfer.

 After tried SPI 1,2,3 and 4 with cubeMx and evaluation board, it is always the same problem clock work but not MOSI (even if clock for SPI4 is on AF5)

nesrine
Senior
Posted on July 09, 2015 at 15:11

Hello deliancourt.sebastie,

I try the example under the STM32cubeF4package/ STM32Cube_FW_F4_V1.6.0\Projects\STM32F429IDiscovery\Examples\SPI\SPI_FullDuplex_ComPolling I do modifications in the soft as follow: 1) In main.c I commented all dependence with Hardware: LEDs configuration, USER Button 2) In main.h I change SPIx pins and SPIx clocks settings :

/* Definition for SPIx clock resources */
#define SPIx SPI3
#define SPIx_CLK_ENABLE() __HAL_RCC_SPI3_CLK_ENABLE()
#define SPIx_SCK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
#define SPIx_MISO_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE() 
#define SPIx_MOSI_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE() 
#define SPIx_NSS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE() 
#define SPIx_FORCE_RESET() __HAL_RCC_SPI3_FORCE_RESET()
#define SPIx_RELEASE_RESET() __HAL_RCC_SPI3_RELEASE_RESET()
/* Definition for SPIx Pins */
#define SPIx_SCK_PIN GPIO_PIN_10
#define SPIx_SCK_GPIO_PORT GPIOC
#define SPIx_SCK_AF GPIO_AF6_SPI3
#define SPIx_MISO_PIN GPIO_PIN_11
#define SPIx_MISO_GPIO_PORT GPIOC
#define SPIx_MISO_AF GPIO_AF6_SPI3
#define SPIx_MOSI_PIN GPIO_PIN_1
#define SPIx_MOSI_GPIO_PORT GPIOC
#define SPIx_MOSI_AF GPIO_AF5_SPI3

3) After this modifications I have the signal on MOSI pin (PC1)!!!