Serial port MSP-EXP430F5529LP TI启动板UART串行通信问题
我正在尝试将MSP-EXP430F5529LP外部串行端口(P3.4和P3.5)连接到外部串行设备。在Energia环境下,两者都设置为9600,8位,无奇偶校验,1个停止位。我在配置文件中设置了Serial1默认值,如上所述。我正在运行以下草图Serial port MSP-EXP430F5529LP TI启动板UART串行通信问题,serial-port,uart,msp430,Serial Port,Uart,Msp430,我正在尝试将MSP-EXP430F5529LP外部串行端口(P3.4和P3.5)连接到外部串行设备。在Energia环境下,两者都设置为9600,8位,无奇偶校验,1个停止位。我在配置文件中设置了Serial1默认值,如上所述。我正在运行以下草图 void setup() { // put your setup code here, to run once: Serial1.begin(9600); Serial.begin(9600); } void loop() {
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
}
TI每秒发送一个字节,ASCII“0”0x30 0B0011000接收器接收到一个比特,但它是0x06 0b00000110-我尝试了所有常用的奇偶校验位和停止位,但无法成功发送“0”。我认为Energia对MSP-EXP430F5529LP系列的支持可能存在一些缺陷,因为它几乎可以正常工作。有什么奇怪的字节交换吗?我已经验证了接收器的设置确实是9600N81。我应该去哪里看
-编辑-
*(&(UCAxCTL1) + uartOffset) = UCSWRST;
*(&(UCAxCTL1) + uartOffset) = UCSSEL_2; // SMCLK
*(&(UCAxCTL0) + uartOffset) = 0;
*(&(UCAxABCTL) + uartOffset) = 0;
上述代码位于HardwareSerial.cpp中,并设置了所有默认值:
无奇偶校验、奇偶校验(由于之前的原因被忽略)、LSB优先、8位、一站式、UART模式、异步(参考slau1.pdf第440页)。使用上面的草图,我有以下传输字符和接收内容的映射。我现在很困惑(我讨厌串行通信!!)
-编辑2-[已解决]至少满足我的需要
我现在必须用“软糖”修复。因为我只需要MSP430的输出,所以我修改了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;
}
如果有人能解释为什么会发生这种情况,我会很高兴地投票给你 在USART模式下,串行端口可以在LSB或MSB first模式下传输数据。通常以LSB第一模式传输。看起来USART可能首先传输数据MSB 方向由UCMSB设置(位5)
UCAxCTL0寄存器中的控制位。这一点需要澄清。谢谢您的评论。我尝试了两种方法,但都没有解决。我添加了更多关于传输内容和接收内容之间关系的细节。目前我还没有找到解决办法!
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;
}