Skip to main content
JShiu
Associate
October 7, 2019
Question

How do I establish communication between STM32F429IG and Energy meter using modbus RS485 serial communication port using Keil version 5 software?

  • October 7, 2019
  • 1 reply
  • 1293 views

Kindly share the code for Keil.

This topic has been closed for replies.

1 reply

Tesla DeLorean
Guru
October 7, 2019

Sounds very work specific, perhaps you need a software developer on the team.

Perhaps start with getting the RS485 interface up, and then layer the protocol, and device specifics on top of that.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
JShiu
JShiuAuthor
Associate
October 9, 2019

Can you help with modbus rtu

main.c file:-
 
#include "bsp.h"
#include"systick.h"
int main()
 {
	USART_INTERRUPT_CONFIGURATION(USART6,GPIOC,GPIO_PinSource6,GPIO_PinSource7,GPIO_Pin_6,GPIO_Pin_7,0,0);
	char tmp[8];
	tmp[0]=0x01;
	tmp[1]=0x03;
	tmp[2]=0xbd;
	tmp[3]=0x02;
	tmp[4]=0x02;
	tmp[5]=0x00;
	tmp[6]=0x01;
	tmp[7]=0Xa6;
int i=0;
	gpio_init(GPIOI,GPIO_Pin_8);
	RS485_TX_ENABLE;
	SEND_STRING(tmp,USART6);
}
 
 
 
 
 
 
 
 
 
 
 
 
Interrupt:-
 
st_buf Rbg={0,0,};
uint16_t S;
uint16_t slave,func,no_of_bytes,data_reg_hi,data_reg_Lo,crc1,crc2;
void USART1_IRQHandler (void)
{
	//gpio_init(GPIOI,GPIO_Pin_11);
static st_buf *p;
	//RS485_RX_ENABLE;
	 // RS485_TX_DISABLE;
 p=&Rbg;
 if ((USART_GetFlagStatus(USART1,USART_IT_RXNE))) 
	 {
	 
 if( p->in!=RBUF_SIZE) 
				{
 p->buf [p->in]=USART1->DR;
				S = p->buf [p->in];
				//gpio_init(GPIOH,GPIO_Pin_6)=S;
 p->in++;
		switch(S)
	 {
		 case 1:
		 slave=S; 
		 break;
		 case 3:
			 func=S;
		 break;
		 case 0x02:
		 no_of_bytes=S;
		 break;
		 case 0:
			 data_reg_hi=S;
		 break;
		 case 0x2d:
			 data_reg_Lo=S;
		 break;
		 case 0x78:
			 crc1=S;
		 break;
		 case 0x59:
			 crc2=S;	 
	 }
			}
 }
}

protocol code? I am using usart interrupt & DMA functions and I find incomplete bits are transferring from the instruction set. Kindly help with Keil program codes. Thank you so much for the help.