cancel
Showing results for 
Search instead for 
Did you mean: 

Currently we make use of three SPI busses on a STM32F405. SPI1 is a slave and SPI 2/3 are masters. I switch SPI1 to master mode and it just doesn't work. I suspect the APB2 bus but I think I have it set correctly.

MBish.1
Associate II

Here's my code:

SPI_HandleTypeDef spi_handle =
    {
        .Instance = DEF_SPI_INS_SPI1,
        .Init =
        {
            .Direction          = SPI_DIRECTION_2LINES,
            .BaudRatePrescaler  = SPI_BAUDRATEPRESCALER_2, 
            .CLKPhase           = SPI_PHASE_2EDGE,          
            .CLKPolarity        = SPI_POLARITY_HIGH,       
            .CRCCalculation     = SPI_CRCCALCULATION_DISABLE,
            .CRCPolynomial      = 0U, // unused
            .DataSize           = SPI_DATASIZE_8BIT,
            .FirstBit           = SPI_FIRSTBIT_MSB,
            .NSS                = SPI_NSS_SOFT,
            .TIMode             = SPI_TIMODE_DISABLE,
            .Mode               = SPI_MODE_MASTER
        }
    };
 
    HAL_StatusTypeDef return_code;
    return_code = HAL_SPI_Init(&spi_handle);
    uint8_t data[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
    uint8_t rx_data[16];
 
    HAL_SPI_Abort(&spi_handle);
    __HAL_SPI_ENABLE(&spi_handle);
    //return_code = HAL_SPI_Transmit(&spi_handle, data, 8, 5);
    return_code = HAL_SPI_TransmitReceive(&spi_handle, data, rx_data, 8, 100);
 
    while (HAL_SPI_GetState(&spi_handle) != HAL_SPI_STATE_READY);

return_code from HAL_SPI_Init() == HAL_OK

return code from HAL_SPI_TransmitReceive() == HAL_OK

I get past the while{} loop.

SPI register settings:


_legacyfs_online_stmicro_images_0693W00000bklpzQAA.pngPIOA settings (pins 5 = SCLK, 6 = MOSI, 7 = MISO):


_legacyfs_online_stmicro_images_0693W00000bkhu2QAA.png
_legacyfs_online_stmicro_images_0693W00000bkhuqQAA.png
_legacyfs_online_stmicro_images_0693W00000bkhugQAA.png
_legacyfs_online_stmicro_images_0693W00000bkhuCQAQ.pngRCC register settings:


_legacyfs_online_stmicro_images_0693W00000bkhv5QAA.png
_legacyfs_online_stmicro_images_0693W00000bkhvPQAQ.png 

I've played around with the prescaler CLK phase and polarity. One note, CLK never idles HIGH with CPOL = SPI_POLARITY_HIGH.

What am I missing?

This is all I get when I am in master mode:

Also note, I am not wiggling a CS right now - just trying to see a CLK and some data.


_legacyfs_online_stmicro_images_0693W00000bkhwcQAA.pngWhen I build it in slave mode and send data to the chip I see nice wiggles in all the right places and the micro reads the data correctly and sends back data to the remote SPI master. When I am doing this mcu SPI master testing, I have the remote master device disconnected and just have the logic analyzer connected.

1 ACCEPTED SOLUTION

Accepted Solutions
MBish.1
Associate II

This was a hardware issue.

View solution in original post

6 REPLIES 6

Are you sure you want SPI_CR1.BIDIMODE be set?

JW

I tried it again with that cleared, updated the image and still the same results.

OK so set SCK to GPIO Output and try to wiggle it "manually" and observe.

JW

I can't wiggle the old CLK and SDI. I can wiggle SDO.

What external device is connected to the SPI signals? Is whatever used to be the master still connected? If so, it is probably driving those signals.

MBish.1
Associate II

This was a hardware issue.