[details=Summary]Hello,
I was occupied with this all day, and i cant seem to figure out the problem. I am using a EVK-N2 with SARA-N211 chip connected to a MSP430F5529 launchpad.I have connected the two devices with 3 wires (TX, RX and GND). My program works as follows:
I enter AT command in the terminal on my PC, which is conected via UART1 with my microcontroler.
Microcontroller passes the command to SARA via UART0.
SARA processes the info and responds via UART0.
Microcontroller passes the response to PC via UART1.
Now, to test this i have entered commands in m-center and saw that the response is written on the terminal on my PC as well. But when i want to send a command to SARA there is no answer. I have debugged the program and UART1 communication is ok. Also UART0 sends data to SARA in the correct way. But it seems that something is wrong.
UART settings for both UARTs are ok. As i understand the AT commands end with a or 0x0D. I have also made voltage divider for TX because high voltage for SARA is 1.8V and for MSP430 is 3.3V.
This is the program i have used:
#include <msp430.h>
#include <stdint.h>
#include <string.h>
/** buffer where received data is placed */
volatile uint8_t data_buffer[10][50] = {0};
volatile uint8_t message[50] = {0};
/** counter used during receive and transmit */
volatile int8_t data_cnt = 0;
volatile int8_t message_cnt = 0;
volatile int8_t data_length = 0;
/**
* flag used to signal that receive phase is done and transmit phase can begin
*/
volatile uint8_t receive_done = 0;
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P4SEL |= BIT5 | BIT4; // select P4.4 and P4.5 for USCI1
P3SEL |= BIT3 | BIT4; // select P3.4 and P3.3 for USCI0
// ***************initialize USCI1********************
UCA1CTL1 |= UCSWRST; // put USCI in reset
UCA1CTL0 = 0;
UCA1CTL1 = UCSSEL__SMCLK | UCSWRST; // use SMCLK and keep in software reset
UCA1BRW = 9; // BR = 9 and
UCA1MCTL = UCBRS_1; // BRS = 1 for 115200 bps
UCA1CTL1 &= ~UCSWRST; // release reset
UCA1IFG = 0; // clear IFG
UCA1IE |= UCRXIE | UCTXIE; // enable rx and tx interrupts
// ****************initialize USCI0*******************
UCA0CTL1 |= UCSWRST; // put USCI in reset
UCA0CTL0 = 0;
UCA0CTL1 = UCSSEL__ACLK | UCSWRST; // use ACLK and keep in software reset
UCA0BRW = 3; // BR = 3 and
UCA0MCTL = UCBRS_3; // BRS = 3 for 9600 bps
UCA0CTL1 &= ~UCSWRST; // release reset
UCA0IFG = 0; // clear IFG
UCA0IE |= UCRXIE | UCTXIE; // enable rx and tx interrupts
__enable_interrupt(); // GIE
while (1)
{
if (receive_done == 1){
data_cnt = 0;
UCA0TXBUF = data_buffer[0][data_cnt];
receive_done = 0;
}
if (message_cnt > 0 && data_buffer[message_cnt-1][0] == 'O' || data_buffer[message_cnt-1][0] == 'E'){
memcpy(message, data_buffer[1], 50);
message_cnt = 0;
data_cnt = 0;
UCA1TXBUF = data_buffer[message_cnt][data_cnt];
}
}
}
void __attribute__ ((interrupt(USCI_A1_VECTOR))) UART1ISR (void)
{
switch (UCA1IV)
{
case 0:
break;
case 2: // RXIFG
data_buffer[message_cnt][data_cnt] = UCA1RXBUF;
if (data_buffer[0][data_cnt] == 0x0D) {
data_buffer[0][data_cnt] = 0x0D;
receive_done = 1;
}
else {
data_cnt++;
}
break;
case 4: // TXIFG
data_cnt++;
if (data_buffer[message_cnt][data_cnt-1] != 0x0A) {
UCA1TXBUF = data_buffer[message_cnt][data_cnt]; // send current byte
}
else {
data_cnt = 0;
if (data_buffer[message_cnt][0] != 'O' && data_buffer[message_cnt][0] != 'E') {
message_cnt++;
UCA1TXBUF = data_buffer[message_cnt][data_cnt];
}
else {
message_cnt = 0;
}
}
break;
}
}
void __attribute__ ((interrupt(USCI_A0_VECTOR))) UART0ISR (void)
{
switch (UCA0IV)
{
case 0:
break;
case 2: // RXIFG
data_buffer[message_cnt][data_cnt] = UCA0RXBUF;
if (data_buffer[message_cnt][data_cnt] == 0x0A) {
message_cnt++;
data_cnt = 0;
}
else {
data_cnt++;
}
break;
case 4: // TXIFG
data_cnt++;
if (data_buffer[0][data_cnt-1] != 0x0D) {
UCA0TXBUF = data_buffer[0][data_cnt]; // send current byte
}
else {
data_cnt = 0;
}
break;
}
}
Any help will be appreciated.[/details]
Solved