本帖最后由 Mcuzone_TKN 于 2020-6-11 09:04 编辑
关键词:AT91SAM7S64 4G模块 EC200S 发送短信 串口 USART AT命令
概述:用AT91SAM7S64 的串口连接4G模块EC200S通过AT命令实现发送短信的功能。
描述:EC200S的电平是1.8v,AT91SAM7S64 的电平是3.3v,所以需要通过电平转换模块连接两者,电平转换模块A端的电平要大于B端的电平。测试时,电话号码写在程序里面。
硬件连接:AT91SAM7S64 的串口(PA6,PA5)通过电平转换模块连接到EC200S的串口。
(附有测试文件)
串口代码: - <div>void uartinit(void)
- {
- *AT91C_PMC_PCER|=0x00000060; //PMCÍâÉèʱÖÓʹÄÜ
- *AT91C_PIOA_PDR|=0x00000060; //Disable I/O,PA5=RXD0,PA6=TXD0
- *AT91C_PIOA_ASR|=0x00000060; //PIO·ÖÅä³ÉUART
- *AT91C_US0_CR=0XAC; //RESET UART
- *AT91C_US0_MR=0X8C0; //8bit,No,1Bit Stop
- *AT91C_US0_IDR=0XF3FFF; //Disable UART Interrupt
- *AT91C_US0_BRGR=26; //BARD RATE:38400(CD=30)
- *AT91C_US0_CR=0X50; //SET UART
- }</div><div>
- unsigned char putchar (unsigned char ch)
- { //Write Character to Serial Port</div><div> if (ch == '\n') { // Check for CR
- while (!((*AT91C_US0_CSR) & AT91C_US_TXRDY)); // Wait for Empty Tx Buffer
- *AT91C_US0_THR = '\r'; // Output CR
- }
- while (!((*AT91C_US0_CSR) & AT91C_US_TXRDY)); // Wait for Empty Tx Buffer
- return (*AT91C_US0_THR = ch); // Transmit Character
- }</div><div>
- void PutStr(unsigned char *str)
- {
- unsigned int i = 0x0;
- while(str[i] != '\0')
- {
- putchar(str[i]);
- i++;
- }
- }
- </div>
复制代码 主函数代码:- int main(void)
- {
- uartinit();
- PutStr("AT+CMGF=1\r");
- PutStr("AT+CMGS=\"此处写目标电话号码\"\r");
- PutStr("\x1A");
- }
复制代码
|