AnsweredAssumed Answered

STM32F0 WITH RN2485 LORA,RADIO TX RESPONSE ISSUE

Question asked by akshay bansod on Mar 17, 2018
Latest reply on Mar 20, 2018 by akshay bansod

Hello,

I have a customized board for STM32F030R8x microcontroller interfaced with Microchip Lora Module RN2483 over UART.

I want to establish P2P connection between Lora module. 

When i am connecting the modules directly over serial port using TTL converter(for testing purpose) and sending the AT commands to i am getting proper response for each command and data is been transmitted and received between modules.

Now when i am connecting my stm32 uart pins to lora module as a transmitter, i need my ADC value to be transmitted to the receiver module.

I am getting proper response from module in aRxBuffer this variable for reset & mac pause..

but when i am sending radio tx <adc_data>\r\n i need to get 2 responses for that one is 'ok\r\n' & 'radio_ok_tx'.

For my first ADC Tx i am Getting the first response but for second response in am receiving only char 'r'. And on my second ADC Tx onward it shows response as 'invalid parameter'.

 

Thank you .

 

following is the code for main:

#include "main.h"
#include "stm32f0xx_hal.h"
#include "adc.h"
#include "usart.h"
#include "gpio.h"
#include <string.h>
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/

 

uint8_t aTxStartMessage3[] = "mac pause\r\n";
uint8_t cmd_pwr[] = "radio set pwr 14\r\n";
char aTxStartMessage4[] = "radio tx ";
char aTxStartMessage5[] = "123123\r\n";
/* Buffer used for reception */
uint8_t rx_index;
volatile uint8_t aRxBuffer[200];
int buftrack=0;
char CRLF[2]={'\r','\n'};
uint32_t adc_conversion;
char adc_data[6]={0};
char cmd2send[20]={0};

 

void SystemClock_Config(void);


int main(void)
{

HAL_Init();


SystemClock_Config();

 


MX_GPIO_Init();
MX_USART1_UART_Init();
MX_ADC_Init();

 

HAL_UART_Receive_IT(&huart1, &rx_index, 1);         // UART Rx interrupt activated
HAL_Delay(1000);

 

HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_0);        //Toggling reset pin
HAL_Delay(1000);

 

//MAC PAUSE COMMAND...................
HAL_UART_Transmit(&huart1, aTxStartMessage3, sizeof(aTxStartMessage3),0XFFFF);
HAL_Delay(500);

 

HAL_ADC_Start(&hadc);

while (1)
{


if(HAL_ADC_PollForConversion(&hadc, 1000) == HAL_OK)
{
adc_conversion = HAL_ADC_GetValue(&hadc);
sprintf(adc_data, "%d", adc_conversion);
}


strcpy(cmd2send,aTxStartMessage4);
strcat(cmd2send,adc_data);
strcat(cmd2send,CRLF);
HAL_UART_Transmit_IT(&huart1, (uint8_t *)&cmd2send, sizeof(cmd2send));

 

HAL_Delay(1000);
}

}

-----------------------------------------------below is UART Rx interrupt call back function

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(huart);
if(rx_index!='\n')
{
aRxBuffer[buftrack]=rx_index;
buftrack++;
}
/*else if(aRxBuffer[0]=='o')
{
HAL_UART_Transmit(&huart1, (uint8_t *)dummy, sizeof(dummy),0xFFFF);
}*/
else
{
buftrack=0;
for(int i=0;i<200;i++)
{
aRxBuffer[i]=0;
}
rx_index=0;
}
/* NOTE : This function should not be modified, when the callback is needed,
the HAL_UART_RxCpltCallback can be implemented in the user file
*/
//HAL_UART_Transmit(&huart1, (uint8_t *)aRxBuffer, 10,0xFFFF);
HAL_UART_Receive_IT(&huart1, (uint8_t *)&rx_index, 1);
}

 

------------------------------------below is system clock config-----------------

void SystemClock_Config(void)
{

RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInit;

/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI14|RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
RCC_OscInitStruct.HSI14CalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL10;
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}

/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}

PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1;
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}

/**Configure the Systick interrupt time
*/
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

/**Configure the Systick
*/
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}

 

-------------------------------below uart.c code-----------------------------------------------------

UART_HandleTypeDef huart1;

/* USART1 init function */

void MX_USART1_UART_Init(void)
{

huart1.Instance = USART1;
huart1.Init.BaudRate = 57600;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}

}

Outcomes