alejoseb / Modbus-STM32-HAL-FreeRTOS

Modbus TCP and RTU, Master and Slave for STM32 using Cube HAL and FreeRTOS
GNU Lesser General Public License v2.1
579 stars 192 forks source link

Coil change according to input #24

Closed S-Prato closed 3 years ago

S-Prato commented 3 years ago

Hi,

I'm new to stm32 programming and in general my knowledge is limited to basic university C courses. My question could be stupid, in that case feel free to close the issue. I can read and write coils through a master simulator but I would like to set coils ON or OFF based on inputs (switches) on the stm32 board. Is this possible? I basically would like to make a keyboard.

alejoseb commented 3 years ago

Certainly, your question is not related to any issue with this library. However, you can read inputs (switches) with something similar to the following code snippet:

if( HAL_GPIO_ReadPin(GPIOA, 3)) { ModbusDATA[0] | = 1<<3; // set }
else { ModbusDATA[0] & = ~ (1<<3); //clear }

ModbusDATA is the array used as part of the Modbus configuration, check that on the main.c file of the examples.