Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to read the sx1250 RF chip #105

Open
loveyu99 opened this issue May 3, 2023 · 1 comment
Open

Unable to read the sx1250 RF chip #105

loveyu99 opened this issue May 3, 2023 · 1 comment

Comments

@loveyu99
Copy link

loveyu99 commented May 3, 2023

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.

@loveyu99
Copy link
Author

loveyu99 commented May 3, 2023

/* 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;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant