无法使用SPI(stm32h743)进行传输。配置问题

时间:2018-08-06 12:00:00

标签: stm32 spi

我正在尝试将stm32h743编码为spi通信,但似乎无法传输。我正在将PA5用作SCK,将PD7用作MOSI。我阅读了参考手册(49.4.9 reference manual)中要求的过程,并在下面编写了代码,但它不会传输0x3(已通过示波器检查)。

    RCC->AHB4ENR |= RCC_AHB4ENR_GPIOAEN;   // clock enable for gpio A,B,D
    RCC->AHB4ENR |= RCC_AHB4ENR_GPIODEN;          
    RCC->AHB4ENR |= RCC_AHB4ENR_GPIOBEN;
    RCC->APB2ENR |= RCC_APB2ENR_SPI1EN;   // enable SPI clock

    GPIOA->MODER &= ~GPIO_MODER_MODER5;   // enable alternate functions for gpioa and d
    GPIOA->MODER |= GPIO_MODER_MODER5_1;  // 0b10 for alternate function, (PIN5)
    GPIOA->AFR[0] |= (0x05 << 5 * 4);      //  AF5 for SPI which is 0101 (it's a 4bit variation)

    GPIOA->MODER &= ~GPIO_MODER_MODER6;  // PIN6
    GPIOA->MODER |= GPIO_MODER_MODER6_1;
    GPIOA->AFR[0] |= (0x05 << 6 * 4);

   GPIOD->MODER &= ~GPIO_MODER_MODER7;  // PIN7
   GPIOD->MODER |= GPIO_MODER_MODER7_1;
   GPIOD->AFR[0] |= (0x05 << 7 * 4);

   SPI1->CFG1=(7u << SPI_CFG1_DSIZE_Pos);  // 8bit data size
   SPI1->CFG2|=SPI_CFG2_MASTER ;  // master mode
   SPI1->CR1|=SPI_CR1_SPE;           // spi enable
   SPI1->CR1|=SPI_CR1_CSTART;        // transfer start
 *(volatile uint8_t *)&SPI1->TXDR = 0x3;

我显然缺少某些配置设置。有什么想法吗?

0 个答案:

没有答案