CN / EN
CN / EN

提问

设计支持

您的项目私密技术问题如需获得一对一支持,请点击下方联系我们。

GH3026移植到国民技术mcu上spi通讯调试 GH3026

291****com

2025-08-25 20:52

我在国民技术的开发板上移植GH3026模块的库,主控是国民的N32G452,选择的通讯方式是SPI,在调用汇顶提供的SDK v4300里面提供的demo,Gh3x2xDemoInit()函数-》GH3X2X_Init()函数里面尝试唤醒芯片时总是失败,读取寄存器0x0036里面的内容是0xf100,却不是0xaa55,请问这个是什么原因呢??

国民的sip初始化如下:

void hal_gh3x2x_spi_init(void)

{

/* init spi and cs pin */

SPI_InitType SPI_InitStructure;

GPIO_InitType GPIO_InitStructure;

/*!< GPIO Periph clock enable */

RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_GPIOB, ENABLE);

/*!< SPI1 Periph clock enable */

RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_SPI1, ENABLE);


/**SPI1 GPIO Configuration

PA5 ------> SPI1_SCK

PA6 ------> SPI1_MISO

PA7 ------> SPI1_MOSI

PB0 ------> SPI1_CS

*/

/*!< Configure SPI1 pins: SCK */

GPIO_InitStructure.Pin = GPIO_PIN_5;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);

/*!< Configure SPI1 pins: MOSI */

GPIO_InitStructure.Pin = GPIO_PIN_7;

GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);

/*!< Configure SPI1 pins: MISO */

GPIO_InitStructure.Pin = GPIO_PIN_6;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);

/*!< Configure SPI1 pin: max86140 CS pin */

GPIO_InitStructure.Pin = GPIO_PIN_0;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure);

/* Configure the SPI1 pin: SPI_INT */

GPIO_InitStructure.Pin = GPIO_PIN_2;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; // 浮空输入模式

GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure);

/*!< SPI configuration */

SPI_InitStructure.DataDirection = SPI_DIR_DOUBLELINE_FULLDUPLEX;

SPI_InitStructure.SpiMode = SPI_MODE_MASTER;

SPI_InitStructure.DataLen = SPI_DATA_SIZE_8BITS;

SPI_InitStructure.CLKPOL = SPI_CLKPOL_HIGH;

SPI_InitStructure.CLKPHA = SPI_CLKPHA_SECOND_EDGE;

SPI_InitStructure.NSS = SPI_NSS_SOFT;

SPI_InitStructure.BaudRatePres = SPI_BR_PRESCALER_16;

SPI_InitStructure.FirstBit = SPI_FB_MSB;

SPI_InitStructure.CRCPoly = 10;

SPI_Init(SPI1, &SPI_InitStructure);

/*!< Enable the SPI1 */

SPI_Enable(SPI1, ENABLE);

}

GU8 hal_gh3x2x_spi_write(GU8 write_buffer[], GU16 length)

{

GU8 ret = 1;

ret = SPI1_ReadWriteByte(write_buffer[0]);

return ret;

}

GU8 SPI_SendByte(GU8 byte)

{

/*!< Loop while DAT register in not emplty */

while (SPI_I2S_GetStatus(SPI1, SPI_I2S_TE_FLAG) == RESET)

;

/*!< Send byte through the SPI1 peripheral */

SPI_I2S_TransmitData(SPI1, byte);

/*!< Wait to receive a byte */

while (SPI_I2S_GetStatus(SPI1, SPI_I2S_RNE_FLAG) == RESET)

;

/*!< Return the byte read from the SPI bus */

return SPI_I2S_ReceiveData(SPI1);

}

// SPI1 读写一个字节

// TxData:要写入的字节

//返回值:读取到的字节

GU8 SPI1_ReadWriteByte(GU8 TxData)

{

GU8 Rxdata;

Rxdata = SPI_SendByte(TxData);

return Rxdata; //返回收到的数据

}

0收藏

0赞成

登录后可回答问题,请 注册

我们时刻倾听您的声音
联系销售

扫描关注公众号

打开微信,使用“扫一扫”即可关注