cancel
Showing results for 
Search instead for 
Did you mean: 

How to transfer data between two STM32+SX1272 LoRa module

mlau.18
Associate II

Hello everyone. I am debugging the STM32+SX1272 LORA wireless communication. Now I follow the sample code provided by ST company which download from the website. The sample code version is STM32CubeExpansion_LRWAN_V1.3.1.

Now I can transfer "ping" and "pong" between two modules using the sample code.

As I understand, there is a buffer which size is 64 which is define to transfer data. It is defined below.

#define BUFFER_SIZE                 64 // Define the payload size here

uint16_t BufferSize = BUFFER_SIZE;

uint8_t Buffer[BUFFER_SIZE];

As I understand, in the main loop, when the state = RX the data transferred in is stored in the Buffer array and prepare the next frame data for the transmission.

      if (strncmp((const char *)Buffer, (const char *)PongMsg, 4) == 0)

      {

       TimerStop(&timerLed);

       LED_Off(LED_BLUE);

       LED_Off(LED_GREEN) ;

       LED_Off(LED_RED1) ;

       // Indicates on a LED that the received frame is a PONG

       LED_Toggle(LED_RED2) ;

       // Send the next PING frame

       Buffer[0] = 'P';

       Buffer[1] = 'I';

       Buffer[2] = 'N';

       Buffer[3] = 'G';

       // We fill the buffer with numbers for the payload

       for (i = 4; i < BufferSize; i++)

       {

        Buffer[i] = i - 4;

       }

       PRINTF("...PING2\n\r");

       DelayMs(1);

       Radio.Send(Buffer, BufferSize);

      }

Now I have a question, If I make an analog and digital conversion and get some data. How can I put the data in the Buffer array and transmit data to another node. How can I use PRINTF function to transmit the data to the computer via USB communication. I don't know how to use PRINTF function. It seems relative to the function of Trace.

Any help will be appreciated.

Best regards,

1 REPLY 1

>>How can I use PRINTF function to transmit the data to the computer via USB communication. I don't know how to use PRINTF function. It seems relative to the function of Trace.

PRINTF on the Murata module (LORA-DISCO) outputs via one of the physical UART to the ST-LINK VCP

To output via USB you'd need to code a CDC device on the "STM32" you are using, and then buffer and manage the data. See the HAL examples in the Cube repository for your "STM32"

>>If I make an analog and digital conversion and get some data. How can I put the data in the Buffer array and transmit data to another node.

It is just a memory buffer, you can put in whatever data you want into the buffer, the transfer is just a collection of bytes, think basic data representation.

The buffer doesn't have to be 64 bytes, but you'd need to manage and queue the data so you could do a new Radio.Send() after it completed the last one. You could define the format of the packet, it could be an array or a structure, it depends on what serves your needs.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..