cancel
Showing results for 
Search instead for 
Did you mean: 

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

JShiu
Associate II

Kindly share the code for Keil.

4 REPLIES 4

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 Venmo
Up vote any posts that you find helpful, it shows what's working..

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.

@Community member​ Can you please help me this?​ I have mentioned the issue in the reply comment above.

Probably not. Not a library I'm familiar with. The logic in the IRQ Handler looks broken to me, and doesn't have code to address failure or error status from the USART.

Perhaps record the data stream actually observed and replay that through the logic used.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..