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.

MSP430FR6047: MSP430FR6047

Part Number: MSP430FR6047


Hello,
I have a problem with the MSP430FR6047 for communication with pc using uart. I'm  trying to send data with different lenght and echo it. 
for example i'm sending  
command = bytes([0x04, 0x81, 0x01, 0xFF, 0x2C, 0x01, 0x01]) as komand: b'\x04\x81\x01\xff,\x01\x01' and the recieved data is wrong Response: b'\x04\x81\x01,\x01\x01'.
but when i send only 2 byte and echo the same 2 byte, it works without problem. what am i doing wrong? I'm sending the command using python. below is my code for sending and recieving using python and the code in MCU. 

import serial
import time
# Define serial port settings
com_port = 'COM3'
baud_rate = 115200
Data_bits = 8
parity = 'N'
stop_bits = 1

# Open serial port
ser = serial.Serial(port=com_port, baudrate=baud_rate, bytesize=Data_bits, parity=parity, stopbits=stop_bits, timeout=0.5)

def read_response():
response = ser.read(7) # Read 7 bytes (packet size)
return response


def send_command():
command = bytes([0x04, 0x81, 0x01, 0xFF, 0x2C, 0x01, 0x01])
print("komand:", command)
print("len:", len(command))

# Send command
ser.write(command)
time.sleep(0.5)

while True:
# Send command
send_command()
# Read response
response = read_response()
# Print response
print("Response:", response)

code for MCU

#include <msp430.h>
#include <stdint.h>
//******************************************************************************
// Pin Config ******************************************************************
//******************************************************************************
static void UART_sendByte(uint8_t byte);

#define CENTER_ID 0x04
#define COMMAND_ID 0x80
#define WRITE_CMD 0x01
#define READ_CMD 0x00
#define DATA_SIZE 2
volatile uint16_t received_data = 0;
//******************************************************************************
// UART Initialization *********************************************************
//******************************************************************************

#define SMCLK_115200 0
#define SMCLK_9600 1
#define ACLK_9600 2
#define SMCLK_19200 3

//#define UART_MODE ACLK_9600//SMCLK_115200//
#define UART_MODE SMCLK_115200//

void initUART()
{
// Configure USCI_A0 for UART mode
UCA0CTLW0 = UCSWRST; // Put eUSCI in reset

#if UART_MODE == SMCLK_115200

UCA0CTLW0 |= UCSSEL__SMCLK; // CLK = SMCLK

// Baud Rate Setting
// Use Table 30-5 in Family User Guide
UCA0BR0 = 8;
UCA0BR1 = 0;
UCA0MCTLW |= UCOS16 | UCBRF_10 | 0xF700; //0xF700 is UCBRSx = 0xF7
//UCA0MCTLW |= UCOS16 | UCBRF_5 | 0xD600; //0xF700 is UCBRSx = 0xF7

#elif UART_MODE == SMCLK_9600

UCA0CTLW0 |= UCSSEL__SMCLK; // CLK = SMCLK

// Baud Rate Setting
// Use Table 30-5 in Family User Guide
UCA0BR0 = 3;
UCA0BR1 = 0;
UCA0MCTLW |= UCOS16 | UCBRF_8 | 0xD600; //0xD600 is UCBRSx = 0xD6

#elif UART_MODE == ACLK_9600

UCA0CTLW0 |= UCSSEL__ACLK; // CLK = ACLK
// Baud Rate calculation
// 32768/(9600) = 3.4133
// Fractional portion = 0.4133
// Use Table 24-5 in Family User Guide
UCA0BR0 = 3; // 32768/9600
UCA0BR1 = 0;
UCA0MCTLW |= 0x9200; //0x9200 is UCBRSx = 0x92
#elif UART_MODE == SMCLK_19200

UCA0CTLW0 |= UCSSEL__SMCLK; // CLK = SMCLK

// Baud Rate Setting
// Use Table 30-5 in Family User Guide
UCA0BR0 = 3;
UCA0BR1 = 0;
UCA0MCTLW |= UCOS16 | UCBRF_4 | 0x0200; //0xF700 is UCBRSx = 0xF7


#else
# error "Please specify baud rate to 115200 or 9600"
#endif

UCA0CTLW0 &= ~UCSWRST; // Initialize eUSCI
UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt
}

//******************************************************************************
// Device Initialization *******************************************************
//******************************************************************************

void initGPIO()
{
// Configure UART
P2SEL0 &= ~(BIT0 | BIT1);
P2SEL1 |= BIT0 | BIT1; // USCI_A0 UART operation

//set P1.6 und P1.7 as output
P1DIR |= BIT6 | BIT7;
// Configure PJ.5 PJ.4 for external crystal oscillator
PJSEL0 |= BIT4 | BIT5; // For XT1

PM5CTL0 &= ~LOCKLPM5;
}

