سلام دوستان من میخوام یک ردیاب ماشین با sim808 با هدربورد stm32f103RET6 طراحی کنم و میخوام که با فرستادن SMS لینک گوگل مپ رو به شماره ای که بهش میدم ارسال کنه. میخوام کد رو مرحله به مرحله جلو ببرم. با مبدل USB به TTL مختصات رو میتونم دریافت کنم و میتونم مختصات رو بلافاصله به شماره مورد نظر بفرستم ولی وقتی میخوام یه اس ام اس بفرستم و تحلیلش کنم که مثلا با فرستادن 1234 یک کاری برام انجام بده به عنوان مثال روشن کردن یک LED به مشکل میخورم و وقتی با دیباگر کیل دیباگ میکنم نشون میده که کلی کاراکتر A فرستاده شده به پورت سریال. این کدی که میذارم با روش polling هست ولی با اینتراپت هم که نوشتم ارور HARDFAULT میده. مشکل از چی میتونه باشه ؟
این کدی که جواب نمید ه
کد:
#include <stm32f10x.h>#include "usart.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
char S=0x1A;
#define Enter usart_sendchar('\n');
#define CR usart_sendchar('\r');
#define GIM usart_sendchar('"');
#define SUB usart_sendchar(S);
char get_Enter = 0;
uint8_t ch;
char str1[300];
int i;
char str_tmp[100];
char str_tmp2[100];
void Send_SMS(char *text);
void del_All_SMS(void);
void CMGF_1(void);
void GGNSPWR(void);
void CGNSINF(void);
void Delay_ms (uint32_t Time);
volatile uint32_t msTicks;
// the interrupt handler for the systick module
void SysTick_Handler(void) {
msTicks++;
}
void Delay_ms (uint32_t dlyTicks) {
uint32_t curTicks;
curTicks = msTicks;
while ((msTicks - curTicks)< dlyTicks);
}
void CMGF_1(void)
{
str_tmp[0]='\0';
Delay_ms(100);
strcpy(str_tmp,"AT+CMGF=1");
Delay_ms(500);
usart_sendstring(str_tmp);
Enter
CR
}
void del_All_SMS(void)
{
str_tmp[0]='\0';
Delay_ms(100);
strcpy(str_tmp,"AT+CMGD=1,4");
Delay_ms(500);
usart_sendstring(str_tmp);
Enter
CR
}
void CGNSPWR(void)
{
str_tmp[0]='\0';
Delay_ms(100);
strcpy(str_tmp,"AT+CGNSPWR=1");
Delay_ms(500);
usart_sendstring(str_tmp);
Enter
CR
}
void CGNSINF(void)
{
str_tmp[0]='\0';
Delay_ms(100);
strcpy(str_tmp,"AT+CGNSINF");
Delay_ms(500);
usart_sendstring(str_tmp);
Enter
CR
}
void CMGR(void)
{
str_tmp[0]='\0';
Delay_ms(100);
strcpy(str_tmp,"AT+CMGR=1");
Delay_ms(500);
usart_sendstring(str_tmp);
Enter
CR
}
void Send_SMS(char *text)
{
CMGF_1();
Delay_ms(500);
str_tmp[0]='\0';
Delay_ms(100);
strcpy(str_tmp,"AT+CMGS=");
Delay_ms(500);
usart_sendstring(str_tmp);
GIM
str_tmp[0]='\0';
Delay_ms(100);
strcpy(str_tmp,"+989058316399");
Delay_ms(500);
usart_sendstring(str_tmp);
GIM
Enter
CR
Delay_ms(500);
usart_sendstring(text);
Enter
CR
str_tmp[0]='\0';
Delay_ms(500);
SUB
Delay_ms(1000);
del_All_SMS();
}
int main()
{
SystemInit();
SysTick_Config(SystemCoreClock/1000); // setup systick timer for 1ms interrupts
usart_init();
CMGF_1();
Delay_ms(250);
del_All_SMS();
Delay_ms(250);
CGNSPWR();
Delay_ms(250);
RCC->APB2ENR|=(1<<3);
GPIOB->CRL &= 0xF;
GPIOB->CRL |= 0x3;
while (1)
{
char* u;
char* j;
char* h;
do {
usart_getstring(str_tmp2);
u=strstr(str_tmp2,"+CMTI:");
}
while (!u);
CMGR();
u=0;
do {
usart_getstring(str_tmp2);
j=strstr(str_tmp2,"+CMGR:");
}
while (!j);
h=strstr(str_tmp2,"1234");
if (h){
GPIOB->BSRR |= (1<<0);
}
}
}
اینم کد قسمت سریال
کد:
#include "stm32f10x.h"#include "usart.h"
char str[200];
char data;
//// initialize usart
void usart_init(void)
{
RCC->APB2ENR |= ( 1UL << 0); /* enable clock Alternate Function */
AFIO->MAPR &= ~( 1UL << 2); /* clear USART1 remap */
RCC->APB2ENR |= ( 1UL << 2); /* enable GPIOA clock */
GPIOA->CRH &= ~(0xFFUL << 4); /* clear PA9, PA10 */
GPIOA->CRH |= (0x0BUL << 4); /* USART1 Tx (PA9) output push-pull */
GPIOA->CRH |= (0x04UL << 8); /* USART1 Rx (PA10) input floating */
RCC->APB2ENR |= ( 1UL << 14); /* enable USART#1 clock */
USART1->BRR = 0x0271; /* 115200 baud @ PCLK2 72MHz */
USART1->CR1 = (( 1UL << 2) | /* enable RX */
( 1UL << 3) | /* enable TX */
( 0UL << 12) ); /* 1 start bit, 8 data bits */
USART1->CR2 = 0x0000; /* 1 stop bit */
USART1->CR3 = 0x0000; /* no flow control */
USART1->CR1 |= (( 1UL << 13) ); /* enable USART */
// USART1->CR1 |= ( 1UL << 5); // RXNE interrupt enable
// NVIC_SetPriority(USART1_IRQn,0); /* Default priority group 0, can be 0(highest) - 31(lowest) */
// NVIC_EnableIRQ(USART1_IRQn); /* Enable UART0 Interrupt */
}
void usart_sendchar(char data){
while(!(USART1->SR&(1<<7)));
USART1->DR=data;
}
char usart_getchar(void)
{
while (!(USART1->SR&(1<<5)));
data=USART1->DR ;
return data;
}
void usart_getstring(char *str)
{
char *temp = str;
do{
*temp = usart_getchar();
usart_sendchar (*temp) ;
} while(*(temp++) != 0x0D );
*(temp-1) = 0;
}
void usart_sendstring(char *s)
{
while (*s)
{
usart_sendchar(*s);
s++;
}
}
اینم کدی که جواب میده (ارسال مختصات بلافاصله)
کد:
#include <stm32f10x.h>
#include "usart.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
char S=0x1A;
#define Enter usart_sendchar('\n');
#define CR usart_sendchar('\r');
#define GIM usart_sendchar('"');
#define SUB usart_sendchar(S);
char get_Enter = 0;
uint8_t ch;
char str1[300];
int i;
char str_tmp[100];
char str_tmp2[100];
void Send_SMS(char *text);
void del_All_SMS(void);
void CMGF_1(void);
void GGNSPWR(void);
void CGNSINF(void);
void Delay_ms (uint32_t Time);
volatile uint32_t msTicks;
// the interrupt handler for the systick module
void SysTick_Handler(void) {
msTicks++;
}
void Delay_ms (uint32_t dlyTicks) {
uint32_t curTicks;
curTicks = msTicks;
while ((msTicks - curTicks)< dlyTicks);
}
void CMGF_1(void)
{
str_tmp[0]='\0';
Delay_ms(100);
strcpy(str_tmp,"AT+CMGF=1");
Delay_ms(500);
usart_sendstring(str_tmp);
Enter
CR
}
void del_All_SMS(void)
{
str_tmp[0]='\0';
Delay_ms(100);
strcpy(str_tmp,"AT+CMGD=1,4");
Delay_ms(500);
usart_sendstring(str_tmp);
Enter
CR
}
void GGNSPWR(void)
{
str_tmp[0]='\0';
Delay_ms(100);
strcpy(str_tmp,"AT+CGNSPWR=1");
Delay_ms(500);
usart_sendstring(str_tmp);
Enter
CR
}
void CGNSINF(void)
{
str_tmp[0]='\0';
Delay_ms(100);
strcpy(str_tmp,"AT+CGNSINF");
Delay_ms(500);
usart_sendstring(str_tmp);
Enter
CR
}
void Send_SMS(char *text)
{
CMGF_1();
Delay_ms(500);
str_tmp[0]='\0';
Delay_ms(100);
strcpy(str_tmp,"AT+CMGS=");
Delay_ms(500);
usart_sendstring(str_tmp);
GIM
str_tmp[0]='\0';
Delay_ms(100);
strcpy(str_tmp,"+989058316399");
Delay_ms(500);
usart_sendstring(str_tmp);
GIM
Enter
CR
Delay_ms(500);
usart_sendstring(text);
Enter
CR
str_tmp[0]='\0';
Delay_ms(500);
SUB
Delay_ms(1000);
del_All_SMS();
}
int main()
{
SystemInit();
SysTick_Config(SystemCoreClock/1000); // setup systick timer for 1ms interrupts
usart_init();
CMGF_1();
del_All_SMS();
GGNSPWR();
Delay_ms(250);
CGNSINF();
while (1)
{
char* u;
usart_getstring(str_tmp2);
u=strstr(str_tmp2,"+CGNSINF:");
if (u){
Send_SMS(u);
}
}
}
