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.
hi this my uart code for msp430fg4618 this code is working so i want modbus plc signal communicate with msp430fg4618 through uart . how to change this code . pls send corrected code
modbus signal how to configure boud rate etc in this code\
pls send corrected code
with modbus implementation code
#include <msp430xg46x.h>
int main(void)
{
volatile unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P4SEL |= 0x03; // P4.1,0 = USART1 TXD/RXD
FLL_CTL0 |= XCAP14PF; // Configure load caps
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
for (i = 0x47FF; i > 0; i--); // Time for flag to set
}
while ((IFG1 & OFIFG)); // OSCFault flag still set?
ME2 |= UTXE1 + URXE1; // Enable USART1 TXD/RXD
U1CTL |= CHAR; // 8-bit character
U1TCTL |= SSEL1 + SSEL0 + URXSE; // UCLK = SMCLK, start edge detect
U1BR0 = 0x37; // 1MHz 19200
U1BR1 = 0x00; // 1MHz 19200
U1MCTL = 0x6B; // 1MHz 19200 modulation
U1CTL &= ~SWRST; // Initialize USART state machine
IE2 |= URXIE1; // Enable USART1 RX interrupt
for (;;)
{
while (!(U1TCTL & TXEPT)); // Confirm no TXing before --> LPM3
_DINT(); // Disable interrupts for flag test
_NOP();
if (!(U1TCTL & SSEL0))
_BIS_SR(LPM0_bits + GIE); // RX'ing char, LPM, int's active
else
_BIS_SR(LPM3_bits + GIE); // Enter LPM3, int's active
}
}
#pragma vector=USART1RX_VECTOR
__interrupt void usart1_rx (void)
{
if ((IFG2 & URXIFG1)) // Test URXIFG0
{
while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready?
U1TXBUF = U1RXBUF; // RXBUF0 to TXBUF0
_BIC_SR_IRQ(LPM3_bits); // Exit LPM3 after reti
U1TCTL |= SSEL0; // SSEL0 = 1, no RX activity
}
else // Start edge
{
U1TCTL &= ~URXSE; // Clear URXS signal
U1TCTL |= URXSE; // Re-enable edge detect
_BIC_SR_IRQ(SCG1 + SCG0); // DCO reamins on after reti
U1TCTL &= ~SSEL0; // SSEL0= 0, RX activity
}
}
**Attention** This is a public forum