将数据发送到 SPI1->DR 作为主机时出现问题

问题描述

我尝试使用 SPI 将数据从主设备发送到从设备,

我真的很陌生,我不知道我做错了什么

我不知道这是否与我的 init 配置或我对 spi proccess 的理解有关。 如果有人知道或可以指导我,因为我不知道出了什么问题。


void SPI_init_master(void){
    RCC->AHBENR |= RCC_AHBENR_GPIOBEN; // enable port b clock
    RCC->APB2ENR |= RCC_APB2ENR_SPI1EN; // enable spi clock
    GPIOB->MODER |= 0x00000A80;     // Configure GPIOB pins 3 and 4 and 5 as alternate function 5
    // AFR[0] is the same as AFRL in the reference manual (p. 241)
    GPIOB->AFR[0] |= 0x00555000;    // configure PB3-PB5
//  SPI1->CR1 |= 0x0044; // enable SPI and Master configuration
     SPI1->CR1 |=  (SPI_CR1_SPE | SPI_CR1_MSTR);
}


void SPI_write(uint8_t ch){
    *(__IO uint8_t *)&SPI1->DR = ch;
    while(!(SPI1->SR & SPI_SR_TXE)); // wait until Transmit buffer empty will be 1 - finish to transmit data and the transmit buffer empty
    print("spi_write - data in DR is: ");
    USART2_printCharacter(ch);
    print("\n");
}


char SPI_read(void)
{
    char ch;
    while(!(SPI1->SR & SPI_SR_RXNE));// wait until Receive buffer not empty will be 1 - finish to transmit data and the transmit buffer not empty
    ch = SPI1->DR;
    print("spi_read - data in DR is: ");
    USART2_printCharacter(ch);
    print("\n");
    return ch;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...