summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAditya Naik2020-02-13 16:42:56 -0500
committerAditya Naik2020-02-13 16:42:56 -0500
commit16ef3a1bb300b1272ed8837f7ddee4f1be6f0191 (patch)
treeadfc6c764c19675fedb70dcea1fc90fc4c8b653a
parent78088e78539bdd5b4948f432f4747e7e1b7b75c8 (diff)
Arduino improvements and STM32 comment formatting
-rw-r--r--examples/arduino/arduino.ino6
-rw-r--r--examples/stm32/main.c35
2 files changed, 31 insertions, 10 deletions
diff --git a/examples/arduino/arduino.ino b/examples/arduino/arduino.ino
index d6d2e1a..c4af98c 100644
--- a/examples/arduino/arduino.ino
+++ b/examples/arduino/arduino.ino
@@ -28,7 +28,7 @@ void setup()
/* Attach the default HardwareSerial class instance to this node */
modbus_dev_single.modbus_uart = &Serial;
- /* Continuously read the this input register in superloop */
+ /* Continuously read this input register in superloop */
reg = 30001;
}
@@ -49,7 +49,7 @@ MB_StatusTypeDef ArduinoSerial_Tx(void* serial, uint16_t* buf, uint8_t* len, uin
_serial->write((uint8_t)*buf);
}
_serial->flush();
- /* Arduino HardwareSerial class does not return any errors, sadly */
+ /* HardwareSerial class funcs do not return any UART errors, sadly */
return MB_OK;
}
@@ -58,7 +58,7 @@ MB_StatusTypeDef ArduinoSerial_Rx(void* serial, uint16_t* buf, uint8_t* len, uin
HardwareSerial* _serial = static_cast<HardwareSerial*>(serial);
buf = _serial->read();
- /* Arduino HardwareSerial class does not return any errors, sadly */
+ /* HardwareSerial class funcs do not return any UART errors, sadly */
return MB_OK;
}
diff --git a/examples/stm32/main.c b/examples/stm32/main.c
index 9e71ed9..ebf90b6 100644
--- a/examples/stm32/main.c
+++ b/examples/stm32/main.c
@@ -1,14 +1,34 @@
-// TODO Makefile
-
#include <modbus.h>
-/* 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 */
+/*
+ * Note that this example is not self-contained. User will need to need to
+ * handle UART device initialization and relevant HAL/LL library includes.
+ * These steps are skipped in this example to ensure simplicity - illustrated
+ * here is the minimum code a user will need to use the modbus library AFTER
+ * the these steps.
+ *
+*/
+
+/*
+ * 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 not using CubeMX to initialize the project, refer to the HAL/LL user
+ * manual for instructions on UART initialization
+ *
+ * In order to run the example, the device initialization and superloop code
+ * will need to be copied from this file into the CubeMX-generated files
+ *
+*/
-/* 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 */
+/*
+ * 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;
@@ -16,13 +36,14 @@ 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? */
+ /* 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 */
+ /* Note that the initialization of UART1 device is not included in this example */
modbus_dev_single.modbus_uart = &huart1;
/* Continuously read the 30001 input register */
uint16_t register = 30001;