diff options
| author | Aditya Naik | 2020-02-13 12:09:50 -0500 |
|---|---|---|
| committer | Aditya Naik | 2020-02-13 12:09:50 -0500 |
| commit | be38e008fb0bae72983aa25e51182fa5f18f8e59 (patch) | |
| tree | 72640e5f013dbf06c550ecfee62ea11116467291 /examples/stm32 | |
| parent | 92845f54739566c6cbb3df7eb02cae2501ff7f94 (diff) | |
STM32 example done, not tested
Diffstat (limited to 'examples/stm32')
| -rw-r--r-- | examples/stm32/main.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/examples/stm32/main.c b/examples/stm32/main.c index e202ae5..7f63529 100644 --- a/examples/stm32/main.c +++ b/examples/stm32/main.c @@ -3,16 +3,35 @@ /* If using CubeMX, the HAL library files will be automatically placed in the correct location. The examples were tested with the Makefile option in CubeMX. */ /* If you are not using CubeMX to initialize the project, you are on your own */ -/* In order to run the example, you will need to copy the superloop code as well as the external function initializations from this file */ +/* In order to run the example, you will need to copy the device initialization, superloop code as well as the external function initializations from this file */ /* Function initialization for the STM32 HAL Library */ /* Since this library was orignally written to work with the STM32 HAL/LL API, the UART functions match perfectly and can be directly mapped to the Modbus library functions */ - +MB_StatusTypeDef (*MB_UART_Tx)(void*, uint16_t*, uint8_t*, uint8_t*) = &HAL_UART_Transmit; +MB_StatusTypeDef (*MB_UART_Rx)(void*, uint16_t*, uint8_t*, uint8_t*) = &HAL_UART_Receive; int main() { + /* Single modbus device node */ + modbus_slave_device modbus_dev_single; + /* Multiple modbus device nodes.. after all what is the point of using Modbus in a single point-to-point connection? */ + /* Not illustrated beyond the definition, but should be clear enough */ + modbus_slave_device modbus_dev_multiple[10]; + + /* Set the slave ID to 1 */ + modbus_dev_single.slave_id = 1; + /* Attach the UART device on the STM32 to this node */ + modbus_dev_single.modbus_uart = &huart1; + /* Continuously read the 30001 input register */ + uint16_t register = 30001; + while (1) { - + MB_StatusTypeDef status = ReadInputRegisters(modbus_dev_single, register, 1); + if (status == MB_OK) { + /* Do something with data in the response buffer */ + /* ... */ + ClearResponseBuffer(&modbus_dev_single); + } } return 1; } |
