MKãUARTçµç±ã§ã³ã³ãã¥ãŒã¿ãŒã«æ¥ç¶ããŠã¿ãŸãããã ãããè¡ãã«ã¯ãPL2303ãããã«åºã¥ããåçŽãªUSB-UART TTLïŒ3.3VïŒïŒMKã3.3 Vã¬ãã«ã§ããããšãå¿ããªãã§ãã ããïŒã³ã³ããŒã¿ãŒã䜿çšããŸãã
STM32ã«ã¯3ã€ã®UARTã€ã³ã¿ãŒãã§ã€ã¹ããããŸãã 䜿çšããåã«ãMKã§ã·ãªã¢ã«ãã©ã³ã·ãŒããŒãæ§æããå¿ èŠããããŸãã ãããè¡ãã«ã¯ã次ã®ã³ãã³ãã䜿çšããŸãã
UART_Init(baud_rate);
ãã®ã³ãã³ãã¯ãæšæºãã©ã¡ãŒã¿ãŒïŒããŒããŠã§ã¢ããªãã£ãªãã®8ããŒã¿ãããïŒã§baud_rateé床ïŒããšãã°ã9600ãŸãã¯19200 kbsïŒã§UARTãèµ·åããŸãã
éæšæºã¢ãŒãã§UARTãèµ·åããå¿ èŠãããå Žåã¯ã次ã䜿çšããŸãã
UARTx_Init_Advanced(baud_rate, data_bits, parity, stop_bits);
ããã«ïŒ
- baud_rate-ããŒãé床ã
- data_bits-ããŒã¿ãããæ°ãæ§é äœ_UART_5_BIT_DATAã_UART_6_BIT_DATAã_UART_7_BIT_DATAã_UART_8_BIT_DATAã䜿çšã§ããŸãã
- ããªã㣠-ããªãã£ïŒ _UART_NOPARITYã_UART_EVENPARITYã_UART_ODDPARITY ïŒããããããããªãã£ãªããããªãã£ãå¥æ°ããªãã£ã
- stop_bits-ã¹ããããããã®æ°ïŒ _UART_ONE_STOPBITã_UART_TWO_STOPBITS ïŒ-ãããã1ãŸãã¯2ã¹ããããããã
ããŒã¿ãã€ããUARTã«è»¢éããã«ã¯ã次ã䜿çšããŸãã
UARTx_Write(unsigned int _data); UARTx_Write(char _data);
ãŸãã¯ãããŒã¿ã®é åã®å ŽåïŒããã¹ããŸãã¯å€ã®ã»ããã«é¢ä¿ãªãïŒãé¢æ°ã«æž¡ããŸãã
UARTx_Write_Text(char * UART_text);
é åãžã®ãã€ã³ã¿ãŒã䜿çšããŸãã
ç°¡åãªããã°ã©ã ãæžããŸãããïŒ
char ourtext[] = "Hellow world"; char *txt_pnt; void main() { UART1_INIT (19200); delay_ms (5); // 5 txt_pnt = &ourtext; UART1_Write_Text(txt_pnt); while (1) { } {
RX STM32ãTXã³ã³ããŒã¿ãŒã«æ¥ç¶ãã TX STM32ãRXã³ã³ããŒã¿ãŒã«æ¥ç¶ããã³ã³ãã¥ãŒã¿ãŒã®USBããŒãã«æ¿å ¥ããŸãã ã¿ãŒããã«ããã°ã©ã ãéãïŒ PuTTYã䜿çšïŒãã·ãªã¢ã«ã¢ãŒããããŒãé床ïŒ19200 kbsãªã©ïŒããã³USB-TTLã³ã³ããŒã¿ãŒã®æ¥ç¶æã«è¡šç€ºãããCOMããŒããéžæããŸãïŒããã€ã¹ãããŒãžã£ãŒã®[COMããã³LPTããŒã]ãã©ã³ãã§ç¢ºèªã§ããŸãïŒã OPENãã ã¿ãŒããã«ãŠã£ã³ããŠã«ããã¹ãã衚瀺ãããŸãã
æ°ãã€ãã®ããŒã¿ãé£ç¶ããŠéä¿¡ããããšã«ãããåã®ããŒã¿ã®éä¿¡ãçµäºãããã©ãããå¶åŸ¡ããå¿ èŠããããŸãã åUARTã«ã¯ç¬èªã®ã¹ããŒã¿ã¹ã¬ãžã¹ã¿ããããŸãã
USART1_SR ã USART1_SRbits.TCãããã¯è»¢éã®çµäºãæ åœãã UARTx_Write_TextïŒchar * UART_textïŒé¢æ°èªäœã¯ã次ã®ãã€ããéä¿¡ããåã«ãåã®ãã€ãã®è»¢éã®å®äºãå¶åŸ¡ããŸãã
UARTãã€ã¯ãã³ã³ãããŒã©ãŒããããŒã¿ãèªã¿åãã«ã¯ã次ã®é¢æ°ã䜿çšããŸãã
char UARTx_READ()
UARTã®ãããã¡ã«åä¿¡ãã€ããããããšãç¥ãããã«ã次ã®é¢æ°ã䜿çšããŸãã
åä¿¡ãããã€ãããããã¡ã«ããå Žåã¯1ãè¿ãããªãå Žåã¯0ãè¿ããŸãã ãã®å Žåãã³ã³ãããŒã©ãŒUARTãäœããåãå ¥ãããã©ãããåžžã«ç£èŠããå¿ èŠããããŸãã ããšãã°ãããŒãã®LEDãç¹ç¯ããæåãAãïŒASCIIã³ãŒã65ïŒãåãåã£ããšãã«è©ŠããŠã¿ãŸããããUART_Data_Ready()
void main() { GPIO_Digital_Output(&GPIOb_BASE, _GPIO_PINMASK_1); UART1_INIT (19200); delay_ms (5); UART1_Write_Text("WAIT CHAR A"); while(1) { if (UART1_Data_Ready()) // UART { if (UART1_READ()== 65) // 65 { GPIOb_ODR.b1 = 1; // } } } }
åžžã«UARTã¬ãžã¹ã¿ã®ã¹ããŒã¿ã¹ãããŒãªã³ã°ããããšã§MKãå æããªãããã«ãå²ã蟌ã¿ã䜿çšã§ããŸãïŒããã³äœ¿çšããå¿ èŠããããŸãïŒã 次ã®ãã€ããåä¿¡ãããšãUARTããããŒããŠã§ã¢å²ã蟌ã¿ãåŒã³åºãããã·ãªã¢ã«ã€ã³ã¿ãŒãã§ã€ã¹ã§åä¿¡ããããŒã¿ãåŠçã§ããŸãã ãRX UARTãã€ãã³ãã§å²ã蟌ã¿ãæå¹ã«ããã«ã¯ã䜿çšããUARTã¢ãžã¥ãŒã«ã®ã¬ãžã¹ã¿CR1ã®RXNEIEãããã«è«çå€1ãæžã蟌ãå¿ èŠããããŸãã
UART1_init (19200); NVIC_IntEnable(IVT_INT_USART1); // IVT_INT_USART1 EnableInterrupts(); // USART1_CR1bits.RXNEIE = 1; // delay_ms (5);
ã¿ã€ããŒãšåæ§ã«ãå²ã蟌ã¿ãçºçãããšããµãã«ãŒãã³ãåŒã³åºãããŸãã
void our_int() iv IVT_INT_USART1 { if (UART1_READ()== 65) GPIOb_ODR.b1 = 1; // A = if (UART1_READ()== 66) GPIOb_ODR.b1 = 0; // B = }
UARTã䜿çšãããšãMKãã³ã³ãã¥ãŒã¿ãŒã ãã§ãªããå€ãã®åšèŸºæ©åšã«ãæ¥ç¶ã§ããŸãã ããšãã°ãåºãå©çšå¯èœãªGSMã¢ãžã¥ãŒã«SIM800LãèããŠã¿ãŸãããã ãã®ã¢ãžã¥ãŒã«ã¯ãã§ã«å°ããªããŒãã«ã¯ãã ä»ããããŠããŸãã ãã®ãããªå®äŸ¡ã¯äžåœã§æ³šæããããšãã§ããŸãã ã¢ãžã¥ãŒã«ã®æäœã«å¿ èŠãªãã¹ãŠã®ä¿¡å·ã¯ããã®ããŒãã®ãã³ã«åºåãããŸããããã«ãããŒãã«ã¯SIMã«ãŒãçšã®ãã«ããŒããããŸãã
å¯äžäžäŸ¿ãªã®ã¯ããã®ããŒãã«3.7ã4.2 Vã®é»å§ãäŸçµŠããå¿ èŠããããããå€éšãªããŠã é»æ± ãæ¥ç¶ãããã4.1 Vã®åºåé»å§ã«å€æããå¿ èŠãããããšã§ãã ãç§ã¯ãç¹å®ã®åé¡ã§ã¯ãªããšæããŸãã
RXã¢ãžã¥ãŒã«ãTX MKã«ããŸããã®éãåæ§ã§ããããšãå¿ããã«ãã¢ãžã¥ãŒã«ãMKã«æ¥ç¶ããŸãã Mapleããã¢ãžã¥ãŒã«ã®å Žåã RXã26ãã³ïŒPA9 / UART1TXïŒã«ãTXã25ïŒPA10 / UART1RXïŒã«æ¥ç¶ããŸãã
ã¢ãžã¥ãŒã«ãšéä¿¡ããããã«ãããããATã³ãã³ãã䜿çšãããŸãã ããã¯ãã¢ãã ãç解ãããããã«å¿ããŠç¹å®ã®ã¢ã¯ã·ã§ã³ãå®è¡ãã端æ«ã³ãã³ãã®ã»ããã§ãã ããŒã¿ã·ãŒãã®ã¢ãžã¥ãŒã«ã®ã³ãã³ãã«æ £ããããšãã§ããŸããããã«ããã®ã¢ãžã¥ãŒã«ã§ã®äœæ¥ãããæãããŠããè¯ãèšäºããããŸãã
2ã€ã®UARTãã€ã¯ãã³ã³ãããŒã©ãŒãMK-GSMéä¿¡çšã®UART1ãšMKéä¿¡çšã®UART3ïŒã³ã³ãã¥ãŒã¿ãŒç«¯æ«ïŒã䜿çšããŸãã
UARTãåæåãã
void main() { UART1_init (19200); // UART UART3_init (19200); // UART GSM NVIC_IntEnable(IVT_INT_USART1); // GSM USART1_CR1bits.RXNEIE = 1; EnableInterrupts(); delay_ms(200); while (1) { } }
ç§ãã¡ã®ããã°ã©ã ã¯æ¯èŒçå€æ°ã®é¢æ°ãå¿ èŠãšããã®ã§ãããããå¥ã®Sãã¡ã€ã«ã«è»¢éããŸãã ãããè¡ãã«ã¯ãMicrocã§Ctrl + NãæŒããŠããããžã§ã¯ãã«å¥ã®ãã¡ã€ã«ãäœæããŸãïŒäŸïŒãGSM_SIM800L.ãïŒã ã³ã³ãã€ã©ãããã€ãã®é¢æ°ãå¥ã®ãã¡ã€ã«ã§æ€çŽ¢ããå¿ èŠãããããšãç解ããããã«ãã¡ã€ã³s-ãââã¡ã€ã«ã®å é ã«è¡ãè¿œå ããŸãïŒåãæ¹æ³ã§ã©ã€ãã©ãªãæ¥ç¶ããããšãã§ããŸãïŒã
#include "GSM_SIM800L."
ãŸãããã¡ã€ã«ãGSM_SIM800L.sãã«ãATã¢ãžã¥ãŒã«ã«ã³ãã³ããéä¿¡ããATã¢ãžã¥ãŒã«ããå¿çãåä¿¡ããé¢æ°ãäœæããŸãã
static char GSM_TEMP[256]; // GSM unsigned short com_status; // 0 - , 1 - , 2 - ( ) unsigned short com_mode = 0; 0 - , 1 - void Clear_GSM_Bufer () // GSM { unsigned int cnt; for (cnt=0; cnt<256; cnt++) GSM_TEMP[cnt] = 0; cntas = 0; } short int gsm_send_at (char *at_cmd) // AT , MicroC { unsigned int brk; // Clear_GSM_Bufer (); // com_status = 2; // " " com_mode = 0; // UART1_Write_Text (at_cmd); // AT - while (com_status == 2 && brk < 50000) // com_status 1 0 { brk++; delay_us(2); } com_mode = 1; // , return com_status; // } void gsm_read() iv IVT_INT_USART1 { GSM_TEMP[cntas] = UART1_READ(); // UART GSM_TEMP if (cntas> 255) cntas = 0; else cntas++; // if (com_mode == 0) // { if (strstr(GSM_TEMP, "OK\r\n") != 0) com_status = 1; // - com_status = 1 if (strstr(GSM_TEMP, "ERROR\r\n") != 0) com_status = 0; //Error - com_status = 0 } }
MicroCã§ã¯ãæååã¯ãæååã®çµãããè¡šãå€00ïŒNULLïŒã§çµããcharæåã®é åã§ãã é¢æ°ãžã®åŒæ°ãšããŠã®æååã¯ã charåãžã®ãã€ã³ã¿ãŒã«ãã£ãŠæå®ãããŸãïŒããšãã°ã char * nasha_stroka ïŒã MicroCã¯ãæšæºã®C_String.hã©ã€ãã©ãªã®æ©èœããµããŒãããŠããŸãã ããšãã°ãäžèšã§äœ¿çšããé¢æ°
char *strstr(char *s1, char *s2);
ãã®é¢æ°ã¯ãã¹ããªã³ã°* s1å ã®* s2ãã€ã³ã¿ãŒã§æå®ããããµãã¹ããªã³ã°ãæ€çŽ¢ããŸãã é¢æ°ã¯ãèŠã€ãã£ãéšåæåå* s2ãžã®ãã€ã³ã¿ãŒãè¿ããŸãã ïŒå®éã«ã¯ãæåå* s1ã®å é * s2ããæ«å°ŸïŒ NULLæåïŒãŸã§ã®æååãè¿ããŸã ïŒã ãµãã¹ããªã³ã°* s2ãèŠã€ãããªãå Žåãé¢æ°ã¯NULLãè¿ããŸã ã Cã®ããã©ã«ãã§ã¯ãååã§é åãæž¡ãããšã¯ãé åã®å é ãžã®ãã€ã³ã¿ãŒã§ãã ç¹å®ã®èŠçŽ ã®é åcãæž¡ãå¿ èŠãããå Žåã¯ãïŒ ïŒarray_name [ind] ïŒã䜿çšããŸãã
å§ããã«ã¯ãã¢ãžã¥ãŒã«ã«åçŽãªã³ãã³ããAT \ rããäžããå¿ èŠããããŸã-ã¢ãžã¥ãŒã«ã¯ãOK \ r \ nããšçããUARTã®é床ã調æŽããå¿ èŠããããŸãã ATã³ãã³ãã¯ãæ¹è¡æå"\ r"ã§çµäºããŸãã ã³ãã³ãã«å¯Ÿããã¢ãžã¥ãŒã«ã®å¿çã¯è€æ°ã®è¡ã§æ§æã§ããåžžã«ãOK \ r \ nããŸãã¯ãERROR \ r \ nãã§çµãããŸãã çä¿¡ã³ãŒã«ãSMSã¡ãã»ãŒãžãªã©ã®ã¢ãžã¥ãŒã«ã¡ãã»ãŒãžã¯åžžã«"\ r \ n"ã§çµäºããéåžžã¯æåŸã®è¡ã®ã¿ãåèã«ãªããšããäºå®ã«ãããç掻ãç°¡çŽ åãããŠããŸãã ãã®ãããªè¡ã®åä¿¡ãç§ã¯éåæå¿çãåŒã³åºããŸãïŒå®å šã«æ£ããããã§ã¯ãããŸãããããããããŠãã ããïŒã
ã¢ãžã¥ãŒã«ã®æ§æã«å¿ èŠãªããã€ãã®ã³ãã³ããå®è¡ããŸãããã ç°¡åã«ããããã«ãã¢ãžã¥ãŒã«ã®å¿çãå¶åŸ¡ããŸããããåã³ãã³ãã®å®è¡äžã«ç¶æ ãçãããã©ããã確èªããããšã¯é£ãããããŸããã
- ãATE0 \ rã -ãšã³ãŒããªãã«ããŸãïŒã³ãã³ããUARTaåºåã«ç¹°ãè¿ããŸãïŒ
- "AT + GMM \ r" -ã¢ãžã¥ãŒã«ã®ååãè¿ããŸã
- ãAT + CMGD = 1.4 \ rã -ã¢ãžã¥ãŒã«ã«ä¿åãããŠãããã¹ãŠã®SMSãåé€ããŸã
- ãAT + CMGF = 1 \ rã-SMSã® ASCIIã¢ãŒãããªã³ã«ããŸããããããªããšãUnicodeæåã§èªã¿åãã®ãé£ãããªããŸãã
- ãAT + DDET = 1ã-DTMFã¢ãžã¥ãŒã«ã«ããã³ãã³ãã®èªèããªã³ã«ããŸã
gsm_send_at ("AT\r"); gsm_send_at ("ATE0\r"); gsm_send_at ("AT+CMGD=1,4\r"); gsm_send_at ("AT+CMGF=1\r"); gsm_send_at ("AT+DDET=1\r");
ã¢ãžã¥ãŒã«ã®å¿çãè¿ãå¥ã®é¢æ°ãäœæããŸãïŒèŠæ±ã®ã¹ããŒã¿ã¹ã ãã§ãªããå¿ èŠãªãã®ã§ããã¢ãžã¥ãŒã«äžã®ããŒã¿ã¯ãã»ãšãã©ã®å Žåãè¡ã®äžéšã2蟺ããå¶éã§ããå¿çæ©èœã«é¢ããæ£èŠè¡šçŸã䜿çšããŠãATã³ãã³ããžã®å¿çãèšè¿°ããŸãæ¢ç¥ã®æåïŒã
char *gsm_at_parse (char *at_cmd, char *beg_str, char *end_str) // *at_cmd = // *beg_str = // *beg_str = { char *tempchar; if (gsm_send_at (at_cmd) == 1) // { tempchar = strstr (GSM_TEMP, beg_str); // beg_str tempchar = tempchar + strlen(beg_str); *(strstr (tempchar, end_str)) = 0; // NULL end_str return tempchar; } }
ããšãã°ã ãAT + GMM \ r \ nãã¯ã ã\ r \ n SIM_800L \ r \ n \ r \ nOK \ r \ nããšãã圢åŒã§ã¢ãžã¥ãŒã«åãè¿ããŸãã æåã®ã\ r \ nããšæåŸã®ã\ r \ n \ r \ nOK \ r \ nãã ããã€ããªãã
UART3_Write_Text (gsm_at_parse("AT+GMM\r", "\r\n", "\r\n\r\nOK\r\n")); \\ UART3 ( , ) UART3_Write_Text ("\r\n"); UART3_Write_Text (gsm_at_parse("AT+CCLK?\r", ",", "+")); \\ UART3_Write_Text ("\r\n"); UART3_Write_Text (gsm_at_parse("AT+CSPN?\r", ": \"", "\""); \\ GSM. UART3_Write_Text ("\r\n");
ã¢ãžã¥ãŒã«ã®ATã³ãã³ãã«ã¯ãã³ãã³ããAT + CREGïŒ\ RãããããŸãã ãã®ã³ãã³ãã¯ããããã¯ãŒã¯ãžã®ç»é²ã«é¢ããã¢ãžã¥ãŒã«ã®ã¹ããŒã¿ã¹ãè¿ããŸãã ãã¹ãŠãæ£åžžã§ãã¢ãžã¥ãŒã«ãç»é²ãããŠããå Žåãå¿çã¯æ¬¡ã®ããã«ãªããŸãã ã\ r \ n + CREGïŒ0,1 \ r \ n \ r \ n \ OK \ r \ nã 0,0-ã¢ãžã¥ãŒã«ã¯ç»é²ãããŠãããããããã¯ãŒã¯æ€çŽ¢ã¯ãããŸããïŒããšãã°ãSIMã«ãŒããæ¿å ¥ãããŠããªãïŒã 0.2-ã¢ãžã¥ãŒã«ã¯ç»é²ãããŠããŸããããããã¯ãŒã¯ãæ€çŽ¢ãããŠããŸãã ã¢ãžã¥ãŒã«ã®ãããã¯ãŒã¯ã¹ããŒã¿ã¹ããã§ãã¯ããé¢æ°ãäœæããããã«GSMãããã¯ãŒã¯ã®ä¿¡å·ã¬ãã«ãè¿ããŸãïŒãã®ããã«ATã³ãã³ããAT + CSQ \ rãããããŸã ïŒã
short int gsm_net_status () { char *tempchar[7]; // int sgr; // dBi if ( gsm_send_at("AT+CREG?\r") == 1) // { if (strstr(GSM_TEMP, "0,1")) // - "+CREG: 0,1" { tempchar = GSM_AT_PARSE ("AT+CSQ\r",": ","," ); // , +CSQ: 17,0, : , sgr = atoi(tempchar); // sgr = -115 + (sgr * 2); // dBi return sgr; // } } return 0; // 0 - . }
ããã§ã¢ãžã¥ãŒã«ãæ©èœããŸããã 圌ã«é»è©±ãããšã圌ã¯æ¬¡ã®ãããªè¡ãçºè¡ããŸã
"\ r \ n RING \ r \ n + CLIPïŒ" + 380XXXXXXXX "ã145ã" ",," "ã0 \ r \ n" ã çä¿¡SMSã®å Žåãå¿çã¯"\ r \ n + CMTIïŒ" SM "ã10 \ r \ n"ã«ãªããŸããããã§ã10ã¯SMSã10çªã®ã¡ã¢ãªã«æ ŒçŽãããããšãæå³ããŸãã å²ã蟌ã¿ãã³ãã©ã§ããããåãå ¥ããŠåŠçããŸãã ç§ã¯ãç§ãæãå¿ èŠãšããçãã®èªèãæžããŸããã ååãšããŠããããã©ã®ããã«è¡ããããã¯ã以äžã®ã³ãŒãããæããã§ãã
char *eol // , "\r\n" char callingnumber[14]; // , 13 NULL char last_sms[4]; // char dtmf_in[2]; // DTMF unsigned short callnow; // unsigned short active_call; // unsigned short sms; // void gsm_read() iv IVT_INT_USART1 { GSM_TEMP[cntas] = UART1_READ(); if (cntas> 255) cntas = 0; else cntas++; if (com_mode == 0) { if (strstr(GSM_TEMP, "OK\r\n") != 0) com_status = 1; if (strstr(GSM_TEMP, "ERROR\r\n") != 0) com_status = 0; } // if (com_mode == 1) { if (cntas> 2) eol = strstr(&GSM_TEMP[2], "\r\n"); else eol = 0; // if (eol != 0) // { if (strstr(&GSM_TEMP, "+CLIP") != 0) // "+CLIP" { callnow=1; // temp = strstr(GSM_TEMP, "\"+"); // + - strncpy (callingnumber, temp+1, 13); // callingnumber[] , 13 } if (strstr(&GSM_TEMP, "CARRIER") != 0) // "NO CARRIER" { *callingnumber=0; // ( NULL ) callnow=0; // active_call=0; } if (strstr(&GSM_TEMP, "DTMF") != 0) { temp = strstr(GSM_TEMP, " "); //SIM800 DTMF , DTMF . strncpy(dtmf_in,temp+1,1); // dtmf_in[] } if (strstr(GSM_TEMP, "CMTI")!=0) // { temp = strstr(GSM_TEMP, ","); // ",", strncpy (last_sms, temp + 1, eol - (temp + 1)); // last_sms[] sms=1; // } Clear_GSM_Bufer (); // } } }
ããã°ã©ã ã«ãŒãå ã®callnowå€æ°ã®å€ãç£èŠããããšã«ãããçä¿¡åŒã³åºãã«ã€ããŠèª¿ã¹ãããšãã§ããŸãã ã³ãã³ããATA \ rãã§é»è©±ãåããã³ãŒã«ãããããããŸã- ãATH0 \ rã ã
har *nashomer[14] = "+380931234567" if (callnow == 1) { if (strcmp(&callingnumber, "nashomer")==0) // strcmp (*s1, *s2) - 2 , 0 s1 = s2 { gsm_send_at ("ATA\r"); // AT " " active_call = 1; // . } else { gsm_send_at ("ATH0\r"); // AT " " callnow = 0; // } }
åæ§ã«ã smså€æ°ã®å€ãå¶åŸ¡ããŠãçä¿¡SMSã¡ãã»ãŒãžã«ã€ããŠåŠç¿ããŸãã ã³ãã³ããAT + CMGR = 2 \ rãã§èªã¿åãããšãã§ããŸããããã§ãN = SMSã¡ãã»ãŒãžã®æ°ã§ãã å¿çãšããŠãã¢ãžã¥ãŒã«ã¯ã\ r \ n + CMGRïŒãã®ãããªæååãè¿ããŸããRECREAD "ã" + 380XXXXXXXX "ã" "ã" 17/02 / 1,11ïŒ57ïŒ46 + 2 "\ r \ n hellow habrahabr \ r \ n \ r \ nOK \ r \ n "ã ãã®è¡ã解æããã«ã¯ãé¢æ°ãäœæããŸãã
char *gsm_read_sms (char *sms_num, unsigned short int sms_field) // ( ) ( ), //1 - , //2 - , //3 - { char sms_at[30]; short int res_at; strcat (sms_at, "AT+CMGR="); strcat (sms_at, sms_num); strcat (sms_at, "\r"); res_at = gsm_send_at (sms_at); if (res_at == 1 && sms_field == 1) { *(strstr (GSM_TEMP, "\",\"\",\"")) = 0; sms = 0; return strstr(GSM_TEMP, "\"+") + 1; } if (res_at == 1 && sms_field == 2) { *(strstr(strstr(GSM_TEMP, "\",\"\",\"") + 6, "+")) = 0; sms = 0; return strstr(GSM_TEMP, "\",\"\",\"") + 6; } if (res_at == 1 && sms_field == 3) { *(strstr (GSM_TEMP, "\r\n\r\nOK\r\n")) = 0; sms = 0; return strstr(GSM_TEMP, "\"\r\n") + 3; } return 0; // 0 }
äŸïŒ
UART3_Write_Text (gsm_read_sms("5",1)); // 5 UART3_Write_Text (gsm_read_sms("2",3)); // 2
SMSãéä¿¡ããã«ã¯ãATã³ãã³ããAT + CMGS =ã+ 380XXXXXXXX \ r "ã䜿çšããŸãããã®ã³ãã³ãã¯ãæåãè¿ããŸã " \ r \ n> "-å ¥åããæåŸ ç¶ããã®æåŸ ç¶ãã¢ãžã¥ãŒã«ã®å¿çã§ãã£ããã§ããŸãã 100ããªç§ãSMSããã¹ããUARTã«éä¿¡ããŸããUARTã¯ASCIIã³ãŒã26ã®æåã§çµäºããå¿ èŠããããŸã
UART1_Write_Text ("AT+CMGS=\""); UART1_Write_Text (nomer); // UART1_Write_Text ("\"\r"); Delay_ms (100); UART1_Write_Text (text); // UART1_Write (26);
ãã®èšäºã§ã¯ãGSMã¢ãžã¥ãŒã«ãšSTM32 MKã®UARTã€ã³ã¿ãŒãã§ã€ã¹ã®äž¡æ¹ã®æ©èœã®ããäžéšã«ã€ããŠã®ã¿èª¬æããŸãã ããã«ãããããããäžèšã®æ å ±ããã€ã¯ãã³ã³ãããŒã©ã«å®è£ ãããã·ãªã¢ã«ã€ã³ã¿ãŒãã§ãŒã¹ã®åäœãç解ããã®ã«åœ¹ç«ã€ããšãé¡ã£ãŠããŸãã
次ã®èšäºã§ã¯ãI2Cãã¹ãšã¯äœãããã®æäœæ¹æ³ãããã³HD44780ã³ã³ãããŒã©ãŒã«åºã¥ãLCDã€ã³ãžã±ãŒã¿ãŒãããã©ã¬ã«ãã¹ããã³I2C I / Oã©ã€ã³ãšã¯ã¹ãã³ããŒãä»ããŠSTM32ã«æ¥ç¶ããæ¹æ³ã«ã€ããŠèª¬æããŸãã