Questions: app receive the integer send by Bluetooth

i think there are some problem on my coding, i did not receive anything from Bluetoth. Would you mind have a look on my code?

You can put your code here in text file. I only have a little experience with arduino. But maybe we can find something. Maybe something with libraries as you mentioned.

this is my Bluetooth Library:

#include <stdio.h>	
#include "tm4c123gh6pm.h"
#include <stdint.h>
#include "SysTick.h"




	double Bluetooth_baudCalc = 0;
	double Bluetooth_fractionBaud = 0;
	int Bluetooth_integerBaud = 0;
	int Bluetooth_calcFractionBaud = 0;
	int Bluetooth_regBits = 0;
	int Bluetooth_Parity = 0;

void Bluetooth_UART_Init(int Bluetooth_bits,int Bluetooth_stopBits, char Bluetooth_parity, double Bluetooth_baudRate){ volatile uint32_t delay;
  SYSCTL_RCGCUART_R = 0x80; 				// UART module 7 enable and activate clock
	SYSCTL_RCGCGPIO_R |= 0x10;  			// activate clock for Port E
	UART7_CTL_R = 0; 									// Disable UART7
	GPIO_PORTE_AFSEL_R = 0x03;        // set alt funct on PE0 and 1
	GPIO_PORTE_PDR_R = 0x10;
	GPIO_PORTE_PCTL_R = 0x00000011;
	GPIO_PORTE_DIR_R  = 0x02;				// PF0 in, PF1 output
	GPIO_PORTE_DEN_R = 0x03;          // enable digital
  GPIO_PORTE_AMSEL_R = 0x00;        // disable analog on PE
	// initialize s function of stopbits
	Bluetooth_stopBits = Bluetooth_stopBits <<3; //Shift 4 places to be in the bit 3 position.
	//initialize uart interrupt
	UART7_IM_R = 0x10; // Interrupt is sent to controller on receive
	NVIC_EN1_R  = 0x80000000; // Enable interrupt on port E Interrupt 63 UART 7
	NVIC_PRI15_R = 0xE0000000;	// Set priority setting PRI7 
	// Calculate Baud Rate
	Bluetooth_baudCalc = 80000000/(16*Bluetooth_baudRate);
	Bluetooth_integerBaud = Bluetooth_baudCalc;
	Bluetooth_fractionBaud = Bluetooth_baudCalc - Bluetooth_integerBaud;
	Bluetooth_calcFractionBaud =(Bluetooth_fractionBaud * 64 + 0.5);
	// Assign # of bits registrar values to switch case.
	switch(Bluetooth_bits)
	{
		case 1:
		{
			Bluetooth_regBits = 0x60;  //8 bits
			break;
		}
		case 2:
		{
			Bluetooth_regBits = 0x40; // 7bits
			break;
		}
		case 3:
		{
			Bluetooth_regBits = 0x20; // 6 bits
			break;
		}
		default:
		{
			Bluetooth_regBits = 0x00; //5 bits
			break;
		}
	}
	//Setting registar value for parity
	switch(Bluetooth_parity)
	{
		case '0': //Parity even
		{
			Bluetooth_Parity = 0x86;
			break;
		}
		case '1': //Parity odd
		{
			Bluetooth_Parity = 0x82;
			break;
		}
		default: //Parity off
		{
			Bluetooth_Parity = 0x00;
			break;
		}
	}
	// initialize uart
	UART7_CTL_R = 0; 	// Disable UART7
	UART7_IBRD_R = Bluetooth_integerBaud; //Assigning integer part
	UART7_FBRD_R = Bluetooth_calcFractionBaud; //Assigning fractional part
	UART7_LCRH_R  |= Bluetooth_regBits; //Oring the word length for the line control
	UART7_LCRH_R  |= Bluetooth_stopBits; //Oring 2 or 1 stop bits
	UART7_LCRH_R |= Bluetooth_Parity; //Assigning parity to registar
	UART7_IFLS_R = 0x00;  // enable FIFO
	UART7_LCRH_R |= 0x10;  // set fifo level
	UART7_CC_R = 0x00; //Want to use system clock
	UART7_CTL_R |= 0x0301; //Turning uart1 back on, transmit and recevie back on
	
	
	UART7_CC_R = 0x00; // UART runs on system clock
	UART7_CTL_R = 0x0301; 	// Enable UART, send, receive
	
	
}

void UART_Tx(int8_t Data){

   UART7_DR_R = Data;// Send the data through UART transmit pin
	
}

This is my Main code


#include <stdio.h>	
#include <stdint.h>
#include "tm4c123gh6pm.h"
#include "ST7735.h"
#include "PLL.h"
#include "SysTick.h"
#include <stdbool.h>
#include "CO2_Sensor.h"
#include "Temp_Header.h"
#include "Bluetooth.h"

