8000 Compatibility with 915MHz SX1276 · Issue #13 · SMotlaq/LoRa · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Compatibility with 915MHz SX1276 #13
Open
@MatheusMarkies

Description

@MatheusMarkies

I'm using the library in a project with a 915MHz SX1276. The initialization of the module went smoothly and I'm already receiving a message saying that the LoRa module is ready for use.
However, I'm having problems transmitting. The transmitter manages to send the signal via the LoRa_transmit command, and gets a return = 1. But the receiver doesn't receive the packet.

Why is this happening? I've configured it according to the Readme example and I've also used HAL_GPIO_EXTI_Callback in case the interrupt on the DIO pin happens.

Captursdfggsdfdfgsar

RX Code:

void setup(){
	DEBUG_PRINT("Starting...\r\n");

	  // SX1276 compatible module connected to SPI1, NSS pin connected to GPIO with label LORA_NSS
	myLoRa = newLoRa();

	myLoRa.CS_port         = NSS_GPIO_Port;
	myLoRa.CS_pin          = NSS_Pin;
	myLoRa.reset_port      = LORA_RST_GPIO_Port;
	myLoRa.reset_pin       = LORA_RST_Pin;
	myLoRa.DIO0_port       = DIO_GPIO_Port;
	myLoRa.DIO0_pin        = DIO_Pin;
	myLoRa.hSPIx           = &hspi1;

	myLoRa.frequency             = 915;             // default = 433 MHz
	myLoRa.spredingFactor        = SF_7;            // default = SF_7
	myLoRa.bandWidth             = BW_250KHz;       // default = BW_125KHz
	myLoRa.crcRate               = CR_4_8;          // default = CR_4_5
	myLoRa.power                 = POWER_17db;      // default = 20db
	myLoRa.overCurrentProtection = 130;             // default = 100 mA
	myLoRa.preamble              = 10;              // default = 8;

	if(LoRa_init(&myLoRa) == LORA_OK){
		DEBUG_PRINT("LoRa Ready\r\n");
	}else DEBUG_PRINT("Error in LoRa connection\r\n");

	LoRa_startReceiving(&myLoRa);

      HAL_GPIO_WritePin(GPIOB, DEBUG_LED_Pin, GPIO_PIN_SET);
	  I2C_Scan();
	  HAL_GPIO_WritePin(GPIOB, K_Pin, GPIO_PIN_RESET);
	  HAL_Delay(100);
	  HAL_GPIO_WritePin(GPIOB, K_Pin, GPIO_PIN_SET);
	  HAL_Delay(1000);
	  HAL_GPIO_WritePin(GPIOB, K_Pin, GPIO_PIN_RESET);

	  //HAL_Delay(10000);
	  DEBUG_PRINT("Started!\r\n");
}

void loop(){
	char msg[64];
	uint8_t received_data[12];
	uint8_t packet_size = 0;
	packet_size = LoRa_receive(&myLoRa, received_data, 12);

	snprintf(msg, sizeof(msg), "Res %s\r\n", received_data);
	DEBUG_PRINT(msg);
}

void ShowSerialData(void)
{
  uint8_t data;
  while (__HAL_UART_GET_FLAG(&huart2, UART_FLAG_RXNE) != RESET) // Verifica se há dados disponíveis no UART3
  {
    HAL_UART_Receive(&huart2, &data, 1, HAL_MAX_DELAY); // Lê um byte do UART3
    HAL_UART_Transmit(&huart1, &data, 1, HAL_MAX_DELAY); // Envia o byte lido para o UART1
  }
  HAL_Delay(1000); // Espera por 1 segundo
}

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){
	if(GPIO_Pin == DIO_Pin){
		LoRa_receive(&myLoRa, rxBuffer, 120);
		DEBUG_PRINT("RECIEVED!\r\n");
	}
	DEBUG_PRINT("Call!\r\n");
}

TX Code:

