Skip to content

Commit

Permalink
通信プロトコルをModbusに変更 (#5)
Browse files Browse the repository at this point in the history
* add timer for modbus frame wait

* Change communication protocol to modbus from nema

* add modbus information to readme
  • Loading branch information
strv authored Dec 30, 2023
1 parent e978a7f commit 77f31da
Show file tree
Hide file tree
Showing 11 changed files with 634 additions and 243 deletions.
4 changes: 3 additions & 1 deletion Core/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ void adc_update_reserve();
/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/
#define PWM_CYCLE (SYSCLOCK / PWM_HZ - 1)
#define SYSCLOCK (64*1000*1000)
#define PWM_HZ (100000)
#define PWM_CYCLE (64*1000*1000 / PWM_HZ - 1)
#define MODBUS_BAUD 115200

/* USER CODE BEGIN Private defines */

Expand Down
1 change: 1 addition & 0 deletions Core/Inc/stm32g0xx_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void SysTick_Handler(void);
void DMA1_Channel1_IRQHandler(void);
void DMA1_Channel2_3_IRQHandler(void);
void TIM1_BRK_UP_TRG_COM_IRQHandler(void);
void TIM17_IRQHandler(void);
void USART1_IRQHandler(void);
void USART2_IRQHandler(void);
/* USER CODE BEGIN EFP */
Expand Down
1 change: 1 addition & 0 deletions Core/Inc/tim.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ extern "C" {
/* USER CODE END Private defines */

void MX_TIM1_Init(void);
void MX_TIM17_Init(void);

/* USER CODE BEGIN Prototypes */
typedef enum {
Expand Down
10 changes: 7 additions & 3 deletions Core/Inc/usart.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ extern "C" {
/* USER CODE BEGIN Includes */
#include <assert.h>
#include <stdbool.h>
#include <string.h>

#include "xprintf.h"
#include "tim.h"
/* USER CODE END Includes */

/* USER CODE BEGIN Private defines */
Expand All @@ -45,11 +46,14 @@ void MX_USART2_UART_Init(void);
/* USER CODE BEGIN Prototypes */
void usart_init();
void usart2_rx_cb();
void usart2_rx_ore_cb();
void usart2_tx_dma_cb();
int usart2_rx_line();
int usart2_puts(const uint8_t const * pbuf);
int usart2_tx_buf(const uint8_t* pbuf, const int length);
int usart2_getc();
int usart2_gets(char* pbuf);
void mb_timer_cb();
int mb_pop_frame(uint8_t* pframe);
void mb_push_frame(uint8_t* pframe, int length);
/* USER CODE END Prototypes */

#ifdef __cplusplus
Expand Down
4 changes: 2 additions & 2 deletions Core/Src/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ void MX_DMA_Init(void)

/* DMA interrupt init */
/* DMA1_Channel1_IRQn interrupt configuration */
NVIC_SetPriority(DMA1_Channel1_IRQn, 0);
NVIC_SetPriority(DMA1_Channel1_IRQn, 2);
NVIC_EnableIRQ(DMA1_Channel1_IRQn);
/* DMA1_Channel2_3_IRQn interrupt configuration */
NVIC_SetPriority(DMA1_Channel2_3_IRQn, 0);
NVIC_SetPriority(DMA1_Channel2_3_IRQn, 1);
NVIC_EnableIRQ(DMA1_Channel2_3_IRQn);

}
Expand Down
Loading

0 comments on commit 77f31da

Please sign in to comment.