void initClockTo16MHz()
{
// Configure one FRAM waitstate as required by the device datasheet for MCLK
// operation beyond 8MHz _before_ configuring the clock system.
FRCTL0 = FRCTLPW | NWAITS_1;

// Clock System Setup
CSCTL0_H = CSKEY_H; // Unlock CS registers
CSCTL1 = DCOFSEL_0; // Set DCO to 1MHz
// Set SMCLK = MCLK = DCO, ACLK = LFXTCLK (VLOCLK if unavailable)
CSCTL2 = SELA__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK;
// Per Device Errata set divider to 4 before changing frequency to
// prevent out of spec operation from overshoot transient
CSCTL3 = DIVA__4 | DIVS__4 | DIVM__4; // Set all corresponding clk sources to divide by 4 for errata
CSCTL1 = DCOFSEL_4 | DCORSEL; // Set DCO to 16MHz
// Delay by ~10us to let DCO settle. 60 cycles = 20 cycles buffer + (10us / (1/4MHz))
__delay_cycles(60);
CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // Set all dividers to 1 for 16MHz operation

CSCTL4 &= ~LFXTOFF;
do
{
CSCTL5 &= ~LFXTOFFG; // Clear XT1 fault flag
SFRIFG1 &= ~OFIFG;
}while (SFRIFG1&OFIFG); // Test oscillator fault flag

CSCTL0_H = 0; // Lock CS registerss
}

//******************************************************************************
// Main ************************************************************************
// Enters LPM0 if SMCLK is used and waits for UART interrupts. If ACLK is used *
// then the device will enter LPM3 mode instead. The UART RX interrupt handles *
// the received character and echoes it. *
//******************************************************************************

int main(void)
{
uint8_t test1[10] = {0};
int i;
WDTCTL = WDTPW | WDTHOLD; // Stop Watchdog

initGPIO();
initClockTo16MHz();
initUART();

P1OUT &= ~BIT6;
P1OUT &= ~BIT7;
while(1)
{
P1OUT &= ~BIT6;
P1OUT &= ~BIT7;
while(!(UCA0IFG & UCRXIFG));
for(i = 0; i<6; i++)
{
test1[i] = UCA0RXBUF;
__delay_cycles(2000);
}
P1OUT |= BIT6;
P1OUT |= BIT7;
while(!(UCA0IFG & UCTXIFG));
for(i = 0; i<6; i++)
{
UCA0TXBUF = test1[i];
__delay_cycles(2000);
}
}
}

  • Hi Pierre,

    Have you tried editing your script to send the characters more slowly? I am wondering if it is possible that the MSP has not had time to read each incoming byte. You might also find it easier to compare your code to some of our existing examples such as this one. Generally, using an interrupt to save the incoming bytes to a buffer, then processing/sending the bytes back in the main body of the code might help to eliminate timing problems.

  • Hi Dylan,
    actually I came to that example, because i had Reading problem in MSP430FR6047EVM_USS_Water_Demo. where i changed the Communication to uart. 

    the Software is sending without Problem and the result is recieved correctly with PC, but When i send a command for Example to change some configuration of the Algorthm from PC they'are not recieved. i tried to debug and realised that there are not recieved. that's why i come to the axample to send buffer and see ich i can echos it back. 
    the use of interrupt doesn't work at all. but if i try to read like i schowed in previous Email i get at least somthing but which is not completly correct. 

    the code in the software in MSP430FR6047EVM_USS_Water_Demo. which doesn't work in In uart.c in uart interrupt routine USCI_UART_UCRXIFG. like i said, send is working without any problem. 

    the question is, there is no exampel in MSP430FR6047 that recieve a buffer, all Example recieve a character and echos a character. 

    if you can tell me if there is an example that recieve a buffer may be it can be helpfull. 

  • Hi Pierre,

    The reason that our examples for the devices receive just one character is that this would be the most basic level of the device behavior. Even when receiving a buffer, the buffer will be received character by character, and saved to a buffer using software. So we leave it up to the designer to save each character to a buffer as needed and process that buffer.

    I will add that when using any interrupts in the USS demo, you will run into some trouble with other interrupts affecting device behavior. In my experience, I need to disable all other interrupts when adding an interrupt for something like UART. 

    To your point about the send from PC to MSP working correctly, but the MSP's parameters not saving, are you certain that your packet correctly matches the HID bridge structure? You may have already seen it but for the sake of clarity, here is a link to the description of the HID interface.

**Attention** This is a public forum