void setup() {
	DEBUG_PRINT("Setup...\r\n");
	I2C_Scan();
	DEBUG_PRINT("\r\n");

	myLoRa = newLoRa();

	myLoRa.CS_port         = NSS_GPIO_Port;
	myLoRa.CS_pin          = NSS_Pin;
	myLoRa.reset_port      = LoRa_RST_GPIO_Port;
	myLoRa.reset_pin       = LoRa_RST_Pin;
	myLoRa.DIO0_port       = DIO_GPIO_Port;
	myLoRa.DIO0_pin        = DIO_Pin;
	myLoRa.hSPIx           = &hspi1;

	myLoRa.frequency             = 915;             // default = 433 MHz
	myLoRa.spredingFactor        = SF_7;            // default = SF_7
	myLoRa.bandWidth             = BW_250KHz;       // default = BW_125KHz
	myLoRa.crcRate               = CR_4_8;          // default = CR_4_5
	myLoRa.power                 = POWER_17db;      // default = 20db
	myLoRa.overCurrentProtection = 130;             // default = 100 mA
	myLoRa.preamble              = 10;              // default = 8;

	if(LoRa_init(&myLoRa) == LORA_OK){
		DEBUG_PRINT("LoRa Ready\r\n");
	}else DEBUG_PRINT("Error in LoRa connection\r\n");

	if (KX122_Init(&hspi2) != HAL_ERROR)
		DEBUG_PRINT("KX122 Ready\r\n");
	else
		DEBUG_PRINT("Error in KX122 connection\r\n");

	if (MCP9808_Init(&hi2c1) != HAL_ERROR)
		DEBUG_PRINT("MCP9808 Ready\r\n");
	else
		DEBUG_PRINT("Error in MCP9808 connection\r\n");

	if (MAX17048_Init(&hi2c1) != HAL_ERROR)
		DEBUG_PRINT("MAX17048 Ready\r\n");
	else
		DEBUG_PRINT("Error in MAX17048 connection\r\n");

	if (FRAM_Init(&hi2c1) != HAL_ERROR)
		DEBUG_PRINT("FRAM Ready\r\n");
	else
		DEBUG_PRINT("Error in FRAM connection\r\n");

	DEBUG_PRINT("Ready!\r\n");

	if(KX122_CheckCommunication(&hi2c1) != HAL_ERROR)
		DEBUG_PRINT("WHO I AM KX122 Ready\r\n");

	FRAM_InitMetadata(&metadata);

	package_factor = 3
			* ceil((float) (SAMPLES) / (float) TRANSMISSION_DATA_PACKAGE);
	data_sender_period = round(
			1000 * ((float) DATA_TRANSMISSION_PERIOD / (float) package_factor));

	acc_sample_factor = floor((float) ACC_DATA_RATE / (float) SAMPLES);
	sampling_period_us = round(1000000 * (1.0 / (float) SAMPLES)); //488.28
	//sampling_period_us = round(1000000 * (1.0 / (float) ACC_DATA_RATE));
	//sampling_period_us *= acc_sample_factor;

	DEBUG_PRINT("package_factor:\r\n");
	printFloat(package_factor);
	DEBUG_PRINT("data_sender_period:\r\n");
	printFloat(data_sender_period);
	DEBUG_PRINT("sampling_period_us:\r\n");
	printFloat(sampling_period_us);
	DEBUG_PRINT("acc_sample_factor:\r\n");
	printFloat(acc_sample_factor);
	DEBUG_PRINT("\r\n");

	sizeInBytes = FRAM_MEMORY_SIZE;
	writeVibrationInformation();
}

void loop() {
	//HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET);

	//HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);

	char*  send_data;
	send_data = "Hello world!";
	if(LoRa_transmit(&myLoRa, (uint8_t*)send_data, 12, 100) == 1){
		DEBUG_PRINT("Success!\r\n");
	}else DEBUG_PRINT("Fail!\r\n");
	DEBUG_PRINT("Sanded!\r\n");
	HAL_Delay(5000);writeVibrationInformation();
}

Captursdfggsdfdsfgdfgsar

Constructor:

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_I2C1_Init();
  MX_SPI1_Init();
  MX_USART1_UART_Init();
  MX_USART2_UART_Init();
  /* USER CODE BEGIN 2 */
  setup();
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
	  loop();
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0