This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C123GH6PM: LoRa interfacing with tiva C series microcontroller

Part Number: TM4C123GH6PM

Greetings,

I was facing an issue when interfacing Lora module RN2483 of microchip over UART communication.

The lux variable when i am directly feeding the data into it its successfully getting transmitted in HEX format while I am trying to transmit fAmbient data which changes upon every sample collected over I2C bus. The which i am receiving on the other end is 0 .

I am pasting the code down below please help.

#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include <string.h>
#include "inc/hw_memmap.h"
#include "inc/hw_ints.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/adc.h"
#include "driverlib/pin_map.h"
#include "inc/tm4c123gh6pm.h"
#define TARGET_IS_BLIZZARD_RB1
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "sensorlib/hw_isl29023.h"
#include "sensorlib/i2cm_drv.h"
#include "sensorlib/isl29023.h"
#include "driverlib/uart.h"

//functions and variables for setting up the lora network
int sendATCommand(char* ATCommand, char* expected_answer);
void loraConfigure(void);
uint8_t cond;
char luxResult[20] = "";

void stringToHex(char *luxResult);

char packet[25]="radio tx ";
char buffer[50]="";
void concatenate();


float fAmbient;
float lux;

uint32_t ui32ADC0Value[4];
uint32_t ui32ADC3Value[4];
volatile uint32_t ui32TempAvg;
volatile uint32_t ui32TempValueC;

#define DEBUG
#define ISL29023_I2C_ADDRESS 0x44 // ISL29023 I2C address
tI2CMInstance g_sI2CInst; // I2C master driver structure
tISL29023 g_sISL29023Inst; // ISL29023 sensor driver structure

volatile unsigned long g_vui8DataFlag; // Data ready flag
volatile unsigned long g_vui8ErrorFlag; // Error flag

//*************************************************************************
void ISL29023AppCallback(void *pvCallbackData, uint_fast8_t ui8Status)
{
	if(ui8Status == I2CM_STATUS_SUCCESS)
	{
		g_vui8DataFlag = 1;
	}
	g_vui8ErrorFlag = ui8Status;
}

void ISL29023I2CIntHandler(void)
{
	I2CMIntHandler(&g_sI2CInst);
}

void ISL29023AppErrorHandler(char *pcFilename, uint_fast32_t ui32Line)
{
	while(1)
	{
	}
}

void ISL29023AppI2CWait(char *pcFilename, uint_fast32_t ui32Line)
{
	while((g_vui8DataFlag == 0) && (g_vui8ErrorFlag == 0));

	if(g_vui8ErrorFlag)
	{
		ISL29023AppErrorHandler(pcFilename, ui32Line);
	}
	g_vui8DataFlag = 0;
}

