Continue to Site

Problem in Running SX1281 Semtech lora IC with Stm32 UART protocol

mettiblack72

Junior Member level 3
Junior Member level 3
Joined
Jun 4, 2018
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
189
hello,
I'm trying to run sx1281 lora ic from semtech with stm32 by uart protocol
1- at the first I reset hardware by reset pin and then
2- send getstatus() command to get mode of ic , for this command I examine BUSY pin to be Low after that I transmit getstatus() command, ic response me STDBY_RC mode and it's ok
3- depends on datasheet then I should to setpackettype(), when I send setpackettype() command or any SET command, voltage of BUSY pin goes to high and remain high!! and I can't send another commands!! I expect after set command busy pin goes to low voltage

please help
 
Hi,

Are you sure the power supply is stable .. down to high nanoseconds?

All other IO are at the expected level .. and stable?

You are driving with the correct signal levels?

Klaus
 
thanks for reply, yes I monitor power supply It's ok and stable
for power supply I use LDO option , and I don't place inductor 15uH to use DC-DC convertor , should I set any config for LDO or not ?

I doubt about RTSN and CTS pins, I pulldown RTSN pin and CTS pin is float

I send opcode and length and parameter with HAL_UART_Transmit() function

which IOs should I monitor value ?
 
Hi,

for more detailed analysis and assistence we need to see your schematic and PCB layout.

RSTN and CTS: We don´t see your code, thus we don´t see their config.

which IOs should I monitor value ?
EVERY IO needs to be within the expected values/signals.

Klaus
 
Dear I attached STM32_SX1281 .h and .c files and Schematic
I don't solder C13, C14, R1, R5, R6, R7, L3
 

Attachments

  • STM32_SX1281.rar
    92.6 KB · Views: 32
Hi,

for more detailed analysis and assistence we need to see your schematic and PCB layout.

RSTN and CTS: We don´t see your code, thus we don´t see their config.


EVERY IO needs to be within the expected values/signals.

Klaus
dear I attached files ... can you help me ?
thanks a lot
 
Hi,

I see a .rar file .. this is an compress file I can´t open on my old tablet. Maybe later when I´m on my PC.

Why don´t you upload code using the [ C O D E ] button and pictures using the [ I N S E R T I M A G E] button?

Klaus
 
C++:
#ifndef STM32_SX1281_H
#define STM32_SX1281_H

#include "stm32f1xx_hal.h"

//----------------------------------------------------------------------------- Registers

//                                                      Address   DefaultValue  Bit7         Bit6         Bit5         Bit4         Bit3         Bit2         Bit1         Bit0
#define CodingRate                                      0x950     //NA          ----         CR           CR           CR           ----         ----         ----         ----                  0x534C

//----------------------------------------------------------------------------- Commands
//                                                      OpCode
#define CMD_GetStatus                                   0xC0
#define CMD_SetStandby                                  0x80
#define CMD_SetPacketType                               0x8A

//----------------------------------------------------------------------------- Command Details
#define Mode_STDBY_RC                                   0x00
#define Mode_STDBY_XOSC                                 0x01
#define Packet_Type_GFSK                                0x00
#define Packet_Type_LORA                                0x01
#define Packet_Type_RANGING                             0x02
#define Packet_Type_FLRC                                0x03
#define Packet_Type_BLE                                 0x04

//----------------------------------------------------------------------------- Command Response
#define CMD_GetStatusResponse_CircuitMode_STDBY_RC      (0x02 << 5)
#define CMD_GetStatusResponse_CircuitMode_STDBY_XOSC    (0x03 << 5)
#define CMD_GetStatusResponse_CircuitMode_FS            (0x04 << 5)
#define CMD_GetStatusResponse_CircuitMode_Rx            (0x05 << 5)
#define CMD_GetStatusResponse_CircuitMode_Tx            (0x06 << 5)

//-----------------------------------------------------------------------------
#define TimeOutCounterforBusyPin                         50

class SX1281
{

private :
  uint16_t            ResetPin  ;
  GPIO_TypeDef*       ResetPort ;
  uint16_t            BusyPin   ;
  GPIO_TypeDef*       BusyPort  ;
  uint16_t            CTSPin    ;
  GPIO_TypeDef*       CTSPort   ;
  UART_HandleTypeDef *UARTBusNo ;

public : 
  //-------- Constructor
  SX1281(UART_HandleTypeDef *_UARTBusNo, GPIO_TypeDef* _ResetPort, uint16_t _ResetPin, GPIO_TypeDef* _BusyPort, uint16_t _BusyPin, GPIO_TypeDef* _CTSPort, uint16_t _CTSPin);

  //-------- Methods
  bool SX1281_Reset(uint16_t *Error);
  bool SX1281_CheckBusyPin(uint16_t *Error) ;
 
  void SX1281_Init_LoRa(uint16_t *Error);
  void SX1281_GetStatus(uint8_t *CircuitMode, uint8_t *CommandStatus, uint16_t *Error);
 
  void SX1281_SetStandby(uint8_t StandbyConfig, uint16_t *Error);
  void SX1281_SetPacketType(uint8_t PacketType, uint16_t *Error);
 
 
  enum SX1281_Error
  {
    NoError = 0,
    BusyPinTogglingTimeout      = 0x0001           
  };
 
}; //END Class

#endif

this is .h code


C++:
#include "STM32_SX1281.hpp"



