Hello! I use a MSP432 to send UART data over RS485 to a MSP430. The problem is that the MSP430 reads only 0xFF and 0xFE and receives only one out of each two bytes.
This is my schematic:
This is my code:
int NUM_OF_TX_BYTES = 0;
char uart_rxBuffer[UART_BUFFER_SIZE];
volatile uint32_t xferIndex = 0;
char uart_txBuffer[UART_BUFFER_SIZE];
volatile bool uartRxFlag = false;
void UART_init(void)
{
// Configuration for 9600 UART with SMCLK at 16384000
// software-dl.ti.com/.../index.html
EUSCI_A_UART_initParam uartConfig = {
EUSCI_A_UART_CLOCKSOURCE_SMCLK, // SMCLK Clock Source
106, // BRDIV = 8
10, // UCxBRF = 14
206, // UCxBRS = 34
EUSCI_A_UART_NO_PARITY, // No Parity
EUSCI_A_UART_LSB_FIRST, // LSB First
EUSCI_A_UART_ONE_STOP_BIT, // One stop bit
EUSCI_A_UART_MODE, // UART mode
EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION // Oversampling Baudrate
};
// Configure pins
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
// Configure and enable the UART peripheral
EUSCI_A_UART_init(EUSCI_A0_BASE, &uartConfig);
EUSCI_A_UART_enable(EUSCI_A0_BASE);
EUSCI_A_UART_enableInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT);
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A0_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(USCI_A0_VECTOR)))
#endif
void USCI_A0_ISR(void) {
switch(__even_in_range(UCA0IV, USCI_UART_UCTXCPTIFG)) {
case USCI_NONE: break;
case USCI_UART_UCRXIFG:
uart_rxBuffer[xferIndex++] = EUSCI_A_UART_receiveData(EUSCI_A0_BASE);
if (uart_rxBuffer[xferIndex - 1] == '\0')
{
xferIndex = 0; // Reset index if at end of array
uartRxFlag = true;
__bic_SR_register_on_exit(LPM0_bits); // Wake up
}
break;
case USCI_UART_UCTXIFG: break;
case USCI_UART_UCSTTIFG: break;
case USCI_UART_UCTXCPTIFG: break;
default: break;
}
}
I've used a logic analyzer to verify and I confirm that the data correctly reaches the MSP430, on pin UART_A0_RXD (e.g. message: "0;1\0"). I put a breakpoint inside the RX ISR and it hits every two bytes, and the RX buffer contains only 0xFF or 0xFE, alternatively.
What is wrong? Is there a problem with my code or with the MCU?