int main(void)
{

	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

	//ADC CONFIGURATION i.e. CPU TEMP
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); // ENABLE ADC0 MODULE
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // ENABLE GPIO for ADC0
	GPIOPinTypeADC(GPIO_PORTE_BASE,GPIO_PIN_3|GPIO_PIN_2);// ENABLE A0 AND A1 OF ADC0 MODULE
	ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
	ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_TS | ADC_CTL_IE |
			ADC_CTL_END);
	ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH1 | ADC_CTL_IE |
			ADC_CTL_END);


	ADCSequenceEnable(ADC0_BASE, 3);
	ADCSequenceEnable(ADC0_BASE, 2);
	//UART 0
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
	UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 57600,
			(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_TWO | UART_CONFIG_PAR_NONE));

	//UART 1
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	GPIOPinConfigure(GPIO_PB0_U1RX);
	GPIOPinConfigure(GPIO_PB1_U1TX);
	GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
	UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 57600,
			(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
	//loraConfigure();


	//I2C CONFIGURATION
	SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
	GPIOPinConfigure(GPIO_PD0_I2C3SCL);
	GPIOPinConfigure(GPIO_PD1_I2C3SDA);
	GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
	GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);

	I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xFF, 0xFF, SysCtlClockGet());
	SysCtlDelay(SysCtlClockGet() / 3);

	//INITIALISING SENSORS
	ISL29023Init(&g_sISL29023Inst, &g_sI2CInst, ISL29023_I2C_ADDRESS,ISL29023AppCallback, &g_sISL29023Inst);
	ISL29023AppI2CWait(__FILE__, __LINE__);
	ISL29023ReadModifyWrite(&g_sISL29023Inst, ISL29023_O_CMD_I, ISL29023_CMD_I_OP_MODE_M,
			ISL29023_CMD_I_OP_MODE_ALS_CONT,
			ISL29023AppCallback, &g_sISL29023Inst);
	ISL29023AppI2CWait(__FILE__, __LINE__);

	while(1)
	{
		ISL29023DataRead(&g_sISL29023Inst, ISL29023AppCallback, &g_sISL29023Inst);
		ISL29023AppI2CWait(__FILE__, __LINE__);
		ISL29023DataLightVisibleGetFloat(&g_sISL29023Inst, &fAmbient);

		//calculating the CPU temperature
		// CLEAR INTERRUPT FLAG FOR ADC0, SEQUENCER 1
		ADCIntClear(ADC0_BASE, 1);
		// TRIGGER IS GIVEN FOR ADC 0 MODULE, SEQUENCER 1
		ADCProcessorTrigger(ADC0_BASE, 1);
		// STORE THE CONVERTED VALUE FOR ALL DIFFERENT SAMPLING IN ARRAY
		//ui32ADC0Value
		ADCSequenceDataGet(ADC0_BASE, 2, ui32ADC0Value);
		ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4;
		ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10;

		//calculating decibal values

		ADCSequenceDataGet(ADC0_BASE,3,ui32ADC3Value);

		//lux=172.607;
		//transmiting data via LoRa
		sprintf(luxResult, "%g",lux);
		stringToHex(luxResult);
		concatenate();//creating a packet to be transfered
		sendATCommand(packet,"OK\0");
		SysCtlDelay(20000000);//500ms delay
		sendATCommand("sys reset\r\n\0","OK\0");
		lux=fAmbient;
	}
}
int sendATCommand(char* ATCommand, char* expected_answer)
{
	uint8_t answer=0;
	while(*ATCommand!='\0')
	{
		UARTCharPut(UART1_BASE, *ATCommand);
		ATCommand++;
	}
	SysCtlDelay(4000000);//100 ms delay
	while(UARTCharsAvail(UART1_BASE))
	{
		UARTCharPut(UART0_BASE, UARTCharGet(UART1_BASE));
		answer=1;
	}
	return answer;
}
void loraConfigure(void)
{
	cond=sendATCommand("radio set mod lora\r\n\0","OK\0");
	SysCtlDelay(400000);//10ms delay
	cond=sendATCommand("radio get mod\r\n\0","lora\0");
	SysCtlDelay(400000);
	cond=sendATCommand("radio set pwr 15\r\n\0","OK\0");
	SysCtlDelay(400000);
	cond=sendATCommand("radio get pwr\r\n\0","15\0");
	SysCtlDelay(400000);
	cond=sendATCommand("radio set freq 868100000\r\n\0","OK\0");
	SysCtlDelay(400000);
	cond=sendATCommand("radio get freq\r\n\0","868100000\0");
	SysCtlDelay(400000);
	cond=sendATCommand("radio set sf sf12\r\n\0","OK\0");
	SysCtlDelay(400000);
	cond=sendATCommand("radio get sf\r\n\0","sf12\0");
	SysCtlDelay(400000);
	cond=sendATCommand("radio set cr 4/5\r\n\0","OK\0");
	SysCtlDelay(400000);
	cond=sendATCommand("radio get cr\r\n\0","4/5\0");
	SysCtlDelay(400000);
	cond=sendATCommand("radio set bw 125\r\n\0","OK\0");
	SysCtlDelay(400000);
	cond=sendATCommand("radio get bw\r\n\0","125\0");
	SysCtlDelay(400000);
	cond=sendATCommand("radio set crc on\r\n\0","OK\0");
	SysCtlDelay(400000);
	cond=sendATCommand("radio get crc\r\n\0","on\0");
	SysCtlDelay(400000);
}
void stringToHex(char *luxResult)
{

	char *pbuffer = buffer;
	int i;
	int len=strlen( luxResult );
	for(i=0;i<len;i++)
	{
		sprintf(pbuffer, "%x", luxResult[i]);
		pbuffer +=2;
	}
}
void concatenate()
{
	int count=9,i=0;
	while(buffer[i]!='\0')
	{
		packet[count]=buffer[i];
		count++;
		i++;
	}
	packet[count++]='\r';
	packet[count++]='\n';
}

  • Hello Stephen,

    Have you checked the UART lines to see if data is being sent at all? Have you been able to print strings of text or other data?

    If the only data presenting the issue with printing is what originates as a float such a 'lux' then we can focus on the float to hex conversion chain.