Hello,
I already checked the codes and confirmed that it didn't return kStatus_LPUART_BaudrateNotSupport.
I assume it's not just a clock or baud rate problems. It seems the problem is related to circuit of the EVK board or something else.
The reason why I think like that first, modbus communication worked well even on UART3 if the transmission data wasn’t much (< 30 - 40bytes) regardless of any baud rates. The problem of receiving one packet to several packets only occurs when transmitted many data and it didn’t occur all the time only occasionally. I guess there is a case that sometime there is a delay than 3.5 characters of the baud rate in transmitting. According to modbus specification, it perceives the transmission end when there is a delay more than 3.5 character time between characters. A strange thing is that there is no issue or intermittently issue on UART3 with baud rate 9600, 19200 and 115200 but it occurs often with 38400 and 57600.
Second, it worked very well on UART1 regardless of any baud rates or any size of transmit data. According to what you said that ‘the configuration should be same way’ then it is more likely issue related to hardware because it’s different between UART1 and UART3. Do you have any idea why the result is different between of the two ports?
The test codes are very simple like below and I checked whether slave sending response or not by using serial monitoring program. The project files is attached in this post.
#define DEMO_LPUART LPUART3
#define DEMO_LPUART_CLK_FREQ BOARD_DebugConsoleSrcFreq()
const uint8_t g_txPacketData[] = { /* MODBUS FC:03, ADDRESS:0, COUNT: 100 */
0x01, 0x10, 0x00, 0x00, 0x00, 0x64, 0xC8, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD4, 0x93
};
/*!
* @brief Main function
*/
int main(void)
{
uint8_t ch;
lpuart_config_t config;
BOARD_ConfigMPU();
BOARD_InitBootPins();
BOARD_InitBootClocks();
/*
* config.baudRate_Bps = 115200U;
* config.parityMode = kLPUART_ParityDisabled;
* config.stopBitCount = kLPUART_OneStopBit;
* config.txFifoWatermark = 0;
* config.rxFifoWatermark = 0;
* config.enableTx = false;
* config.enableRx = false;
*/
LPUART_GetDefaultConfig(&config);
config.baudRate_Bps = 38400UL;
config.enableTx = true;
config.enableRx = true;
LPUART_Init(DEMO_LPUART, &config, DEMO_LPUART_CLK_FREQ);
while (1)
{
LPUART_WriteBlocking(DEMO_LPUART, g_txPacketData, sizeof(g_txPacketData));
SDK_DelayAtLeastUs(1000000U, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
}
}
By the way, I tested it by changing the UART clock selector and the clock divider. For baud 38400 on UART3, clock divider of 7 based on both PLL3 and OSC 24MHz worked well without the issue above but other baud rates except 9600 and 19200 had issue in communication to slave.
I will definitely check if there is a delay between data in transmitting, let you know.
Any ideas and advice would help me a lot.
Thanks