This commit is contained in:
lmx
2025-11-25 16:40:37 +08:00
parent 51788e4b88
commit 8089cf5b3a
3 changed files with 8 additions and 6 deletions

View File

@ -85,7 +85,7 @@ unsigned char FM176XX_SoftReset(void){
unsigned char FM176XX_HardInit(void){
gpio_set_direction(IO_PORTA_05,0); //nss
gpio_set_output_value(IO_PORTA_05, 1); //初始设置为高
spi_open(SPI1); //初始化spi1PC3、PC5
return SUCCESS;
}
@ -107,7 +107,7 @@ unsigned char GetReg(unsigned char address, unsigned char *reg_data){
addr_byte = (address << 1) | 0x01;
// ---- 开始SPI事务 ----
gpio_direction_output(IO_PORTA_05,0);
// gpio_direction_output(IO_PORTA_05,0);
// 1. 发送地址字节,忽略接收到的数据
spi_send_byte(SPI1, addr_byte);
@ -116,7 +116,7 @@ unsigned char GetReg(unsigned char address, unsigned char *reg_data){
*reg_data = spi_recv_byte(SPI1, &err);
// ---- 结束SPI事务 ----
gpio_direction_output(IO_PORTA_05,1);
// gpio_direction_output(IO_PORTA_05,1);
if (err != 0) {
xlog("GetReg error\n");
@ -139,12 +139,12 @@ unsigned char SetReg(unsigned char address, unsigned char reg_data){
unsigned char addr_byte = (address << 1) & 0xFE; // Bit0=0 for write
int err1, err2;
gpio_direction_output(IO_PORTA_05,0); // <<-- CS拉低开始事务
// gpio_direction_output(IO_PORTA_05,0); // <<-- CS拉低开始事务
err1 = spi_send_byte(SPI1, addr_byte); // 发送地址
err2 = spi_send_byte(SPI1, reg_data); // 发送数据
gpio_direction_output(IO_PORTA_05,1); // <<-- CS拉高结束事务
// gpio_direction_output(IO_PORTA_05,1); // <<-- CS拉高结束事务
if (err1 != 0 || err2 != 0) {
return FAIL;