I’m using the library mbed-modbus with Mbed-CE, the target is a board with STM32F407VE (custom target).
The code works in general, but in portserial.cpp the xMBPortSerialInit did not pass the parity to UnbufferedSerial object. I added this, but pc.write() is still sending with parity none, although the underlying HAL_init for the uart is called with the correct parameters like 9 bits for 8 data + parity and parity setting is also even.
For testing I added a pc.write() loop into the init function. The string is sent, but with parity none. What can be the problem?
This is a part from portserial.cpp for the init function with my testcode, it is called with MB_PAR_EVEN:
/* ----------------------- System Variables ---------------------------------*/
// UnbufferedSerial pc(USART3_TX, USART3_RX); // Cam - mbed USB serial port
UnbufferedSerial pc(PD_5, PD_6);
DigitalOut rs485TxEn(PD_7, 0);
/* ----------------------- Start implementation -----------------------------*/
void
vMBPortSerialEnable( BOOL xRxEnable, BOOL xTxEnable )
{
/* If xRXEnable enable serial receive interrupts. If xTxENable enable
* transmitter empty interrupts.
*/
pc.enable_input( xRxEnable );
pc.enable_output( xTxEnable );
rs485TxEn = xTxEnable ? 1 : 0;
}
BOOL
xMBPortSerialInit( UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits, eMBParity eParity )
{
pc.enable_output( false );
pc.enable_input( false );
pc.set_blocking( false );
pc.baud( ulBaudRate );
// convert MBParity to Mbed Parity
SerialBase::Parity p = SerialBase::Parity::None;
if (eParity == eMBParity::MB_PAR_EVEN) {
p = SerialBase::Parity::Even;
} else if (eParity == eMBParity::MB_PAR_ODD) {
p = SerialBase::Parity::Odd;
} else {
return FALSE;
}
pc.format(ucDataBits, p);
//pc.attach( &prvvUARTTxReadyISR, SerialBase::TxIrq );
//pc.attach( &prvvUARTRxISR, SerialBase::RxIrq );
// testcode
pc.enable_output( true );
rs485TxEn = 1;
while(true) {
pc.write( "0123456789", 10 );
ThisThread::sleep_for(10ms);
}
return TRUE;
}