2021-02-02 07:41 PM
Hello everybody:
i'm trying to implement modbus function on mcu(stm32F4)
my structure as following
i receive data from usart6 by HAL_UART_Receive_DMA function(circular mode)
it's work when just only one MCU edge. but if two mcu edge (two modbus slave), it will make some problem.
when i polling the mcu1 only, the rxbuffer from DMA is correctly(modbus-rtu query package)
when i pooling mcu1(slaveID 2) and mcu2(slaveID 4), the package will be shift or incorrect.
my DMA parameter
my question is
i reveice uart data by "HAL_UART_Receive_DMA"
how to fix the rxbuffer shifting issue
i 'm sure that the modbusPoll(master) send the correct package
/* USER CODE BEGIN 4 */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(huart);
/* NOTE: This function should not be modified, when the callback is needed,
the HAL_UART_RxCpltCallback could be implemented in the user file
*/
__NOP();
if(huart==&huart6)
{
if (rxbuffer[0]==slaveID)
{
/* if slaveID match
* put rxbuffer to ModBusInHandle
*/
__NOP();
for(int i=0;i<8;i++)
osMessagePut(ModBusInHandle,rxbuffer[i], 8);
}
else
{
// if uart RX_ID no match slaveID(switch on board), reset rxbuffer
memset(rxbuffer,0, 8);
}
HAL_Delay(1);
}
// active DMA again, because DMA set normal mode
//HAL_UART_Receive_DMA(&huart6, rxbuffer, 8);
}
2021-02-03 12:27 PM
Sounds like a similar problem to this. Try to do what I've recommended there. Maybe the ISR is too slow or some other ISR blocks it for too long so that data are missing.
JW