bluetooth receive string for control of servo motor

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi all, i want to control servo motor with bluetooth module hc-05. process is when i enter the OCR1A values in serial monitor app the timer1 set the angle of the servo. but the receive string part of the usart is not working. code that i run for atmega16 microcontroller  is :

#define F_CPU 16000000UL 
#include<string.h>
#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>
#include <stdio.h>
#define BUF_SIZE 10

void UART_init()
{
UCSRB |= (1 << RXEN)|(1<<TXEN);
UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);
UBRRL = 0x67;
}

unsigned char UART_RxChar()
{
while ((UCSRA & (1 << RXC)) == 0);
return(UDR); 
}

void UART_TxChar(char ch)
{
    while (! (UCSRA & (1<<UDRE)));    /* Wait for empty transmit buffer*/
    UDR = ch ;
}

void UART_SendString(char *str)
{
    unsigned char j=0;
    
    while (str[j]!=0)        
    {
        UART_TxChar(str[j]);    
        j++;
    }
}

int main(void)

int main(void)

{
char buff[4];
int i=0,j,k=0;
DDRD =(1<<PD5);
UART_init();
TCCR1A  = 0x82;
TCCR1B  = 0x1B;
ICR1H   = 0x13;
ICR1L    = 0x87;

    while(1)
    {    
        
        while(i<=3)
        {
     buff[i] = UART_RxChar();

     if(buff[3] == '!')
     {
        
     break;
     }

        i++;
        }

        UART_SendString(buff); // for testing whether it is taking the value entered in serial monitor app or not

        j   = atoi(buff);
        OCR1A  = j;
        
        _delay_ms(1500);

    }

        
}
 

help me out with this 

thanks in advance

nsk

Last Edited: Mon. Jun 10, 2019 - 02:17 PM