Skip to main content
Visitor II
October 1, 2024
Solved

STM32F446ZE SPI4 PORTE MISO Pin does not work as required or expected.

  • October 1, 2024
  • 3 replies
  • 1545 views

I am using SPI4 PORTE pins 2,5 and 6. I have a 16 channel ADC hooked up to it. Everything functions as needed on the ADC including. Reset, Averaging setup, channels setup. I can see the MISO pin(Pin 5 PortE changes as the voltage changes. but 0 is read from the DR on the SPI peripheral.

I noticed in the data manual PORTE AF5(Alternate function 5) is assigned to two sets of pins

DS10693 Rev 10 Page 61

PORTE Pin 2 = SPI4_SCK

PORTE Pin 5 = SPI4_MISO

PORTE Pin 6 = SPI4_MOSI

and

PORTE Pin 12 = SPI4_SCK

PORTE Pin 13 = SPI4_MISO

PORTE Pin 14 = SPI4_MOSI

I used CUBEMX to setup the pins for the peripheral, and have double checked it. I use the generated SPI function HAL_SPI_TransmitReceive to get the data.

We also had this part work on two other boards, using a different SPI port.

Do I have to use PORTE pin 13 for the MISO? Why does PORTE Pin 5 not work as advertised?

 

    This topic has been closed for replies.
    Best answer by -MCR-

    Okay, I got it...The AF Register is at 3...I have to dig into why that is. 

    Thank you everyone for your help.

    3 replies

    Graduate II
    October 1, 2024

    PE5 AF5 and PE13 AF5 should both be viable in a one or the other sense.

    What board are we talking about? Make sure there isn't a pin level conflict, that the pin from the IC gets to the point which you are probing. Check schematic, check continuity, check for any solder bridge or resistors in the path.

    Going to need to see more of the board design and code to be able to better understand what's going on.

    -MCR-Author
    Visitor II
    October 1, 2024

    As I said before I can electrically see the data at Pin5 It definitely changes as the voltage changes. I can see the clock, and the MOSI pin 6 works as the ADC is setup properly. So the only thing I can surmise is the pin is not connected to the pin. I checked the project code for any PORTE references and everything is as expected without overrides of the pin in question.

    CUBE MX generated the code

    /**SPI4 GPIO Configuration

    PE2 ------> SPI4_SCK

    PE5 ------> SPI4_MISO

    PE6 ------> SPI4_MOSI

    */

    GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_5|GPIO_PIN_6;

    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

    GPIO_InitStruct.Pull = GPIO_NOPULL;

    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

    GPIO_InitStruct.Alternate = GPIO_AF5_SPI4;

    HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

     

    -MCR-Author
    Visitor II
    October 1, 2024

    This is a in house circuit board.

    Super User
    October 1, 2024

    > I can see the MISO pin(Pin 5 PortE changes as the voltage changes

    Did you measure *directly* at the physical pin?

    Read out and check/post content of SPI and GPIOE registers.

    Another possible exercise is to manually bit-bang the SPI.

    JW

    -MCR-Author
    Visitor II
    October 1, 2024

    Yes I measured it directly on the processor pin.

    Here are the register settings

    PI4 Registers
    ==============
    CR1 = 0x00000354
    CR2 = 0x00000000
    CCRCPR = 0x00000007
    I2SCFGR = 0x00000000
    I2SPR = 0x00000000
    RXCRC = 0x00000000
    SR = 0x00000002
    TXCRC = 0x00000000

    PORTE Registers
    ===============
    AFR = 0x40021020
    BSRR = 0x00000000
    IDR = 0x00003A60
    LCKR = 0x00000000
    MODER = 0x00492920
    ODR = 0x00000800
    OSPEEDR = 0x00823230
    OTYPER = 0x00000000
    PUDR = 0xAA208080

     

     

    -MCR-AuthorAnswer
    Visitor II
    October 1, 2024

    Okay, I got it...The AF Register is at 3...I have to dig into why that is. 

    Thank you everyone for your help.

    Super User
    October 2, 2024

    AF3 for PE5 is TIM9_CH1, so you probably set that somewhere, too.

    If you don't know where, set a data breakpoint (aka watchpoint) on GPIOE_AFR[0] to find out where is it modified.

    JW