2019-08-27 04:07 AM
Hi
I tried to develop my own code for s2lp on NUCLEO-L476RG
my setup include:
NUCLEO-L476RG+s2lp FKI433v2 on top(RX working fine)
NUCLEO-L476RG+s2lp FKI433v2 on top(TX cant go to TX mode)
NUCLEO-L053R8+s2lp FKI433v2 on top(as a test for both RX and TX)
I was able to receive messages with the my code on the RX side the message was from the L053R to my L47RG
However when I Tried to send From TX L476RG it Wouldn't send Nor Got to TX mode
I know this because i saw the S2lp status Bit after I sent the TX Command it didn't go to TX MODE but Went to Ready only
The status Bits were(52 1)
I am using kiel V5 and did initialize with Cube MX
void FLUSH_FIFO(){
UARTBuf[21]=COMMAND_FLUSHRXFIFO ;
HAL_SPI_Transmit(&hspi1 , &UARTBuf[20],2,500);
HAL_GPIO_WritePin(SDA_GPIO_Port, SDA_Pin, GPIO_PIN_SET);
HAL_Delay(50);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET);
UARTBuf[20]=0x80;
UARTBuf[21]=COMMAND_FLUSHTXFIFO ;
HAL_SPI_Transmit(&hspi1 , &UARTBuf[20],2,500);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET);}
void TX_MODE()
{UARTBuf[20]=0x80;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET);
UARTBuf[0]=0x80;
UARTBuf[1]=COMMAND_TX ;
HAL_SPI_Transmit(&hspi1 , &UARTBuf[0],2,500);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET);
}
void RX_MODE()
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET);
UARTBuf[0]=0x80;
UARTBuf[1]=COMMAND_RX ;
HAL_SPI_Transmit(&hspi1 , &UARTBuf[0],2,500);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET);
}
void READY_MODE()
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET);
UARTBuf[0]=0x80;
UARTBuf[1]=COMMAND_READY ;
HAL_SPI_Transmit(&hspi1 , &UARTBuf[0],2,500);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET);
}
void S2LPSpiWriteRegisters(uint8_t adress,uint8_t number, uint8_t *conetent)
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET);
UARTBuf[0]=0x00;
UARTBuf[1]= adress;
UARTBuf[2]= conetent[0];
UARTBuf[3]= conetent[1];
UARTBuf[4]= conetent[2];
UARTBuf[5]= conetent[3];
UARTBuf[6]= conetent[4];
UARTBuf[7]= conetent[5];
UARTBuf[8]= conetent[6];
HAL_SPI_Transmit(&hspi1 , &UARTBuf[0],number+2,50);//mode
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET);
}
void S2LPSpiWriteRegisters1(uint8_t adress,uint8_t number, uint8_t *conetent)
{
HAL_GPIO_WritePin(SDA_GPIO_Port, SDA_Pin, GPIO_PIN_RESET);
buffer1[0]=0x00;
buffer1[1]= adress;
HAL_SPI_Transmit(&hspi1 , &buffer1[0],2,50);//mode
HAL_SPI_Transmit(&hspi1 , &UARTBuf[0],178,500);//mode
HAL_GPIO_WritePin(SDA_GPIO_Port, SDA_Pin, GPIO_PIN_SET);
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
MX_SPI1_Init();
/* USER CODE BEGIN 2 */
uint8_t i=0;
HAL_GPIO_WritePin(SDN_GPIO_Port, SDN_Pin, GPIO_PIN_RESET);
HAL_Delay(50);
HAL_GPIO_WritePin(SDN_GPIO_Port, SDN_Pin, GPIO_PIN_SET);
HAL_Delay(50);
HAL_GPIO_WritePin(SDN_GPIO_Port, SDN_Pin, GPIO_PIN_RESET);//HAL_GPIO_WritePin(GPIOC, GPIO_PIN_1, GPIO_PIN_RESET);HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET);
HAL_Delay(50);
READY_MODE();
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
tmp[0] = 0x72; /* reg. SYNT3 (0x05) */
tmp[1] = 0x2A; /* reg. SYNT2 (0x06) */
tmp[2] = 0x3D; /* reg. SYNT1 (0x07) */
tmp[3] = 0x1B; /* reg. SYNT0 (0x08) */
tmp[4] = 0x2F; /* reg. IF_OFFSET_ANA (0x09) */
tmp[5] = 0xC2; /* reg. IF_OFFSET_DIG (0x0A) */
S2LPSpiWriteRegisters(0x05, 6, tmp);
tmp[0] = 0x92; /* reg. MOD4 (0x0E) */
tmp[1] = 0xA7; /* reg. MOD3 (0x0F) */
tmp[2] = 0x27; /* reg. MOD2 (0x10) */
S2LPSpiWriteRegisters(0x0E, 3, tmp);
tmp[0] = 0xA3; /* reg. MOD0 (0x12) */
tmp[1] = 0x13; /* reg. CHFLT (0x13) */
S2LPSpiWriteRegisters(0x12, 2, tmp);
tmp[0] = 0x55; /* reg. ANT_SELECT_CONF (0x1F) */
S2LPSpiWriteRegisters(0x1F, 1, tmp);
tmp[0] = 0x00; /* reg. PCKTCTRL3 (0x2E) */
tmp[1] = 0x01; /* reg. PCKTCTRL2 (0x2F) */
tmp[2] = 0x30; /* reg. PCKTCTRL1 (0x30) */
S2LPSpiWriteRegisters(0x2E, 3, tmp);
tmp[0] = 0x01; /* reg. PROTOCOL1 (0x3A) */
S2LPSpiWriteRegisters(0x3A, 1, tmp);
tmp[0] = 0x40; /* reg. FIFO_CONFIG3 (0x3C) */
tmp[1] = 0x40; /* reg. FIFO_CONFIG2 (0x3D) */
tmp[2] = 0x40; /* reg. FIFO_CONFIG1 (0x3E) */
tmp[3] = 0x40; /* reg. FIFO_CONFIG0 (0x3F) */
tmp[4] = 0x41; /* reg. PCKT_FLT_OPTIONS (0x40) */
S2LPSpiWriteRegisters(0x3C, 5, tmp);
tmp[0] = 0x1D; /* reg. PA_POWER8 (0x5A) */
S2LPSpiWriteRegisters(0x5A, 1, tmp);
tmp[0] = 0x07; /* reg. PA_POWER0 (0x62) */
tmp[1] = 0x01; /* reg. PA_CONFIG1 (0x63) */
S2LPSpiWriteRegisters(0x62, 2, tmp);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
TX_MODE();
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SPIBuf_WRITE[0]=0x00;//reead
SPIBuf_WRITE[1]=0xff;// regester
SPIBuf_READ[0]=0x0;SPIBuf_READ[1]=0xcc;SPIBuf_READ[2]=0;SPIBuf_READ[3]=0;SPIBuf_READ[4]=0;SPIBuf_READ[5]=0;SPIBuf_READ[6]=0;SPIBuf_READ[7]=0;SPIBuf_READ[8]=0;
// SPIBuf_WRITE_REGESTER[0]=0x00;SPIBuf_WRITE_REGESTER[1]=0x3c;SPIBuf_WRITE_REGESTER[2]=0xff;SPIBuf_WRITE_REGESTER[3]=0xff;SPIBuf_WRITE_REGESTER[4]=0;SPIBuf_WRITE_REGESTER[5]=0;SPIBuf_WRITE_REGESTER[6]=0;SPIBuf_WRITE_REGESTER[7]=0;SPIBuf_WRITE_REGESTER[8]=0;
// HAL_GPIO_WritePin(SDN_GPIO_Port, SDN_Pin, GPIO_PIN_RESET);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
HAL_Delay(500);
for(i=0;i<=40;i++){
SPIBuf_READ[i]='0';
} i=0;
HAL_GPIO_WritePin(SDA_GPIO_Port, SDA_Pin, GPIO_PIN_RESET);
HAL_SPI_TransmitReceive(&hspi1, &SPIBuf_WRITE[0], &SPIBuf_READ[0], 18,1000);
HAL_Delay(500);
HAL_GPIO_WritePin(SDA_GPIO_Port, SDA_Pin, GPIO_PIN_SET);
sprintf( buffer3, "\r\n RECIVED @ adress %x is = [%x %x %x %x %x %x %x %x %x ] \r\n",SPIBuf_WRITE[1],SPIBuf_READ[0],SPIBuf_READ[1],SPIBuf_READ[2],SPIBuf_READ[3],SPIBuf_READ[4],SPIBuf_READ[5],SPIBuf_READ[6],SPIBuf_READ[7],SPIBuf_READ[8]);
for(i=0;i<=strlen(buffer3);i++){
buffer1[i]=buffer3[i];
} i=0;
// sprintf( buffer3, "\r\n RECIVED is = [%c %c %c %c %c %c %c %c ] \r\n",UARTBuf[42],UARTBuf[43],UARTBuf[44],UARTBuf[45],UARTBuf[46],UARTBuf[47],UARTBuf[48],UARTBuf[49]);
HAL_UART_Transmit(&huart2,&buffer1[0],150,500);
// HAL_UART_Transmit(&huart2,&SPIBuf_READ[0],18,500);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
FLUSH_FIFO();
//READY_MODE();
//TX_MODE();
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
/* USER CODE END 3 */
}
HT STMicroelectronics *****END OF FILE****/
2019-08-27 04:16 AM
Edit code
void FLUSH_FIFO(){
UARTBuf[21]=COMMAND_FLUSHRXFIFO ;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi1 , &UARTBuf[20],2,500);
HAL_GPIO_WritePin(SDA_GPIO_Port, SDA_Pin, GPIO_PIN_SET);
HAL_Delay(50);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET);
UARTBuf[20]=0x80;
UARTBuf[21]=COMMAND_FLUSHTXFIFO ;
HAL_SPI_Transmit(&hspi1 , &UARTBuf[20],2,500);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET);}
void TX_MODE()
{UARTBuf[20]=0x80;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET);
UARTBuf[0]=0x80;
UARTBuf[1]=COMMAND_TX ;
HAL_SPI_Transmit(&hspi1 , &UARTBuf[0],2,500);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET);
}
void RX_MODE()
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET);
UARTBuf[0]=0x80;
UARTBuf[1]=COMMAND_RX ;
HAL_SPI_Transmit(&hspi1 , &UARTBuf[0],2,500);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET);
}
void READY_MODE()
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET);
UARTBuf[0]=0x80;
UARTBuf[1]=COMMAND_READY ;
HAL_SPI_Transmit(&hspi1 , &UARTBuf[0],2,500);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET);
}
void S2LPSpiWriteRegisters(uint8_t adress,uint8_t number, uint8_t *conetent)
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET);
UARTBuf[0]=0x00;
UARTBuf[1]= adress;
UARTBuf[2]= conetent[0];
UARTBuf[3]= conetent[1];
UARTBuf[4]= conetent[2];
UARTBuf[5]= conetent[3];
UARTBuf[6]= conetent[4];
UARTBuf[7]= conetent[5];
UARTBuf[8]= conetent[6];
HAL_SPI_Transmit(&hspi1 , &UARTBuf[0],number+2,50);//mode
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET);
}
void S2LPSpiWriteRegisters1(uint8_t adress,uint8_t number, uint8_t *conetent)
{
HAL_GPIO_WritePin(SDA_GPIO_Port, SDA_Pin, GPIO_PIN_RESET);
buffer1[0]=0x00;
buffer1[1]= adress;
HAL_SPI_Transmit(&hspi1 , &buffer1[0],2,50);//mode
HAL_SPI_Transmit(&hspi1 , &UARTBuf[0],178,500);//mode
HAL_GPIO_WritePin(SDA_GPIO_Port, SDA_Pin, GPIO_PIN_SET);
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
MX_SPI1_Init();
/* USER CODE BEGIN 2 */
uint8_t i=0;
HAL_GPIO_WritePin(SDN_GPIO_Port, SDN_Pin, GPIO_PIN_RESET);
HAL_Delay(50);
HAL_GPIO_WritePin(SDN_GPIO_Port, SDN_Pin, GPIO_PIN_SET);
HAL_Delay(50);
HAL_GPIO_WritePin(SDN_GPIO_Port, SDN_Pin, GPIO_PIN_RESET);//HAL_GPIO_WritePin(GPIOC, GPIO_PIN_1, GPIO_PIN_RESET);HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET);
HAL_Delay(50);
READY_MODE();
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
tmp[0] = 0x72; /* reg. SYNT3 (0x05) */
tmp[1] = 0x2A; /* reg. SYNT2 (0x06) */
tmp[2] = 0x3D; /* reg. SYNT1 (0x07) */
tmp[3] = 0x1B; /* reg. SYNT0 (0x08) */
tmp[4] = 0x2F; /* reg. IF_OFFSET_ANA (0x09) */
tmp[5] = 0xC2; /* reg. IF_OFFSET_DIG (0x0A) */
S2LPSpiWriteRegisters(0x05, 6, tmp);
tmp[0] = 0x92; /* reg. MOD4 (0x0E) */
tmp[1] = 0xA7; /* reg. MOD3 (0x0F) */
tmp[2] = 0x27; /* reg. MOD2 (0x10) */
S2LPSpiWriteRegisters(0x0E, 3, tmp);
tmp[0] = 0xA3; /* reg. MOD0 (0x12) */
tmp[1] = 0x13; /* reg. CHFLT (0x13) */
S2LPSpiWriteRegisters(0x12, 2, tmp);
tmp[0] = 0x55; /* reg. ANT_SELECT_CONF (0x1F) */
S2LPSpiWriteRegisters(0x1F, 1, tmp);
tmp[0] = 0x00; /* reg. PCKTCTRL3 (0x2E) */
tmp[1] = 0x01; /* reg. PCKTCTRL2 (0x2F) */
tmp[2] = 0x30; /* reg. PCKTCTRL1 (0x30) */
S2LPSpiWriteRegisters(0x2E, 3, tmp);
tmp[0] = 0x01; /* reg. PROTOCOL1 (0x3A) */
S2LPSpiWriteRegisters(0x3A, 1, tmp);
tmp[0] = 0x40; /* reg. FIFO_CONFIG3 (0x3C) */
tmp[1] = 0x40; /* reg. FIFO_CONFIG2 (0x3D) */
tmp[2] = 0x40; /* reg. FIFO_CONFIG1 (0x3E) */
tmp[3] = 0x40; /* reg. FIFO_CONFIG0 (0x3F) */
tmp[4] = 0x41; /* reg. PCKT_FLT_OPTIONS (0x40) */
S2LPSpiWriteRegisters(0x3C, 5, tmp);
tmp[0] = 0x1D; /* reg. PA_POWER8 (0x5A) */
S2LPSpiWriteRegisters(0x5A, 1, tmp);
tmp[0] = 0x07; /* reg. PA_POWER0 (0x62) */
tmp[1] = 0x01; /* reg. PA_CONFIG1 (0x63) */
S2LPSpiWriteRegisters(0x62, 2, tmp);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
TX_MODE();
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SPIBuf_WRITE[0]=0x00;//reead
SPIBuf_WRITE[1]=0xff;// regester
SPIBuf_READ[0]=0x0;SPIBuf_READ[1]=0xcc;SPIBuf_READ[2]=0;SPIBuf_READ[3]=0;SPIBuf_READ[4]=0;SPIBuf_READ[5]=0;SPIBuf_READ[6]=0;SPIBuf_READ[7]=0;SPIBuf_READ[8]=0;
// SPIBuf_WRITE_REGESTER[0]=0x00;SPIBuf_WRITE_REGESTER[1]=0x3c;SPIBuf_WRITE_REGESTER[2]=0xff;SPIBuf_WRITE_REGESTER[3]=0xff;SPIBuf_WRITE_REGESTER[4]=0;SPIBuf_WRITE_REGESTER[5]=0;SPIBuf_WRITE_REGESTER[6]=0;SPIBuf_WRITE_REGESTER[7]=0;SPIBuf_WRITE_REGESTER[8]=0;
// HAL_GPIO_WritePin(SDN_GPIO_Port, SDN_Pin, GPIO_PIN_RESET);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
HAL_Delay(500);
for(i=0;i<=40;i++){
SPIBuf_READ[i]='0';
} i=0;
HAL_GPIO_WritePin(SDA_GPIO_Port, SDA_Pin, GPIO_PIN_RESET);
HAL_SPI_TransmitReceive(&hspi1, &SPIBuf_WRITE[0], &SPIBuf_READ[0], 18,1000);
HAL_Delay(500);
HAL_GPIO_WritePin(SDA_GPIO_Port, SDA_Pin, GPIO_PIN_SET);
sprintf( buffer3, "\r\n RECIVED @ adress %x is = [%x %x %x %x %x %x %x %x %x ] \r\n",SPIBuf_WRITE[1],SPIBuf_READ[0],SPIBuf_READ[1],SPIBuf_READ[2],SPIBuf_READ[3],SPIBuf_READ[4],SPIBuf_READ[5],SPIBuf_READ[6],SPIBuf_READ[7],SPIBuf_READ[8]);
for(i=0;i<=strlen(buffer3);i++){
buffer1[i]=buffer3[i];
} i=0;
// sprintf( buffer3, "\r\n RECIVED is = [%c %c %c %c %c %c %c %c ] \r\n",UARTBuf[42],UARTBuf[43],UARTBuf[44],UARTBuf[45],UARTBuf[46],UARTBuf[47],UARTBuf[48],UARTBuf[49]);
HAL_UART_Transmit(&huart2,&buffer1[0],150,500);
// HAL_UART_Transmit(&huart2,&SPIBuf_READ[0],18,500);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
FLUSH_FIFO();
//READY_MODE();
//TX_MODE();
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
/* USER CODE END 3 */
}
2019-09-24 10:17 AM
hi, did you got it working?
am facing similar issue with s2lp transmitter, considering am fairly new to rf design, so am more of in learning by doing mode. Sigfox is pretty far for me as of now.
If you have time would like to know how and what steps did you follow to set s2lp in Tx mode as well as Rx. I was actually trying to generate CW first but it did,nt worked.
SPI is working fine and device is indeed going into ready/standby and sleep state, tried to go on with tx and lock commands and device state is as per the command issued, but no response on tx and rx side am not sure whether it is due to register configuration or what.
so any help would be good enough apart from "good-luck"
2019-09-24 01:23 PM
Hi
I got it fixed the main thing was that i changed the
PCKTCTRL3 RX mode direct through FIFO
and
PCKTCTRL1 TX mode direct through FIFO
then i was able to to change it to TX mode
I was able to send and receive with s2lp but i couldn't do the RCS so i disabled it