问题描述
我买了ATMEGA64A-AU,并将USART0连接到FT232RL(USB到串行),而USART1连接到GSM模块。
我使用USART0仅监视目的,并使用USART1与GSM模块进行通信。
我写这些来启用USART:
void USART0_Init( unsigned int ubrr )
{
UBRR0H = (unsigned char) (ubrr >> 8);
UBRR0L = (unsigned char) ubrr;
UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0);
UCSR0C = (1 << USBS0) | (3 << UCSZ00);
}
void USART1_Init( unsigned int ubrr )
{
UBRR1H = (unsigned char) (ubrr >> 8);
UBRR1L = (unsigned char) ubrr;
UCSR1B = (1 << RXEN1) | (1 << TXEN1) | (1 << RXCIE1);
UCSR1C = (1 << USBS1) | (3 << UCSZ01);
}
然后将这些字符放在每个USART中的字符或字符串:
void usart0_putc (char send)
{
while ((UCSR0A & (1 << UDRE0)) == 0) {};
UDR0 = send;
}
void usart0_puts (const char *send)
{
while (*send) {
usart0_putc(*send++);
}
}
void usart1_putc (char send)
{
while ((UCSR1A & (1 << UDRE1)) == 0) {};
UDR1 = send;
}
void usart1_puts (const char *send)
{
while (*send) {
usart1_putc(*send++);
}
}
我使用RX1中断向量来获取模块的响应:
ISR (USART1_RX_vect)
{
data_in[data_count] = UDR1;
if (data_in[data_count] == '\n') {
command_ready = TRUE;
data_count = 0;
} else {
data_count++;
}
}
主要功能:
void main( void )
{
sei();
USART0_Init(MYUBRR);
USART1_Init(MYUBRR);
while(1){
if (command_ready == TRUE) {
memcpy(command_in,data_in,MAXCHAR );
memset(data_in,sizeof(data_in));
usart0_puts(command_in);
command_ready = FALSE;
}
}
}
它显示响应或诸如振铃和消息之类的内容,但问题是,当我通过微控制器向其添加一些命令时,例如将此行放在main while循环之前:
usart1_puts("ATD+545555555555;\r\n");
要呼叫某个号码,整个过程都会停止,不仅不会呼叫该号码,而且还会停止显示模块的响应,所以我认为代码有问题。
任何帮助将不胜感激。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)