Maker Pro
Maker Pro

Esp8266 wifi module on avr gcc

Hello..I am working on the esp82666 WiFi Module and want to use it as acess point but since I am new to avr gcc I am having issues withits coding.. my code is giving errors..kindly help me with this..
This is my code...for using my wifi module as an access point..
#include <avr/io.h>
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>

#define BAUDRATE 9600
#define BAUD_PRESCALLER (((F_CPU / (BAUDRATE * 16UL))) - 1)
#define DEBUG true
#define String espmode
#define espmode "3"
#define SSid "KFRL-4"
#define password "RFID5678"

void Esp_init(void);
unsigned char Esp_receive(void);
void Esp_send( unsigned char data);
void Esp_putstring(char* StringPtr);
void wifiSetup(String,String,String);
void sendData(String,const,boolean);

char String[]="Hello world";
unsigned char data;

int main(void)
{
Esp_init();
while(1)
{
wifiSetup(String espmode,SSid,password);
if (Esp_receive()!=0X00)
{
_delay_ms(1000);
int ConnectionId=Esp_receive()-48;
Esp_putstring(String);
Esp_send(data);
}
}
return 0;
}
void sendData(String Command,const int timeout,boolean debug)
{
String response="";
Esp_receive(Command);
long int time=millis();
while(time+timeout)>millis;
{
while(Esp_receive()!=0X00);
{
char c=Esp_receive();
response+=c;
}
}
if(debug)
{
Esp_putstring(response);
}
return response;
}
void wifiSetup(String mode,String SSid,String pass)
{
sendData("AT\r\n",2000,DEBUG); //reset mode
String mode0= "AT+CWMODE=";
mode0 += mode;
mode0 += "\r\n";
sendData(mode0,2000,DEBUG); // configure as access point
String ssidset="AT+CWJAP=\"";
ssidset += SSid ;
ssidset += "\",\"" ;
ssidset += pass ;
ssidset += "\"" ;
ssidset += "\r\n" ;
sendData(ssidset,5000,DEBUG);
return;

}

void Esp_init(void)
{
//UBRRn is a baudrate register
//UMSELn bit in USART Control and Status Register C (UCSRnC) selects
//between asynchronous and synchronous operation
UBRR0H = (uint8_t)(BAUD_PRESCALLER>>8); // Baud Rate Register upper 4 bits
UBRR0L = (uint8_t)(BAUD_PRESCALLER); // Baud Rate Register lower 4 bits
//enable the transmission and receive functionality independently.
//Both the RXENn bit (Receive Enable) and the TXEN(TXENn) bit (Transmitter Enable)
//are both located in the B Register (UCSRnB)
UCSR0B = (1<<RXEN0)|(1<<TXEN0);
//All of our configuration options are located in Register C
UCSR0C = (3<<UCSZ00); //Set frame

}

unsigned char Esp_receive(void){

while(!(UCSR0A & (1<<RXC0)));//Wait until data is received
return UDR0; // Read the data from the RX buffer

}

void Esp_send( unsigned char data) //write byte to serial port
{

while(!(UCSR0A & (1<<UDRE0)));// Wait until buffer is empty
UDR0 = data;// Send the data to the TX buffer

}

void Esp_putstring(char* StringPtr){

while(*StringPtr != 0x00){
Esp_send(*StringPtr);
StringPtr++;}

}
 
Top