// Debugging port
#define DEBUG_USART USART1
+#define DEBUG_LED_BLUEPILL
// MODBUS library parameters
#define MODBUS_USART_ISR usart3_isr
#define MODBUS_TXEN_GPIO_PORT GPIOA
-#define MODBUS_TXEN_GPIO_PIN GPIO1
+#define MODBUS_TXEN_GPIO_PIN GPIO6
#define MODBUS_TIMER TIM2
#define MODBUS_NVIC_TIMER_IRQ NVIC_TIM2_IRQ
#define MODBUS_BAUD_RATE 19200
+#define MODBUS_DEBUG
+
// DS18B20 library parameters
#define DS_TIMER TIM3
#include "util.h"
#include "ds18b20.h"
+#include "modbus.h"
#include <libopencm3/cm3/nvic.h>
#include <libopencm3/cm3/systick.h>
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO0);
gpio_set(GPIOB, GPIO0);
- // PB1 = IR RC active LED*
+ // PB1 = MODBUS frame LED*
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO1);
gpio_set(GPIOB, GPIO1);
debug_puts("Hello, world!\n");
ds_init();
+ modbus_init();
for (;;) {
- gpio_toggle(GPIOC, GPIO13);
-
- gpio_clear(GPIOB, GPIO1);
- delay_ms(100);
- gpio_set(GPIOB, GPIO1);
+ debug_led_toggle();
gpio_clear(GPIOB, GPIO0);
- delay_ms(100);
+ delay_ms(50);
gpio_set(GPIOB, GPIO0);
+ delay_ms(50);
+
+ modbus_loop();
}
#if 0
return 0;
}
+
+/*** Modbus callbacks ***/
+
+bool modbus_check_discrete_input(u16 addr UNUSED)
+{
+ return false;
+}
+
+bool modbus_get_discrete_input(u16 addr UNUSED)
+{
+ return false;
+}
+
+bool modbus_check_coil(u16 addr UNUSED)
+{
+ return false;
+}
+
+bool modbus_get_coil(u16 addr UNUSED)
+{
+ return false;
+}
+
+void modbus_set_coil(u16 addr UNUSED, bool value UNUSED)
+{
+}
+
+bool modbus_check_input_register(u16 addr UNUSED)
+{
+ return false;
+}
+
+u16 modbus_get_input_register(u16 addr UNUSED)
+{
+ return 0;
+}
+
+bool modbus_check_holding_register(u16 addr UNUSED)
+{
+ return (addr < 16);
+}
+
+u16 modbus_get_holding_register(u16 addr UNUSED)
+{
+ return 0xbeef;
+}
+
+void modbus_set_holding_register(u16 addr UNUSED, u16 value UNUSED)
+{
+}
+
+void modbus_ready_hook(void)
+{
+ // Frame LED off
+ gpio_set(GPIOB, GPIO1);
+}
+
+void modbus_frame_start_hook(void)
+{
+ // Frame LED on
+ gpio_clear(GPIOB, GPIO1);
+}
+
+const char * const modbus_id_strings[MODBUS_ID_MAX] = {
+ [MODBUS_ID_VENDOR_NAME] = "United Computer Wizards",
+ [MODBUS_ID_PRODUCT_CODE] = "42",
+ [MODBUS_ID_MAJOR_MINOR_REVISION] = "1.0",
+ [MODBUS_ID_VENDOR_URL] = "http://www.ucw.cz/",
+ [MODBUS_ID_PRODUCT_NAME] = "Magic Gadget",
+ [MODBUS_ID_USER_APP_NAME] = NULL,
+};