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

Testing RA-02 SX1278 module with STM32L031 #8

Open
krupis opened this issue Aug 1, 2023 · 15 comments
Open

Testing RA-02 SX1278 module with STM32L031 #8

krupis opened this issue Aug 1, 2023 · 15 comments
Labels
help wanted Extra attention is needed

Comments

@krupis
Copy link

krupis commented Aug 1, 2023

I am trying to get this example project working on the STM32L031 development board:
https://www.st.com/en/evaluation-tools/nucleo-l031k6.html

I cannot fully understand how am I intended to test this. I have 2 identical STM32L031 devices and connected each STM32L031 to the RA-02 SX1278 lora module.

One is running LoRa transmit code:

  while (1)
  {
	  char*  send_data;
	  send_data = "Hello!";
	  if(LoRa_transmit(&myLoRa, (uint8_t*)send_data, 6, 100) == 1){
		  printf("Transmit ok \n");
	  }
		else{
			printf("Transmit failed \n");
		}
		HAL_Delay(1500);
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }

The other is running receive code:

  LoRa_startReceiving(&myLoRa);
  uint8_t received_data[10];
  uint8_t packet_size = 0;
  while(1){
    packet_size = LoRa_receive(&myLoRa, received_data, 10);
    if(packet_size > 0 ){
    	printf("received data = %s \n",received_data);
    }
    HAL_Delay(500);
  }

The logs side by side:
image

Is that the expected behaviours of this library?
How to ensure I receive the correct data?
Is it normal that it fails to transmit every now and then?

@SMotlaq
Copy link
Owner

SMotlaq commented Aug 1, 2023

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.

@krupis
Copy link
Author

krupis commented Aug 2, 2023

@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

@SMotlaq
Copy link
Owner

SMotlaq commented Aug 2, 2023

Please send me your project and codes
[email protected]

@krupis
Copy link
Author

krupis commented Aug 2, 2023

@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)

@SMotlaq
Copy link
Owner

SMotlaq commented Aug 2, 2023

Have you checked what value LoRa_init() function returns?

@krupis
Copy link
Author

krupis commented Aug 2, 2023

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 

@krupis
Copy link
Author

krupis commented Aug 2, 2023

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

@SMotlaq
Copy link
Owner

SMotlaq commented Aug 2, 2023

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.

@krupis
Copy link
Author

krupis commented Aug 3, 2023

@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.

@SMotlaq
Copy link
Owner

SMotlaq commented Aug 6, 2023

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

@krupis
Copy link
Author

krupis commented Aug 8, 2023

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. :)

@krupis
Copy link
Author

krupis commented Aug 11, 2023

@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

@krupis
Copy link
Author

krupis commented Aug 11, 2023

@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

@SMotlaq
Copy link
Owner

SMotlaq commented Aug 11, 2023

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.

@krupis
Copy link
Author

krupis commented Aug 12, 2023

@SMotlaq

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

@SMotlaq SMotlaq added the help wanted Extra attention is needed label Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants