msp430f248与sim900串口连接,无法通信的问题
电路的连接关系很简单MSP430 SIM900
RXD ------ TXD (两者之间加了一个10K上拉电阻到3.3V)
TXD------- RXD (两者之间串了一个22欧姆电阻)
现在的问题是:sim900接收msp430的AT命令,没有反应;sim900给430发的数据,后者接收正常(用PC机接一个232转换板给SIM900发AT命令)
后来我用STM32代替msp430,就替换了收发两根线,别的地方没动,就一切OK了。因为本人是头次用430,所以经验不足,忘高手指点。以下是配置程序,我用的是uart1。还有就是430发的AT命令通过232转换连到PC后,用串口调试助手能观察到。
#include"msp430x24x.h"
void Init_uart1(void) //TX or RX between the GSM , P3.6 and P3.7
{
UCA1CTL0 = 0x0;
UCA1CTL1 |= UCSSEL_1; // CLK = ACLK
UCA1BR0 = 0x03; // 32kHz/9600 = 3.41
UCA1BR1 = 0x00; //
UCA1MCTL = UCBRS1 + UCBRS0; // Modulation UCBRSx = 3
UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UC1IE |= UCA1RXIE; // Enable USCI_A1 RX interrupt
}
void Uart1_SendChar(unsigned char chr)
{
while (!(UC1IFG&UCA1TXIFG));
UCA1TXBUF = chr;
}
void Uart1_SendString(unsigned char *ptr)
{
while(*ptr)
{
Uart1_SendChar(*ptr++);// 发送数据
}
}
主程序调用Uart1_SendString("AT\r"); Uart1的两个单片机IO口没有设置成Uart使用,还是普通IO口PXSEL 设置一下 回楼上,设置过了P3SEL = 0xF0; UART0也用了,接的是GPS 我做过EM310和GTM900,如果确认串口没有问题的话,问题应该出在模块初始化及模块硬件启动上。好好对比一下STM32代码,如果STM32代码通过,问题应该出在延时上。 恩 有道理 我再试试 应该是时钟问题,之前我系统时钟用的是DCO_1MHz,而串口时钟用的是32.768khz,现在我统一都用DCO_1mhz,两者通信正常了,先把代码贴出来,因为只是刚刚调试,代码还不是很完善,仅当参考。
void Init_uart1(void) //TX or RX between the GSM , P3.6 and P3.7
{
/*UCA1CTL0 = 0x0;
UCA1CTL1 |= UCSSEL_1; // CLK = ACLK
UCA1BR0 = 0x03; // 32kHz/9600 = 3.41
UCA1BR1 = 0x00; //
UCA1MCTL = UCBRS1 + UCBRS0; // Modulation UCBRSx = 3*/
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
{
while(1); // If calibration constants erased
// do not load, trap CPU!!
}
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
UCA1CTL1 |= UCSSEL_2; // SMCLK
UCA1BR0 = 104; // 1MHz 9600; (104)decimal = 0x068h
UCA1BR1 = 0; // 1MHz 9600
UCA1MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UC1IE |= UCA1RXIE; // Enable USCI_A1 RX interrupt
// UC1IE |= UCA1TXIE; // Enable USCI_A1 TX interrupt 实际调试串口时,再将此命令打开
// _EINT();
}
void Set_DCO(unsigned int Delta) // Set DCO to selected frequency
{
unsigned int Compare, Oldcapture = 0;
BCSCTL1 |= DIVA_3; // ACLK = LFXT1CLK/8
TACCTL2 = CM_1 + CCIS_1 + CAP; // CAP, ACLK
TACTL = TASSEL_2 + MC_2 + TACLR; // SMCLK, cont-mode, clear
while (1)
{
while (!(CCIFG & TACCTL2)); // Wait until capture occured
TACCTL2 &= ~CCIFG; // Capture occured, clear flag
Compare = TACCR2; // Get current captured SMCLK
Compare = Compare - Oldcapture; // SMCLK difference
Oldcapture = TACCR2; // Save current captured SMCLK
if (Delta == Compare)
break; // If equal, leave "while(1)"
else if (Delta < Compare)
{
DCOCTL--; // DCO is too fast, slow it down
if (DCOCTL == 0xFF) // Did DCO roll under?
if (BCSCTL1 & 0x0f)
BCSCTL1--; // Select lower RSEL
}
else
{
DCOCTL++; // DCO is too slow, speed it up
if (DCOCTL == 0x00) // Did DCO roll over?
if ((BCSCTL1 & 0x0f) != 0x0f)
BCSCTL1++; // Sel higher RSEL
}
}
TACCTL2 = 0; // Stop TACCR2
TACTL = 0; // Stop Timer_A
BCSCTL1 &= ~DIVA_3; // ACLK = LFXT1CLK
}
void main(void)
{
unsigned char i;
//_DINT(); //关闭所有中断
CLR_DOG; // 禁止看门狗定时器
//SET_DOG; // 开启看门狗定时器
P1DIR = 0xFF; // All P1.x outputs
P1OUT = 0; // All P1.x reset
P2DIR = 0xFF; // All P2.x outputs
P2OUT = 0; // All P2.x reset
P3SEL = 0xF0; // P3.4,5 = USCI_A0 TXD/RXD
P3DIR = 0xFF; // All P3.x outputs
P3OUT = 0; // All P3.x reset
P4DIR = 0xFF; // All P4.x outputs
P4OUT = 0; // All P4.x reset
P5DIR = 0xFF; // All P5.x outputs
P5OUT = 0; // All P5.x reset
P6DIR = 0xFF; // All P6.x outputs
P6OUT = 0; // All P6.x reset
Set_DCO(DELTA_1MHZ); // Set DCO and obtain constants
// Init_uart0();
Init_uart1();
/******************** make Three LEDs flash 5 *********************/
for ( i = 0; i<10 ; i++ )
{
delay(10);
P1OUT = ~ P1OUT;
}
P1OUT = 0xFF;
/******************** Final Trun off after flash 5*****************/
Timer0_Init(); //50ms中断
//Delay_ms(1000); //等待 GSM模块上电后的硬件初始化。
_EINT(); //总中断打开
// GPS_Init();
sim900_init();
//__bis_SR_register(LPM3_bits + GIE); // Enter LPM3, interrupts enabled
for(;;)
{
Uart1_SendString("AT\r");
for ( i = 0; i<10 ; i++ )
{
delay(100);
}
}
} 为什么要一个上拉一个串电阻啊?而且是
MSP430 SIM900
RXD ------TXD (两者之间加了10K上拉电阻到3.3V)
TXD-------RXD (两者之间串了一个22欧姆电阻)
SIM900 的手册中说的电压范围是3.4~4.5V,你用的是多少?
假如比3.3高,会不会是信号电平的问题?
我觉得上拉和串电阻应该换换
因为SIM900 比MSP430信号电平高的话,
应该串个电阻在SIM900 TXD到MSP430RXD 以保护430的IO
而MSP430 TXD到SIM900RXD 应当加电阻上拉到SIM900的电源。以提高msp430输出高电平的电压值。
MSP430 SIM900
RXD <------TXD (两者之间串了一个22欧姆电阻)
TXD ------>RXD (两者之间加了10K上拉电阻到4.2V)
这样会不会更可靠些 谢谢了,兄弟{:handshake:} 你好 我也遇到了相同的问题正在纠结于硬件的连接希望大神能给指点一二 不胜感激 QQ 779742846
页:
[1]