void EnableInterrupts(void);
void WaitForInterrupt(void);
extern uint8_t rx_data[8];
extern uint8_t rx_index;
double co2_calculation;


int main(void){
	PLL_Init();									//Initilize PLL to 80MHz
	SysTick_Init();							//Initilize SysTick Timer
	ST7735_InitR(INITR_REDTAB); //Initilize LCD Screen
	EnableInterrupts();
	CO2_UART_Init (1, 0,' ', 9600); // initialize co2 uart
	tempSensor_Init();
	Bluetooth_UART_Init(1, 0,' ', 9600);
	
	

	while(1){
		sendBytes();
		WaitForInterrupt();	
		co2_calculation = rx_data[3]*256+rx_data[4];
    //checksum = 256-(rx_data[0]+rx_data[1]+rx_data[2])
//		ST7735_SetCursor(10,6);
//		ST7735_DrawString(11, 6, "      ", 0xFFFF);
//    ST7735_OutUDec(co2_calculation);
//		ST7735_DrawString(11,8,"ppm ", 0xF69F);
//			ST7735_SetCursor(11,11);                  // Set location of temp read number in lCD
//    ST7735_OutUDec(GetTemp());          // Display results 
			int8_t temp = GetTemp();
		 int16_t co2_concentration = co2_calculation;
		// Split the 16-bit integer into two 8-bit integers
		int8_t co2_high_byte = (co2_concentration >> 8) & 0xFF;
		int8_t co2_low_byte = co2_concentration & 0xFF;
		// Send the data over Bluetooth
		UART_Tx(temp); // Send the temperature as an 8-bit integer
		UART_Tx(co2_high_byte); // Send the high byte of the CO2 concentration as an 8-bit integer
		UART_Tx(co2_low_byte); // Send the low byte of the CO2 concentration as an 8-bit integer
		
			SysTick_Wait10ms(15);
	
	
	
		
	}
	





}

For my Temperature and CO2 library, they all can be display reading number on the LCD screen, so i think we do not need to modify those codes.

It's best if you do this with the original source files.

try

Bluetooth_UART_Init(8, 1,' ', 9600);

ok, i have no idea for that. But these two are my main and Bluetooth library, do u need my CO2 and Temp library/

8 bits
for this part, i am using a switch statement, when i initialize ''1', at there , which means i make the bit size for 8bit.

Oh, I didn't go any deeper. I think you should go to the forum dedicated to programming this module and ask them to check the code to see if addresses etc are correct for this module. Once your module sends data correctly, we'll help with the app code.

What does while(1) mean? Is this an infinite loop? Can the module send data once? I don't see any logical fallacies. Only there may be a problem with addressing the BT module. I don't know this module and I can't tell if it's correct.

yes, it is a infinite loop. I was trying to find some forum for helping on the coding, but i can not find some. Do u have any idea where i can seeking for help?

Did you find the library on the internet for this particular microcontroller? did I write it myself using the documentation of the microcontroller? Maybe download the documentation from the internet and check if the addressing is correct. Does this module have BT on board, or do you use an external module, e.g. hc-05? Maybe you swapped the RX and TX pins?

oh, i will check them, this might be a problem, i was using this Bluetooth code to control board LED turn on or off. i will check pin first

I checked the connection, i think there should be problems on the coding, i am using the extra blurtooth module TEL0026.

It's hard for me to advise anything why the module is not sending anything.

1 Like

Dear @Zhaonan_Liu,
as Patryk_F already said, it's hard to help you because the HW you are using isn't the typical Arduino series.
Anyway, as he already suggested, by searching the web, you could probably find some specific hints, like the following:

Maybe helped by reading this link you could implement a chunk of code that allows you verify if your HW is sending something to the BT terminal. Once you are done with that, to make the receiving app, will follow.

hi @Patryk_F i make transmit working but i get some point strange. when i run


it is showing CO2 reading, i think this reading is good. But when i reading temp, it just show 0,4,36, these three number, when i put these together, it will show like below

Maybe let's start like this:
In your code for the module, turn off co2 sending, leave only temperature.

UART_Tx(temp); // Send the temperature as an 8-bit integer
		//UART_Tx(co2_high_byte); // Send the high byte of the CO2 concentration as an 8-bit integer
		//UART_Tx(co2_low_byte); // Send the low byte of the CO2 concentration as an 8-bit integer

Blocks set like this:

And show what you recejved in app.

The temperature is measured from -127 to +127 degrees? Then use this:

I have already tried on that, maybe the problem is I am using temperature and Bluetooth modules in the same port E, it might have a conflict. I am changing Bluetooth to port D and I will try again.