Close or Esc Key

Arduino Projects   |   Raspberry Pi   |   Electronic Circuits   |   AVR   |   PIC   |   8051   |   Electronic Projects

Esp8266 interfacing with Atmega 8/16

1 post / 0 new
bivash
bivash's picture
Offline
Last seen: 2 months 3 weeks ago
Joined: 25/09/2017 - 14:25
Esp8266 interfacing with Atmega 8/16
I am not getting OK response when I am sending "AT\r\n" command to ESP8266. I am working on 9600bps and my module(esp) is also working on 9600bps, I checked it through Hyper terminal and it works fine.
 
 
 
 
//************************************************************
//Project: ESP-8266 with Atmega8(16Mhz)
//Author: Bivashkumar singh
//Module description: 4-bit Lcd 
//************************************************************
 
 
#include <stdio.h>
#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>
#include "lcd.h"
unsigned char recive[50] = {0};
 
#define LCD_DPRT PORTC
#define LCD_DDDR DDRC
#define LCD_DPIN PINC
#define LCD_CPRT PORTB
#define LCD_CDDR DDRB
#define LCD_CPIN PINB
#define LCD_RS 0
#define LCD_RW 1
#define LCD_EN 2
 
int i=0;
void lcdcommand(unsigned char cmnd)
{
unsigned char chr = cmnd;
chr = (cmnd>>4); 
        LCD_DPRT = chr;
        LCD_CPRT &= ~(1<<LCD_RS);
        LCD_CPRT &= ~(1<<LCD_RW);
        LCD_CPRT |= (1<<LCD_EN);
        _delay_ms(1000);
        LCD_CPRT &= ~(1<<LCD_EN);
        for(i=0;i<=2;i++)
        _delay_ms(500);
        LCD_DPRT = (cmnd & 0x0f);
        LCD_CPRT |= (1<<LCD_EN);
        _delay_ms(1000);
        LCD_CPRT &= ~(1<<LCD_EN);
        for(i=0;i<=3;i++)
        _delay_ms(500);
 
}
 
 
 
 
void lcd_init()
{
        LCD_DDDR = 0XFF;
        LCD_CDDR = 0XFF;
        LCD_CPRT &=~(1<<LCD_EN);
for(i=0;i<=1;i++) 
        _delay_ms(1000); 
        lcdcommand(0x33);
_delay_ms(1000);
lcdcommand(0x32);
_delay_ms(1000);
lcdcommand(0x28);
_delay_ms(1000);
        lcdcommand(0x0e);
_delay_ms(1000);
        lcdcommand(0x01);
        for(i=0;i<=1;i++)
        _delay_ms(1000);
        lcdcommand(0x06);
}
 
 
void lcddata(unsigned char data)
{
       unsigned char chr = data;
        chr = (data>>4); 
        LCD_DPRT = chr;
        LCD_CPRT |= (1<<LCD_RS);
        LCD_CPRT &= ~(1<<LCD_RW);
        LCD_CPRT |= (1<<LCD_EN);
        _delay_ms(100);
        LCD_CPRT &= ~(1<<LCD_EN);
LCD_DPRT = (data & 0X0F);
LCD_CPRT |= (1<<LCD_EN);
        _delay_ms(500);
LCD_CPRT &= ~(1<<LCD_EN);
        for(i=0;i<=4;i++)
        _delay_ms(500);
}
 
 
void lcd_gotoxy(unsigned char x,unsigned char y)
{
        unsigned char firstchar[]={0x80,0xc0,0x94,0xd4};
        lcdcommand(firstchar[y-1]+x-1);
        _delay_us(500);
}
 
void lcd_print(char *ch)
{
        unsigned char i = 0;
        while(ch[i] !=0)
        {
        lcddata(ch[i]);
        i++;
        }
}
 
 
int lcd(unsigned char *recive)
{
        lcd_init();
        lcd_gotoxy(1,1);
// while(recive[i])
        lcd_print(recive);
        while(1);
return 0;
}
 
 
 
 
//****************************************ESP-8266***************************
//***************************************************************************
unsigned char recive[10] = {0};
//____________________________UART INIT______________________________________
//___________________________________________________________________________
void usart_init(void)
{
        UCSRB = (1<<TXEN) | (1<<RXEN);
        UCSRC = (1<<UCSZ1) | (1<<UCSZ0) | (1<<URSEL);
        UBRRL = 103; //baud rate 9600 (atmega8 16MHz)
}
 
 
//____________________________UART SEND_______________________________________
//____________________________________________________________________________
void usart_send(char *ch)
{
char i=0;
while(ch[i] != 0) 
{
        while(!(UCSRA & (1<<UDRE)));
        UDR = ch[i];
i++;
}
}
 
 
//_____________________________UART RECIVE_____________________________________
//_____________________________________________________________________________
void usart_recive()
{
while(UDR)
{
while(!(UCSRA &(1<<RXC)));
recive[i++] = UDR;
}
}
 
 
 
//---------------------------------main---------------------------------------------
//----------------------------------------------------------------------------------
int main(void)
{
int i=0;
cahr ch[50] = "AT\r\n"
 
    usart_init();
    usart_send(ch);
usart_send("\r\n");
_delay_ms(500);
for(i=0;i<=20;i++)
recive[i]=usart_recive();
 
lcd(recive);
 
 
return 0;
}
 
//################################### END ###########################################
//###################################################################################