Rs485 Uart C Code

Posted on
$begingroup$

The UART (Universal Asynchronous Receiver Transmitter) Wildcard provides two full-duplex serial ports that can be configured for RS232, RS422, and RS485 protocols to implement the communications links that are often needed in instrument control applications.

Using embedded proggraming, Code Composer Studio 6.0.1,

Trying to configurate UART to communicate between MSP430F6736A and my PC. Using USB/RS485 converver(2 vire (A,B)).

For sending data using HERCULES(app for testing communication).

All I want is when I send data(for eample number 5) from HERCULES(config same: 1200 baud, no parity, 1 stop bit) I want to receive them and turn LED on. But it doesn´t work.

Somewhere in this code is something missing or something bad written. , . I got big head from datasheets so can anyone help me?

user5939530
$endgroup$

migrated from stackoverflow.comMay 6 '16 at 8:24

This question came from our site for professional and enthusiast programmers.

1 Answer

$begingroup$

The entire interrupt handler function is wrong.

UCA1IV is a vector register, not an interrupt flag. To wait for the TX buffer being ready, you must check for the UCTXIFG bit being set.

This line happens to be correct.

Accessing registers has side effects. Reading UCA1TXBUF might actually work, but reading UCA0RXBUF removes the next byte from the buffer, if it exists.

And this comparison does not make sense; you echoed the received byte in the previous line, so this condition, if it worked, would always be true.

You do not need to reinitialize this bit.

This does not change the state of the LED, because the bit has the same value you initialized it with.

The interrupt function should look somewhat like this:

CL.CL.
10.7k3 gold badges24 silver badges46 bronze badges
$endgroup$$begingroup$

Using embedded proggraming, Code Composer Studio 6.0.1,

Trying to configurate UART to communicate between MSP430F6736A and my PC. Using USB/RS485 converver(2 vire (A,B)).

For sending data using HERCULES(app for testing communication).

All I want is when I send data(for eample number 5) from HERCULES(config same: 1200 baud, no parity, 1 stop bit) I want to receive them and turn LED on. But it doesn´t work.

Uart

Somewhere in this code is something missing or something bad written. , . I got big head from datasheets so can anyone help me?

user5939530
$endgroup$

migrated from stackoverflow.comMay 6 '16 at 8:24

This question came from our site for professional and enthusiast programmers.

1 Answer

Modbus Rs485 C Code

$begingroup$

The entire interrupt handler function is wrong.

UCA1IV is a vector register, not an interrupt flag. To wait for the TX buffer being ready, you must check for the UCTXIFG bit being set.

This line happens to be correct.

Accessing registers has side effects. Reading UCA1TXBUF might actually work, but reading UCA0RXBUF removes the next byte from the buffer, if it exists.

And this comparison does not make sense; you echoed the received byte in the previous line, so this condition, if it worked, would always be true.

You do not need to reinitialize this bit.

This does not change the state of the LED, because the bit has the same value you initialized it with.

The interrupt function should look somewhat like this:

CL.CL.
10.7k3 gold badges24 silver badges46 bronze badges
$endgroup$