Code Monkey home page Code Monkey logo

Comments (15)

krupis avatar krupis commented on June 19, 2024 1

I will run your code on my hardware as soon as possible and tell you the result.

Sounds good. Please let me know if you are able to reproduce the issue at all. :)

from lora.

krupis avatar krupis commented on June 19, 2024 1

@SMotlaq

I will try to receive using EXT interrupt and post back the results

from lora.

SMotlaq avatar SMotlaq commented on June 19, 2024

Hello
Using char* without memory allocation is not recommended.
Please use char* as array and use sprintf and snprintf functions like this:

char   send_data[20];
snprintf(send_data, 6, "Hello!");
LoRa_transmit(&myLoRa, (uint8_t*)send_data, 6, 100);

I think this should solve your problem.

from lora.

krupis avatar krupis commented on June 19, 2024

@SMotlaq I have updated the transmitter code as you have suggested but im afraid not much changed. I believe issue lies in the receiver code. Something is not right.

The receiver is constantly printing garbage even when I dont have transmitter powered.

image

from lora.

SMotlaq avatar SMotlaq commented on June 19, 2024

Please send me your project and codes
[email protected]

from lora.

krupis avatar krupis commented on June 19, 2024

@SMotlaq
I can share my project through here. You access it via my github:
https://github.com/krupis/Lora-STM32

All you need to do is to update :

// 0 - receiver mode
// 1 - transmitter mode
#define MODA_LORA 0

depending on which mode you want to program the device

Additionally, I have put a scope on the DIO0 pin on the receiver device. It is never triggered but on the console it prints the received garbage data. Does your receiver code utilize DIO0 rx interrupt?. I was under the impression that data received should only be printed when the RX interrupt is triggered.

On my STM32, the DIO0 is configured as input pin and is pulled down. (You can check my CubeMX configuration)

from lora.

SMotlaq avatar SMotlaq commented on June 19, 2024

Have you checked what value LoRa_init() function returns?

from lora.

krupis avatar krupis commented on June 19, 2024

Have you checked what value LoRa_init() function returns?

Yes. I have added the following to my code:

  LoRa_reset(&myLoRa);
  uint16_t lora_ret = LoRa_init(&myLoRa);
  printf("Lora return value = %u \n",lora_ret);

and the result:

Lora return value = 200 
Starting RX mode 

from lora.

krupis avatar krupis commented on June 19, 2024

If it would be helpful, I can connect logic analyzer to SPI pins and check what happens

from lora.

SMotlaq avatar SMotlaq commented on June 19, 2024

1- Please reset the buffer first, using memset to check that we get any packet or not:

uint8_t received_data[10];
memset(received_data,  NULL, 10);

2- Also please send a variable data from sender. For example "Hello 1", "Hello 2", ...

3- Print the exact values of the received_data. Not the character or ASCII.

from lora.

krupis avatar krupis commented on June 19, 2024

@SMotlaq
I have modified my receiver code as following:

	if(MODA_LORA == 0){
		printf("Starting RX mode \n");
		LoRa_startReceiving(&myLoRa);
		uint8_t received_data[10];
		memset(received_data,  NULL, 10);
		uint8_t packet_size = 0;
		while(1){
		packet_size = LoRa_receive(&myLoRa, received_data, 10);
		if(packet_size > 0 ){
			for(int i = 0; i<packet_size;i++){
				printf("received data[i] = %u \n",i,received_data[i]);

			}
		}
		memset(received_data,  NULL, 10); // Clear the received data buffer after it is received
		packet_size = 0; // set packet size to 0 after receiving data.
		HAL_Delay(500);
		}
	}

and my transmitter code as following:

	else if(MODA_LORA == 1){
		printf("Starting TX mode \n");
		while (1)
		{
			char   send_data[20];
			for (int i = 0; i < 100; i++)
			{
				snprintf(send_data, 20, "test%d", i); // puts string into buffer
				printf("String to send = %s and length =%u \n", send_data,strlen(send_data)); // outputs so you can see it
				if(LoRa_transmit(&myLoRa, (uint8_t*)send_data, 6, 100) == 1){
					printf("Transmitting %s successful \n",send_data);
				}
				else{
					printf("Transmit failed \n");
				}
				HAL_Delay(2000);
			}

		/* USER CODE END WHILE */
		/* USER CODE BEGIN 3 */
		}
	}

The logs side by side:
image

As you can see lora receiver receives strange data. This data is being does not have anything to do with my lora transmitter since it will keep receiving:

received data[i] = 0 
received data[i] = 1 
received data[i] = 2 
received data[i] = 3 
received data[i] = 4 
received data[i] = 5 
received data[i] = 6 
received data[i] = 7 
received data[i] = 8 
received data[i] = 9 

Even when my transmsitter is powered OFF.

I have updated my git repository for this project if you want to have a look at the latest code.

from lora.

SMotlaq avatar SMotlaq commented on June 19, 2024

I will run your code on my hardware as soon as possible and tell you the result.

from lora.

krupis avatar krupis commented on June 19, 2024

@SMotlaq
I have recently watched your Youtube video regarding this library.
I have noticed a few comments:
image

Perhaps my issue is related to this?

In my case, NVIC settings are as following
image

from lora.

krupis avatar krupis commented on June 19, 2024

@SMotlaq
Additionally, I do not fully understand whether DIO0 signal is set high or low when message is received? Could you confirm whether it is active LOW or active HIGH? I havent been able to find this information

from lora.

SMotlaq avatar SMotlaq commented on June 19, 2024

When the module receives a valid LoRa packet, it changes the DIO0 from LOW to HIGH (I don't know how long this pin stays HIGH). You can enable an EXTI in the rising edge mode to detect arriving packets.

You didn't use interrupts in your code, so I don't think that is the reason of your problem. But you can test it. The polling mode is not recommended. It's better than using interrupts.

from lora.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.