Konstantin
New member
Как реализовать сортировку ответа от ESP. Т.е. запустив сервер на ESP, клиент отсылает какие то данные, ESP ловит их в виде результата (+IPD,0,5:hello). как на атмеги отсортировать ответ, чтобы переменная была в виде строки (hello), а не в виде (+IPD,0,5:hello)???
Код инициализации UART-a:
[inline]
[HASHTAG]#define[/HASHTAG] BAUDRATE 9600
[HASHTAG]#define[/HASHTAG] F_CPU 8000000UL
[HASHTAG]#include[/HASHTAG] <avr/io.h>
[HASHTAG]#include[/HASHTAG] <util/delay.h>
[HASHTAG]#include[/HASHTAG] <stdlib.h>
[HASHTAG]#include[/HASHTAG] <avr/interrupt.h>
unsigned char byte_receive = 0;
unsigned char NUM = 0;
void send_Uart(char c)
{
while(!(UCSRA&(1<<UDRE)));
UDR = c;
}
void send_Uart_str(char *s)
{
while (*s != '\0')
{
send_Uart(*s);
s++;
}
}
int getch_Uart(void)
{
while(!(UCSRA&(1<<RXC)));
return UDR;
}
void init_UART(void)
{
UBRRH=0;
UBRRL=51;
UCSRB |= (1<<RXCIE)|(1<<RXEN)|(1<<TXEN);
UCSRC |= (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);
}
ISR(USART_RXC_vect)
{
NUM = UDR;
byte_receive = 1;
send_Uart(NUM);
}
int main(void)
{
DDRC |= (1<<5);
DDRC |= (1<<4);
DDRC |= (1<<3);
init_UART();
_delay_ms(5000);
send_Uart(13);send_Uart(10);
send_Uart_str("AT+CIPMUX=1");
send_Uart(13);send_Uart(10);
_delay_ms(5000);
send_Uart_str("AT+CIPSERVER=1,8888");
send_Uart(13);send_Uart(10);
_delay_ms(5000);
PORTC |= (1<<5);
while(1)
{
//sei();
if (NUM == 1)
PORTC |= (1<<3);
if (NUM == 2)
PORTC &=~ (1<<3);
//cli()
}
}
[/inline]
Код инициализации UART-a:
[inline]
[HASHTAG]#define[/HASHTAG] BAUDRATE 9600
[HASHTAG]#define[/HASHTAG] F_CPU 8000000UL
[HASHTAG]#include[/HASHTAG] <avr/io.h>
[HASHTAG]#include[/HASHTAG] <util/delay.h>
[HASHTAG]#include[/HASHTAG] <stdlib.h>
[HASHTAG]#include[/HASHTAG] <avr/interrupt.h>
unsigned char byte_receive = 0;
unsigned char NUM = 0;
void send_Uart(char c)
{
while(!(UCSRA&(1<<UDRE)));
UDR = c;
}
void send_Uart_str(char *s)
{
while (*s != '\0')
{
send_Uart(*s);
s++;
}
}
int getch_Uart(void)
{
while(!(UCSRA&(1<<RXC)));
return UDR;
}
void init_UART(void)
{
UBRRH=0;
UBRRL=51;
UCSRB |= (1<<RXCIE)|(1<<RXEN)|(1<<TXEN);
UCSRC |= (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);
}
ISR(USART_RXC_vect)
{
NUM = UDR;
byte_receive = 1;
send_Uart(NUM);
}
int main(void)
{
DDRC |= (1<<5);
DDRC |= (1<<4);
DDRC |= (1<<3);
init_UART();
_delay_ms(5000);
send_Uart(13);send_Uart(10);
send_Uart_str("AT+CIPMUX=1");
send_Uart(13);send_Uart(10);
_delay_ms(5000);
send_Uart_str("AT+CIPSERVER=1,8888");
send_Uart(13);send_Uart(10);
_delay_ms(5000);
PORTC |= (1<<5);
while(1)
{
//sei();
if (NUM == 1)
PORTC |= (1<<3);
if (NUM == 2)
PORTC &=~ (1<<3);
//cli()
}
}
[/inline]