This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430FG6626: MSP430: MSP430FG6626: SN75176A

Part Number: MSP430FG6626
Other Parts Discussed in Thread: SN75176A

Hiii this is Amol Gholap,

i have a question related RS485 communication.here i used the SN75176A IC for communication.i was tried transmitting as well receiving a data from microcontroller through interrupt base, here i observed no issue come during transmitting dada at buad rate 9600. but during the receiving time code was stuck inside the "  __bis_SR_register(LPM3_bits + GIE);       // General interrupts enabled  and entering low power mode 3 "

this line in my code. give me the proper solution to receive data to the microcontroller.also i will share the my code for reference below.

Highlighted in green color line having stuck issue!.

Source Code:

//******************************************************************************
// MSP430FG662x Demo - eUSCI_A0, Ultra-Low Pwr UART 9600 Echo ISR, 32kHz ACLK
//
// Description: Echo a received character, RX ISR used. Normal mode is LPM3,
// eUSCI_A0 RX interrupt triggers TX Echo.
// ACLK = 32768Hz crystal, MCLK = SMCLK = DCO ~1.045MHz
// Baud rate divider with 32768Hz XTAL @9600 = 32768Hz/9600 = 3.41
// See User Guide for baud rate divider table
//
// Note that UCA0RXD and UCA0TXD need to be assigned pins via the PMAP
// controller.
//
// MSP430FG662x
// -----------------
// /|\ | XIN|-
// | | | 32kHz
// ---|RST XOUT|-
// | |
// | P2.0/UCA0TXD|------------>
// | | 9600 - 8N1
// | P2.1/UCA0RXD|<------------
//
// M. Swanson
// Texas Instruments Inc.
// April 2014
// Built with Code Composer Studio v5.5
//******************************************************************************
#include <msp430.h>

int ReceiveData;
int main(void)
{

WDTCTL = WDTPW | WDTHOLD; // Stop WDT
CTSD16CCTL0 |= CTSD16SC; // Workaround for CTSD16OFFG errata
do
{
CTSD16CTL &= ~CTSD16OFFG;
}
while (CTSD16CTL&CTSD16OFFG); // End of CTSD16OFFG workaround

while(BAKCTL & LOCKBAK) // Unlock XT1 pins for operation
BAKCTL &= ~(LOCKBAK);
UCSCTL6 &= ~(XT1OFF); // XT1 On
UCSCTL6 |= XCAP_3; // Internal load cap


// Loop until XT1 fault flag is cleared
do
{
UCSCTL7 &= ~(XT2OFFG | XT1LFOFFG | DCOFFG);
// Clear XT2,XT1,DCO fault flags
SFRIFG1 &= ~OFIFG; // Clear fault flags
}while (SFRIFG1&OFIFG); // Test oscillator fault flag

__enable_interrupt(); // enable all interrupts
__bis_SR_register(LPM3_bits + GIE); // General interrupts enabled // (LPM3_bits +)
__no_operation(); // For debugger


//----------------------------------------- Configuring MAX485 Control Lines ---------------------------------------//

P8SEL |= BIT4; // COMMON P8.4 to ~RE DE and...at P8.4
P8DIR |= BIT4; // common P8.4 -> DE,-> ~RE output P8.4
// P8OUT &= ~(BIT4); // ~RE & DE SET TO ZERO IN RECEIVING MODE

P8SEL |= 0x0C; // Assign P8.2 to UCA0TXD and...
P8DIR |= 0x0C; // P8.3 to UCA0RXD

UCA1CTL1 |= UCSWRST; // **Put state machine in reset**
UCA1CTL1 |= UCSSEL_1; // CLK = ACLK
UCA1BR0 = 0x03; // 32kHz/9600=3.41 (see User's Guide)
UCA1BR1 = 0x00; //
UCA1MCTL = UCBRS_3|UCBRF_0; // Modulation UCBRSx=3, UCBRFx=0
UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UCA1IE |= UCRXIE; // Enable USCI_A1 RX interrupt
//-----------------------------------******************************--------------------------------------------------------//


/*************************************************************************************************/

while(1)
{
// while (!(UCA1IFG&UCTXIFG)); // USCI_A1 TX buffer ready?
// UCA1TXBUF = 0xAA;
// __delay_cycles (48000);

}
}


/************************************RS485 ISR SETUP***************************/

// Echo back RXed character, confirm TX buffer is ready first//
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A1_VECTOR

__interrupt void USCI_A1_ISR(void)

#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_A1_VECTOR))) USCI_A1_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(UCA1IV,4))
{
case 0:break; // Vector 0 - no interrupt
case 2: // Vector 2 - RXIFG
P8OUT &= (~BIT4); // ~RE & DE SET TO ZERO IN RECEIVING MODE
while (!(UCA1IFG&UCTXIFG)); // USCI_A1 TX buffer ready?
ReceiveData=UCA1RXBUF;
P8SEL |= BIT4;
__delay_cycles (4800);
UCA1TXBUF = ReceiveData; // TX -> RXed character
__delay_cycles (4800);
break;
case 4:break; // Vector 4 - TXIFG
default: break;
}
}
/*****************************************************************************************************************************/

  • You appear to be going into LPM3 before you've configured UCA1, so the UART won't be running and thus it won't receive anything.

    What happens if you remove that line? (Longer term you'll probably want to move it into the while(1) loop.)

  • Hello Sayali,

    In addition to Bruce's comment, please be sure when posting code to the forum to utilize the code formatting tool. When making a post, just click "Insert" then "</> Code" to bring up a window you can paste code into. This will format it for readability. I've already edited your post to reflect such a change. 

  • According to you said i have made changes, that is the initialize LPM3 mode after UART but still same issue is occured program will stucked into this same line. please check my clock configuration in code is correct or not? bcoz In datasheet LPM3 section having said -> 

    Low-power mode 3 (LPM3) – CPU is disabled – MCLK, FLL loop control, and DCOCLK are disabled – DC generator of the DCO is disabled – ACLK remains active. i think clock setting wrong then may be it will be happening.

  • 1) The UART is symmetric, so if you saw correct transmission (including correct baud rate) on transmit, the clock is presumed OK. 

    2) As you said, ACLK runs in LPM3, so the UART continues to operate. That said: If you think it's getting in the way, try just removing the LPM (or try e.g. LPM0) for now.

    3) This doesn't look quite right:

    > P8SEL |= BIT4; // COMMON P8.4 to ~RE DE and...at P8.4

    since this will assign P8.4 to UCB1CLK, after which you can't control it. I suspect you want /RE low at least until you receive something, so try replacing this with:

    > P8OUT &= ~BIT4; // /RE,DE initially low (Rx mode)

    4) Your ISR sets /RE low, but too late -- /RE needs to be low in order to receive any bits. I suggest you remove that line (but see (5) below).

    5) Your ISR sets /RE high for the transmit (echo), but then leaves it high, so you won't receive anything else. I suggest you replace the (second) __delay_cycles with:

    > while (UCA1STAT & UCBUSY) /*EMPTY*/;  // Wait for transmission to finish

    > P8OUT &= ~BIT4;   // Back into receive mode

  • Hello Sayali,

    I suggest you utilize our standard UART code example that implements TX and RX. This should help you continue on with your project.

    https://dev.ti.com/tirex/explore/node?node=ALbd14Q.8l5pR.NohrNbuQ__IOGqZri__LATEST 

**Attention** This is a public forum