ali
Joined: 08 Jun 2010 Posts: 1
|
18f452 modbus problem |
Posted: Tue Jun 08, 2010 2:04 am |
|
|
Code: |
#include <stdio.h>
#include <stdlib.h>
#define MODBUS_BUS SERIAL
#define MODBUS_SERIAL_RX_BUFFER_SIZE 64
#define MODBUS_SERIAL_INT_SOURCE MODBUS_INT_EXT
#define MODBUS_TYPE MODBUS_TYPE_MASTER
#define MODBUS_SERIAL_RX_PIN PIN_B0
#define MODBUS_SERIAL_TX_PIN PIN_B1
#define MODBUS_SERIAL_BAUD 19200
#define MODBUS_SLAVE_ADDRESS 10
#include "modbus.c"
char full_message[10]={'$','R','F','Z','Z','E','N','D',0xD,0xA};
int16 temp;
int8 lsb,msb;
int8 tempson1,tempson2;
int i;
void read_all_holding()
{
if(!(modbus_read_holding_registers(MODBUS_SLAVE_ADDRESS,1024,8)))
{
//Started at 1 since 0 is quantity of coils//
for(i=1; i < (modbus_rx.len); ++i)
fprintf(COM_A,"%X ", modbus_rx.data[i]);
}
else
{
fprintf(COM_A,"Exception %X", modbus_rx.error);
}
/*
modbus_read_holding_registers(MODBUS_SLAVE_ADDRESS,1030,2);
for(i=1; i < (modbus_rx.len); ++i)
fprintf(COM_A,"%X ", modbus_rx.data[i]);
*/
}
void main()
{
setup_wdt(WDT_ON);
// setup_timer_0(RTCC_INTERNAL);
// enable_interrupts(INT_EXT);
//SET_TRIS_B( 0xf0 );
modbus_init();
tempson1=0xD;
tempson2=0xA;
fprintf(COM_A,"$C2");
while(1)
{
read_all_holding();
output_low(PIN_B4);
//fprintf(COM_A,full_message);
// fprintf(COM_A,full_message);
delay_ms(400);
//fprintf(COM_A,"denemebilgisayarı");
output_high(PIN_B4);
//delay_ms(1000);
}
}
|
This is my hardware test program. I was compiling and only one warning message:
Quote: |
Interrupt disabled during call to prevent re-entrancy:(modbus_calc_crc) |
I send to read holding register command. My second uart to pc send me only time out error. But if I can use 232 serial monitor I can see all correct register value. |
|