Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

STM32F407xx MCU Configured as Master Tx

Status
Not open for further replies.

retheridge

New Member
Hello Everyone,

I'm currently taking a bare metal driver development course using STM32F407 Discovery Board. My project is to configure the STM MCU to act as a master with no attached slave peripheral. STM32CubeIDE Debug shows the following configuration :

C:
MSTR  = 01
SSI      = 01
SSM    = 01
CPOL and CPHA = 00
OTYPE = Push-Pull
OSPEED = FAST
PUPD Register = None
SPE = 01
char buff[] = "Hello World"

I believe everything is set to the course specification but I am getting no data activity on SCK(PB13) or MOSI(PB15) GPIO Pins. Why am I not receiving data on my EasySync USB Logic Analyzer? Here is a copy of my sending data api :

C:
/*
 * 006_SPI_SendTest.c
 *
 *  Created on: Nov 10, 2022
 *      Author: Rodney Etheridge
 */

/** Setup
 * SPI2_NSS  --> PB12 AF5
 * SPI2_SCLK --> PB13 AF5
 * SPI2_MISO --> PB14 AF5
 * SPI2_MOSI --> PB15 AF5
 */
#include <stdint.h>
#include <string.h>
#include "stm32f407xx_gpio_driver.h"
#include "stm32f407xx_spi_driver.h"

void PinInit()
{
    // Configure MOSI Pin
    GPIO_Handle_t spiPin;
    memset(&spiPin, 0, sizeof(spiPin));

    // Both pins share similar configurations
    spiPin.pGPIOx = GPIOB; // stm32f407xx.h --> line 191 --> #define GPIOB     ((GPIO_RegDef_t*) GPIOB_BADDR)
    spiPin.GPIO_PinConfig.GPIO_PinMode = GPIO_MODE_ALTFN;
    spiPin.GPIO_PinConfig.GPIO_PinAltFunMode = BIT5;
    spiPin.GPIO_PinConfig.GPIO_PinOPType = GPIO_OUTPUT_TYPE_PP;
    spiPin.GPIO_PinConfig.GPIO_PinSpeed = GPIO_SPEED_FAST;
    spiPin.GPIO_PinConfig.GPIO_PinPuPdControl = GPIO_PUPD_NONE;

    // Setting up MOSI pin
    spiPin.GPIO_PinConfig.GPIO_PinNumber = BIT15;
    GPIO_Init(&spiPin);

    // Setting up SCLK pin
    spiPin.GPIO_PinConfig.GPIO_PinNumber = BIT13;
    GPIO_Init(&spiPin);
}

int main()
{

    PinInit();

    // Configure spi2 for master communication
    SPI_Handle_t spi2;
    memset(&spi2, 0, sizeof(spi2));

    spi2.pSPIx = SPI2;
    spi2.SPIConfig.SPI_BusConfig = SPI_BUS_CFG_FULLD;
    spi2.SPIConfig.SPI_DeviceMode = SPI_DEVICE_MODE_MASTER;
    spi2.SPIConfig.SPI_Speed = SPI_CLK_SPEED_DIV2; //
    spi2.SPIConfig.SPI_DFF = SPI_DFF_MODE_8BIT;
    spi2.SPIConfig.SPI_CPHA = SPI_CLKPHA_LOW;
    spi2.SPIConfig.SPI_CPOL = SPI_CLKPOL_LOW;
    spi2.SPIConfig.SPI_SSM = SPI_SSM_ENABLE;
    SPI_Init(&spi2);

    // Manually setting SSI to high to avoid modf error.
    SPI_SSIConfig(spi2.pSPIx, ENABLE);
    spi2.pSPIx->SPI_CR2 |= (1 << 2);
    //spi2.pSPIx->SPI_CR1 |= (1 << 14);

    // Enable device after configuration
    SPI_SetupDevice(spi2.pSPIx, ENABLE);

    // Send data
    char buff[] = "Hello World";
    SPI_SendData(spi2.pSPIx, (uint8_t*)buff, strlen(buff));


    while (1)
    {
        /* code */
    }

    return 0;
}

I have attached copies of my header and driver implementation files. Any suggestions are greatly appreciated.

Thanks,

Rodney
 

Attachments

  • stm32f407xx_gpio_driver.h
    3.1 KB · Views: 134
  • stm32f407xx.h
    11.5 KB · Views: 139
  • stm32f407xx_spi_driver.h
    6.2 KB · Views: 130
  • STM32F407xx.C
    284 bytes · Views: 127
  • stm32f407xx_gpio_driver.c
    7.2 KB · Views: 135
  • stm32f407xx_spi_driver.c
    6.3 KB · Views: 129
Last edited by a moderator:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top