Thank you but it does not work.
I really do not understand, I begin to drop … : /
Here is my program and some explanations:
Slave address: 07
Baud Rate: 9600
Data Length: 8
Stop Bit: 1
Parity: No Parity
half duplex
Program:
#define Mesure
#define MODBUS_DEBUG_PRINT 0 // define to 1 to print transactions
#define CINBUFSIZE 15
#define COUTBUFSIZE 15
#define MODBUS_PORT C
#define _RS485 485
#define SERIAL_PORT_MODE _RS485
#use modbus_master.lib
void brdInit (void);
int MBM_Send_ADU ( char *Packet, int ByteCount );
int MBM_Rcv_Resp ( char * Packet );
void serInit ( void );
void ser485Tx(void);
void ser485Rx(void);
main ()
{ int i,a, RegsValue[50];
serInit();
ser485Tx();
i = MBM_ReadRegs ( 7, &RegsValue[0], 0xC558, 4 ); // read reg 0
ser485Rx();
a =MB_SUCCESS;
if (a==0)
printf("Connexion NON OK,
“);
else printf(“Connexion OK”);
printf(”%d, %d,
", RegsValue[0], RegsValue[1]);
while (1);
}
/****************************************************
/****************************************************/
void brdInit (void)
{
WrPortI(PCFR, &PCFRShadow, PCFRShadow&0xEA); //clear bit 4,2,0 to normal function
WrPortI(PCDR, &PCDRShadow, PCDRShadow|0x15); //bits 5,3,1 normally inputs
WrPortI(PDDDR, &PDDDRShadow, 0x8b); //set bits 7,3,1,0 to output, rest inputs
}
void serInit ( void )
{ serCopen (9600 ); // open the serial port
}
void ser485Tx( void )
{
#asm
push ip ;save off IP state
ipset 1 ;set interrupt priority to level 1
ld a,(PDDRShadow) ;get copy of shadow reg
set 7,a ;set bit 7
ioi ld (PDDR),a ;set PD7 high
ld (PDDRShadow),a ;update shadow reg
pop ip ;restore IP to the previous state
#endasm
}
void ser485Rx( void )
{
#asm
push ip ;save off IP state
ipset 1 ;set interrupt priority to level 1
ld a,(PDDRShadow) ;get copy of shadow reg
res 7,a ;clear bit 7
ioi ld (PDDR),a ;set PF5 low
ld (PDDRShadow),a ;update shadow reg
pop ip ;restore IP to the previous state
#endasm
}
/* START FUNCTION DESCRIPTION ********************************************
MBM_Send_ADU
END DESCRIPTION **********************************************************/
int MBM_Send_ADU ( char *Packet, int ByteCount )
{ auto unsigned CRCvalue;
auto unsigned long Endtime;
int i;
// insert CRC
CRCvalue = MODBUS_CRC ( Packet, ByteCount );
Packet[ByteCount+1] = CRCvalue; // store low byte
Packet[ByteCount] = CRCvalue>>8; // store high byte
ByteCount+=2; // adjust for CRC
#ifdef MODBUS_DEBUG_PRINT & 1
printf ( “Tx:” );
for ( i=0; i