Not receiving bt data into usart buffer at all

So I'm stuck at the first step of communication. Just want to send a string to HC-05 and write the full message on LCD. Currently i suspect that the usart buffer isn't filling at all, therefor probably something with the delimiter byte.

Did my best to find the problem, C code from microchip studio and app inventor are attached below.

#include "AVR lib/AVR_lib.h"
#include <avr/io.h>
#include "LCD/lcd.h"
#include "USART/USART.h"
#include <avr/eeprom.h>
#include <util/delay.h>
#include <avr/interrupt.h>

#define sklopka PB2
#define CLK PD3
#define DT PD2

//alociranje prostora u memoriji za zapis svih varijabli
uint8_t brojac;
uint8_t razina;


uint8_t trenutni_CLK;
uint8_t trenutni_DT;
uint8_t prosli_CLK;
uint8_t prosli_DT;

uint8_t snare_osjet;
uint8_t snare_luk;

uint8_t cinela_osjet;
uint8_t cinela_luk;

ISR(INT0_vect) {
	_delay_ms(10);
	trenutni_DT=get_pin(PIND, DT);
	if(prosli_DT != trenutni_DT) {
		if(prosli_DT != prosli_CLK) {
			brojac--;
			} else if(prosli_DT == prosli_CLK) {
			brojac++;
		}
	}
	prosli_DT=trenutni_DT;
	lcd_refresh();
}

ISR(INT1_vect) {
	_delay_ms(10);
	trenutni_CLK=get_pin(PIND, CLK);
	prosli_CLK=trenutni_CLK;
	lcd_refresh();
}

ISR(INT2_vect) {
	if(debounce(&PINB, sklopka, 0) == 0) {
		razina++;
		brojac=0;
	}
	lcd_refresh();
}


int ucitavanje_iz_memorije (void) {
	snare_osjet = eeprom_read_byte(0);
	snare_luk = eeprom_read_byte(1);
	cinela_osjet = eeprom_read_byte(2);
	cinela_luk = eeprom_read_byte(3);
	return 0;
}

void lcd_refresh() {
	lcd_clrscr();
	lcd_home();
}

void inicijalizacija(){
	brojac=0;
	razina=0;
	set_bit_reg(MCUCR, ISC00);
	reset_bit_reg(MCUCR, ISC01);
	set_bit_reg(GICR, INT0);
	
	set_bit_reg(MCUCR, ISC10);
	reset_bit_reg(MCUCR, ISC11);
	set_bit_reg(GICR, INT1);
	
	reset_bit_reg(MCUCSR, ISC2);
	set_bit_reg(GICR, INT2);
	
	// sklopka, CLK i DT postavljeni kao ulazni pinovi
	DDRD &= ~((1 << CLK) | (1 << DT));
	DDRB &= ~(1 << sklopka);
	DDRB |= (1 << PB7);
	// prikljucivanje priteznih otpornika
	PORTD |= (1 << CLK) | (1 << DT);
	PORTB |= (1 << sklopka);
	prosli_CLK = get_pin(PIND, CLK);
	prosli_DT = get_pin(PIND, DT);
	lcd_init();
	lcd_refresh();
	usart_init(9600);
	sei(); // globalno omogucenje prekida

	
}

int main(void){
	
	inicijalizacija();
	while (1){
		ucitavanje_iz_memorije();
		if (razina == 0) {
			if (brojac < 0) brojac = 2;
			if (brojac > 2) brojac = 0;
		} else if (razina == 1) {
			if (brojac < 0) brojac = 9;
			if (brojac > 9) brojac = 0;
		}
		
		
		if(usart_read_all() == 1) {
			set_port(PORTB, PB7, 1);
			lcd_clrscr();
			lcd_home();
			lcd_print("%s", usart_buffer);
			
			
			if(usart_buffer[0] == 'S' && usart_buffer[1] == 'O') eeprom_write_byte(0, usart_buffer[2]-48);
			else if(usart_buffer[0] == 'C' && usart_buffer[1] == 'O') eeprom_write_byte(1, usart_buffer[2]-48);
			else if(strcmp(usart_buffer, "Get_SO")) usart_write("CO%d", eeprom_read_byte(0));
			else if(strcmp(usart_buffer, "Get_CO")) usart_write("CO%d", eeprom_read_byte(1));
		}
	return 0;
	}
}

the usart header is here:

/*
 Naslov: MIKRORAÈUNALA - Programiranje mikrokontrolera porodice 
 Atmel u programskom okruženju Atmel Studio 6
 Autori: Zoran Vrhovski, Marko Miletiæ
 
 USART.h
 */ 

#define F_CPU 8000000ul
#include <avr/io.h>
#include <avr/interrupt.h>
#include "stdbool.h"
#include <stdio.h>

void usart_init(uint32_t baut_rate);
void usart_write_int(int16_t a);
void usart_write_char(char data);
void usart_write_string(char *a);
void usart_write_float(float a);
void usart_write(char *szFormat, ...);
char usart_read_char();
bool usart_read_all();

#define end_char 0x0A // zakljuèni znak // 0x0D je znak za poèetak linije
#define MESSAGE_LENGTH 50 // maksimalna duljina poruke
char usart_buffer[MESSAGE_LENGTH];

and the blocks from ai are here:




Screenshot 2025-09-04 224724

Your C code does not look like any other C code for BlueTooth on this board.

Consider using a Bluetooth terminal program from the Play Store to test your C code, independent of AI2.

If that does not work, check for tx and rx connection in your hardware.

Regarding yout AI2 code, one should not receive text without first checking that text is available to receive, otherwise your AI2 code will block.

Here is a simple sample, to receive text ending in \n (Line Feed):

(Canned Reply)
Here is a simple BlueTooth text receiver sample, for single value per line:
blocks
initialize global message to

...

This AI2 code assumes the text is being sent using println().

thank you for your help. my c code is different probably because i'm using headers provided by my professor some of which he wrote himself.

physical connections are okay, i believe the problem is purely software, my assumption is that the ai sending code isn't correct. can you provide please an example of sending a message from ai to bluetooth module?

thanks!


BlueTooth_delimiter_sample.aia (3.5 KB)

(Canned Reply: ABG- Export & Upload .aia)
Export your .aia file and upload it here.

export_and_upload_aia

.