//------- Constructor
SX1281::SX1281(UART_HandleTypeDef *_UARTBusNo, GPIO_TypeDef* _ResetPort, uint16_t _ResetPin, GPIO_TypeDef* _BusyPort, uint16_t _BusyPin, GPIO_TypeDef* _CTSPort, uint16_t _CTSPin)
{
  UARTBusNo = _UARTBusNo ;
  ResetPort = _ResetPort ;
  ResetPin  = _ResetPin ;
  BusyPort  = _BusyPort ;
  BusyPin   = _BusyPin ;
  CTSPort   = _CTSPort ;
  CTSPin    = _CTSPin ;
}

/**
  * @brief  Check value of busy pin to
  * @param  ---
  * @param  ---
  * @retval true if busy pin goes to low and false if timeout
  */
bool SX1281::SX1281_CheckBusyPin(uint16_t *Error)
{
  uint32_t TimeOut = 0 ;
 
  //------- Wait Until Busy Pin goes to low voltage and SX1281 Ready to accept command
  do
  {
    
    TimeOut++ ;
    if (TimeOut > TimeOutCounterforBusyPin)
    {
      *Error |= SX1281::SX1281_Error::BusyPinTogglingTimeout;
      return false ;
    }
    //------- Read Busy Pin Value
  }while((HAL_GPIO_ReadPin(BusyPort, BusyPin)) == 1) ;
 
  return true ;
}

/**
  * @brief  Hardware Reset, after reset we should wait for busy pin to go low
            but we do this by waiting for IC to go to Stand By mode state
  * @param  ---
  * @param  ---
  * @retval None
  */
bool SX1281::SX1281_Reset(uint16_t *Error)
{
 
  //------- Perform Hardware Reset
  HAL_GPIO_WritePin(ResetPort, ResetPin, GPIO_PIN_RESET);
  HAL_Delay(10) ;
  HAL_GPIO_WritePin(ResetPort, ResetPin, GPIO_PIN_SET);
  HAL_Delay(10) ;
 
  return (SX1281_CheckBusyPin(Error)) ;
 
}

/**
  * @brief  Perform GetStatus command
  * @param  CircuitMode   : Call by reference variable, initiated by 5 modes
  * @param  CommandStatus : Call by reference variable, initiated by command process status
  * @retval None
  */
void SX1281::SX1281_GetStatus(uint8_t *CircuitMode, uint8_t *CommandStatus, uint16_t *Error)
{
  uint8_t  DataToSend[1] = {CMD_GetStatus} ;
  uint8_t  DataToReceive[1] = {0x00} ;
 
  if (SX1281_CheckBusyPin(Error))
  {
    //------- Send GetStatus() Command
    HAL_UART_Transmit(UARTBusNo, DataToSend, sizeof(DataToSend), 10) ;
  }
 
  //------- Receive GetStatus() Respone and Examine Return Value
  HAL_UART_Receive(UARTBusNo, DataToReceive, sizeof(DataToSend), 10) ;
 
  *CircuitMode   = DataToReceive[0] &  0xE0 ; //[7:5]
  *CommandStatus = DataToReceive[0] &  0x1C ; //[4:2]
}

/**
  * @brief  Set to Standby RC (13MHz) mode or Standby XOSC mode(52MHz)
  * @param  StandbyConfig : Should set by rc mode or xosc mode
            Mode_STDBY_RC
            Mode_STDBY_XOSC
  * @retval None
  */
void SX1281::SX1281_SetStandby(uint8_t StandbyConfig, uint16_t *Error)
{
  uint8_t  DataToSend[3] = {CMD_SetStandby, 0x01, StandbyConfig} ;
 
  if (SX1281_CheckBusyPin(Error))
  {
    //------- Send SetStandby() Command
    HAL_UART_Transmit(UARTBusNo, DataToSend, sizeof(DataToSend), 10) ;
  }
}


/**
  * @brief  The command SetPacketType() sets the transceiver radio frame
  * @param  PacketType : Should set one of 5 different type
  * @retval None
  */
void SX1281::SX1281_SetPacketType(uint8_t PacketType, uint16_t *Error)
{
  uint8_t  DataToSend[3] = {CMD_SetPacketType, 0x01, PacketType} ;
 
  if (SX1281_CheckBusyPin(Error))
  {
    //------- Send SetPacketType() Command
    HAL_UART_Transmit(UARTBusNo, DataToSend, sizeof(DataToSend), 10) ;
  }
}


/**
  * @brief  Initial Standby mode, Packet Type,
  * @param  ---
  * @param  ---
  * @retval None
  */
void SX1281::SX1281_Init_LoRa(uint16_t *Error)
{
  uint8_t  mode = 0x00 ;
  uint8_t  Cstatus = 0x00;
 
  SX1281_GetStatus(&mode, &Cstatus, Error) ;
 
  //HAL_GPIO_WritePin(CTSPort, CTSPin, GPIO_PIN_SET);
  //------- Set Standby Mode
  SX1281_SetStandby(Mode_STDBY_RC, Error);
 
  //------- Set Packet Type
  //SX1281_SetPacketType(Packet_Type_LORA, Error);
 
  //SX1281_GetStatus(&mode, &Cstatus, Error) ;
}

this is .c code

Schematic.PNG
 
Hi,

now at post#9 .. almost a week is gone... eventually there is the code.
Still I´m having difficulties in reading the text in the schematic.
I guess I will stop here.

Good luck..
Klaus
 
Hi,

now at post#9 .. almost a week is gone... eventually there is the code.
Still I´m having difficulties in reading the text in the schematic.
I guess I will stop here.

Good luck..
Klaus
Hello dear, Really excuse me for my delay, I had cold & cough
I switched to SPI protocol and it's work
thanks a lot
 
Last edited:


Write your reply...

LaTeX Commands Quick-Menu:

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top