问答

汇集网友智慧,解决技术难题

Japloya

TA的家园币:28  

  • 主机SPI0无法接收到从机SPI2数据,反之可以

    使用官方例程,修改了管脚。使用的设备是GD32F303CET648PIN的单片机主SPI0发给从SPI2的数据接收正常从SPI2发给主SPI0的数据不正常代码如下复制#include"gd32f30x.h"#include"gd32f307c_eval.h"#definearraysize10#defineSET_SPI0_NSS_HIGHgpio_bit_set(GPIOA,GPIO_PIN_4);#defineSET_SPI0_NSS_LOWgpio_bit_reset(GPIOA,GPIO_PIN_4);#defineSET_SPI2_NSS_HIGHgpio_bit_set(GPIOA,GPIO_PIN_15);#defineSET_SPI2_NSS_LOWgpio_bit_reset(GPIOA,GPIO_PIN_15);uint32_tsend_n=0,receive_n=0;uint8_tspi0_send_array[arraysize]={0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA};uint8_tspi2_send_array[arraysize]={0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA};uint8_tspi0_receive_array[arraysize];uint8_tspi2_receive_array[arraysize];ErrStatusmemory_compare(uint8_t*src,uint8_t*dst,uint8_tlength);voidrcu_config(void);voidgpio_config(void);voidspi_config(void);/*!\briefmainfunction\paramnone\param[out]none\retvalnone*/intmain(void){/*initled2andled3*/gd_eval_led_init(LED2);gd_eval_led_init(LED3);/*peripheralclockenable*/rcu_config();/*GPIOconfig*/gpio_config();/*SPIconfig*/spi_config();SET_SPI0_NSS_HIGH/*SPIenable*/spi_enable(SPI2);spi_enable(SPI0);SET_SPI0_NSS_LOW/*waitfortransmitcomplete*/while(send_n<arraysize){while(RESET==spi_i2s_flag_get(SPI2,SPI_FLAG_TBE));spi_i2s_data_transmit(SPI2,spi2_send_array[send_n]);while(RESET==spi_i2s_flag_get(SPI0,SPI_FLAG_TBE));spi_i2s_data_transmit(SPI0,spi0_send_array[send_n++]);while(RESET==spi_i2s_flag_get(SPI2,SPI_FLAG_RBNE));spi2_receive_array[receive_n]=spi_i2s_data_receive(SPI2);while(RESET==spi_i2s_flag_get(SPI0,SPI_FLAG_RBNE));spi0_receive_

    MCU GD32

    2021-11-25 9