我正试图通过使用STM32F4-Discovery Board的UART外设实现ModBus RTU协议。如何使用C/C++映射Modbus寄存器地址
我打算使用Modbus RTU实现主站和从站功能。
这里是我的问题
我怎么能在UART动我接收到的数据MODBUS和传输来自MODBUS层数据到UART,用C/C++,请提供一些代码片断,可以帮助我理解你的解释。 (截至目前我正在考虑想出一些API的,请建议一些模式)
其次我怎么能实现Modbus寄存器和线圈。我的意思是我如何定义ModBus应用手册中指定的地址。请用代码片段解释我。下面我试图实现。
/*Global Array, Structure and Variable Declarations*/
/* So to access Discrete_Output_Coils[2345]
the valid address to include in the protocol would be
so we have to access address 0x929 to read the
data.*/
const unsigned short int Discrete_Output_Coils[4999];
const unsigned short int Discrete_Input_Contacts[4999];
const unsigned short int Analog_Input_Register[4999];
const unsigned short int Anlog_output_Holding_Register[4999];
你的问题太宽泛。首先,从master *或* slave开始,但不能同时使用两者。其次,阅读Modbus规范。第三,从非常简单的非常简单的实现开始,您可以发送或接收帧,而不需要其他任何东西。如果您没有基本的传输分拣机,尝试考虑注册实施毫无意义。 – user694733