Open loveyu99 opened 1 year ago
/* check SX1302 version */
int32_t u = 0;
while (u == 0){
lgw_reg_r(SX1302_REG_COMMON_VERSION_VERSION, &u);
printf("Note: chip version is 0x%02lX\n", u);
}
This code is OK and the version and model can be read.
/* Get status to check Standby mode has been properly set */
buff[0] = 0x00;
err |= sx1250_reg_r(GET_STATUS, buff, 1, rf_chain);
if ((uint8_t)(TAKE_N_BITS_FROM(buff[0], 4, 3)) != 0x02) {
printf("ERROR: Failed to set SX1250_%u in STANDBY_RC mode\n", rf_chain);
return LGW_REG_ERROR;
}
This code is not OK and cannot read the status.
The underlying SPI communication code used by both is as follows, lgw_spi_r() is the read function of sx1302, sx1250_spi_r is read function of sx1250, The main difference between the two is the target and read address of the first byte:
int lgw_spi_r(uint8_t spi_mux_target, uint16_t address, uint8_t *data) {
HAL_GPIO_WritePin(SPI1_CSN_GPIO_Port, SPI1_CSN_Pin, GPIO_PIN_RESET);
SPI1_WriteByte(spi_mux_target);
SPI1_WriteByte(READ_ACCESS | ((address >> 8) & 0x7F));
SPI1_WriteByte( ((address >> 0) & 0xFF));
for (int i = 0; i < sizeof(data); i++)
data[i] = SPI1_ReadWriteByte(0XFF);
HAL_GPIO_WritePin(SPI1_CSN_GPIO_Port, SPI1_CSN_Pin, GPIO_PIN_SET);
return LGW_SPI_SUCCESS;
}
int sx1250_spi_r(uint8_t spi_mux_target, sx1250_op_code_t op_code, uint8_t data, uint16_t size) { / wait BUSY */ HAL_Delay(1);
/* prepare frame to be sent */
HAL_GPIO_WritePin(SPI1_CSN_GPIO_Port, SPI1_CSN_Pin, GPIO_PIN_RESET);//
SPI1_ReadWriteByte(spi_mux_target); //
SPI1_ReadWriteByte((uint8_t)op_code);
for (int i = 0; i < size; i++)
data[i]=SPI1_ReadWriteByte(0XFF); //
HAL_GPIO_WritePin(SPI1_CSN_GPIO_Port, SPI1_CSN_Pin, GPIO_PIN_SET);//
return LGW_SPI_SUCCESS;
}
May I ask why I can use SPI to read and write to the Sx1302 chip, but I cannot read and write to the Sx1250 chip? The module I am using is the sx1302S module on the market, which contains two sx1250 RF chips internally. May I ask if the beginning of the read section in the code, 0x00, 0x01, and 0sx02, respectively, represent sx1302, sx1250A, and sx1250B? Is the code implemented for multiplexing? I am using this type of code, but the sx1250 RF chip cannot read the return value, which makes me very distressed.