0
votes

I am trying to connect MSP-EXP430F5529LP external serial port (P3.4 and P3.5) to an external serial device. Both are set to 9600,8 bits, No Parity, 1 stop bit under Energia environment. I have set the Serial1 defaults in the config file as above. I am running the following sketch

    void setup()
{
  // put your setup code here, to run once:
  Serial1.begin(9600);
  Serial.begin(9600);
}

void loop()
{
  // put your main code here, to run repeatedly:

  Serial1.write(48);
  Serial.println(48,HEX); 
  delay(1000); //1 a second 
}

The TI is transmitting one byte every second, ASCII '0' 0x30 0b00110000 The receiver is receiving one bite but it's 0x06 0b00000110 - I have tried all the usual messing with parity and stop bits but I cannot get the '0' transmitted successfully. I think there may be some bug with Energia support for MSP-EXP430F5529LP Serial as it's soooo nearly working. Is there some weird byte swap thing going g on? I have verified the settings of the receiver are indeed 9600N81. Where should I look?

-EDIT-

*(&(UCAxCTL1) + uartOffset) = UCSWRST;
    *(&(UCAxCTL1) + uartOffset) = UCSSEL_2;                                // SMCLK
    *(&(UCAxCTL0) + uartOffset) = 0;
    *(&(UCAxABCTL) + uartOffset) = 0;

The above code is in HardwareSerial.cpp and sets all defaults: No parity, Odd parity (ignored because of previous), LSB first, 8 bit, one stop, UART mode, Async.(ref. slau1.pdf pg. 440). Using the above sketch, I have the following mapping of transmitted characters and what is received. I am baffled currently (and I hate serial comms!!)

Output from MSP430     Received
0000 0001              0111 1111
0000 0010              0011 1111
0000 0011              0111 1110
0000 0100              0001 1111
0000 0101              0111 1101
...
0000 1000              0000 1111
...
0001 0000              0000 0111
....
0010 0000              0000 0011 

-EDIT 2- [SOLVED] at least good enough for my needs

I now have to working with a 'fudge' fix. Since I only need output from the MSP430 I have modified HardwareSerial.cpp

size_t HardwareSerial::write(uint8_t c)
{
    unsigned int i = (_tx_buffer->head + 1) % SERIAL_BUFFER_SIZE;

    // If the output buffer is full, there's nothing for it other than to
    // wait for the interrupt handler to empty it a bit
    // ???: return 0 here instead?
    while (i == _tx_buffer->tail);

    //Fix wierdness
    ///////////////////////
    _tx_buffer->buffer[_tx_buffer->head] = 255-(c*2); //Originally was 'c' this formula was calculated by JWH
    ///////////////////////
    _tx_buffer->head = i;

#if defined(__MSP430_HAS_USCI_A0__) || defined(__MSP430_HAS_USCI_A1__) || defined(__MSP430_HAS_EUSCI_A0__) || defined(__MSP430_HAS_EUSCI_A1__)
    *(&(UCAxIE) + uartOffset) |= UCTXIE;
#else
    *(&(UC0IE) + uartOffset) |= UCA0TXIE;
#endif  

    return 1;
}

If anyone can explain why this is happening, I will happily up vote you!

1

1 Answers

0
votes

In USART mode the serial port can transmit the data in either LSB or MSB first mode. Normally you transmit in LSB first mode. It looks as if the USART could be transmitting the data MSB first.

The direction is set by the UCMSB (bit 5) control bit in the UCAxCTL0 register. This bit needs to be clear.