nagarajud
Newbie level 3
hi,
i got error in master reception. master controller establishing transmission and slave controller receiving data.
but when i'm sending data from slave to master controller got error.
but one thing is i used adm485 with 120ohm resistor and pull-up and pull down resistors rs485 transceiver in master and max485 without pull-up,pull-down and 120ohm resistor in slave.
R/T pin of transceiver to RC2(PWM) pin of MUC
program for master:
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
char dat[9],data1[8]; // buffer for receving/sending messages
char i,j;
sbit rs485_rxtx_pin at RC2_bit; // set transcieve pin
sbit rs485_rxtx_pin_direction at TRISC2_bit; // set transcieve pin direction
// Interrupt routine
void interrupt() {
RS485Master_Receive(data1);
}
void main(){
ancon0=0;
ancon1=0;
ancon2=0;
LATB = 0;
LATD = 0;
TRISB = 0;
TRISD = 0;
UART1_Init(9600); // initialize UART1 module
lcd_init();
Delay_ms(100);
RS485Master_Init(); // initialize MCU as Master
dat[0] = 0x31;
dat[1] = 0x32;
dat[2] = 0x33;
dat[4] = 0; // ensure that message received flag is 0
dat[5] = 0; // ensure that error flag is 0
dat[6] = 0;
RS485Master_Send(dat,3,160);
RCIE_bit = 1; // enable interrupt on UART1 receive
TXIE_bit = 0; // disable interrupt on UART1 transmit
PEIE_bit = 1; // enable peripheral interrupts
GIE_bit = 1; // enable all interrupts
while (1){
// upon completed valid message receiving
// data[4] is set to 255
if (data1[5]) { // if an error detected, signal it
lcd_out(2,1,"ERROR");
data1[5] = 0;
}
if (data1[4]) { // if message received successfully
data1[4] = 0; // clear message received flag
j = data1[3];
for (i = 1; i <= data1[3]; i++) { // show data on PORTB
lcd_chr(1,i,data1[i-1]);
} // increment received dat[0]
Delay_ms(30);
RS485Master_Send(dat,3,160);
}
}
}
program for slave:
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
char dat[9]; // buffer for receving/sending messages
char i,j;
sbit rs485_rxtx_pin at RC2_bit; // set transcieve pin
sbit rs485_rxtx_pin_direction at TRISC2_bit; // set transcieve pin direction
// Interrupt routine
void interrupt() {
RS485Slave_Receive(dat);
}
void main() {
ancon0=0;
ancon1=0;
ancon2=0;
LATB = 0;
LATD = 0;
TRISB = 0;
TRISD = 0;
UART1_Init(9600); // initialize UART1 module
lcd_init();
Delay_ms(100);
RS485Slave_Init(160); // Intialize MCU as slave, address 160
dat[4] = 0; // ensure that message received flag is 0
dat[5] = 0; // ensure that message received flag is 0
dat[6] = 0; // ensure that error flag is 0
RCIE_bit = 1; // enable interrupt on UART1 receive
TXIE_bit = 0; // disable interrupt on UART1 transmit
PEIE_bit = 1; // enable peripheral interrupts
GIE_bit = 1; // enable all interrupts
while (1) {
if (dat[5]) { // if an error detected, signal it by
lcd_out(2,1,"ERROR");
dat[5] = 0;
}
if (dat[4]) { // upon completed valid message receive
dat[4] = 0; // data[4] is set to 0xFF
j = dat[3];
for (i = 1; i <= dat[3];i++){
lcd_chr(1,i,dat[i-1]);
}
dat[0] = 65;
dat[1]=66;
dat[2]=67; // increment received dat[0]
Delay_ms(30);
RS485Slave_Send(dat,3); // and send it back to master
}
}
}
please any one guide me.
Thanks advance.
i got error in master reception. master controller establishing transmission and slave controller receiving data.
but when i'm sending data from slave to master controller got error.
but one thing is i used adm485 with 120ohm resistor and pull-up and pull down resistors rs485 transceiver in master and max485 without pull-up,pull-down and 120ohm resistor in slave.
R/T pin of transceiver to RC2(PWM) pin of MUC
program for master:
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
char dat[9],data1[8]; // buffer for receving/sending messages
char i,j;
sbit rs485_rxtx_pin at RC2_bit; // set transcieve pin
sbit rs485_rxtx_pin_direction at TRISC2_bit; // set transcieve pin direction
// Interrupt routine
void interrupt() {
RS485Master_Receive(data1);
}
void main(){
ancon0=0;
ancon1=0;
ancon2=0;
LATB = 0;
LATD = 0;
TRISB = 0;
TRISD = 0;
UART1_Init(9600); // initialize UART1 module
lcd_init();
Delay_ms(100);
RS485Master_Init(); // initialize MCU as Master
dat[0] = 0x31;
dat[1] = 0x32;
dat[2] = 0x33;
dat[4] = 0; // ensure that message received flag is 0
dat[5] = 0; // ensure that error flag is 0
dat[6] = 0;
RS485Master_Send(dat,3,160);
RCIE_bit = 1; // enable interrupt on UART1 receive
TXIE_bit = 0; // disable interrupt on UART1 transmit
PEIE_bit = 1; // enable peripheral interrupts
GIE_bit = 1; // enable all interrupts
while (1){
// upon completed valid message receiving
// data[4] is set to 255
if (data1[5]) { // if an error detected, signal it
lcd_out(2,1,"ERROR");
data1[5] = 0;
}
if (data1[4]) { // if message received successfully
data1[4] = 0; // clear message received flag
j = data1[3];
for (i = 1; i <= data1[3]; i++) { // show data on PORTB
lcd_chr(1,i,data1[i-1]);
} // increment received dat[0]
Delay_ms(30);
RS485Master_Send(dat,3,160);
}
}
}
program for slave:
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
char dat[9]; // buffer for receving/sending messages
char i,j;
sbit rs485_rxtx_pin at RC2_bit; // set transcieve pin
sbit rs485_rxtx_pin_direction at TRISC2_bit; // set transcieve pin direction
// Interrupt routine
void interrupt() {
RS485Slave_Receive(dat);
}
void main() {
ancon0=0;
ancon1=0;
ancon2=0;
LATB = 0;
LATD = 0;
TRISB = 0;
TRISD = 0;
UART1_Init(9600); // initialize UART1 module
lcd_init();
Delay_ms(100);
RS485Slave_Init(160); // Intialize MCU as slave, address 160
dat[4] = 0; // ensure that message received flag is 0
dat[5] = 0; // ensure that message received flag is 0
dat[6] = 0; // ensure that error flag is 0
RCIE_bit = 1; // enable interrupt on UART1 receive
TXIE_bit = 0; // disable interrupt on UART1 transmit
PEIE_bit = 1; // enable peripheral interrupts
GIE_bit = 1; // enable all interrupts
while (1) {
if (dat[5]) { // if an error detected, signal it by
lcd_out(2,1,"ERROR");
dat[5] = 0;
}
if (dat[4]) { // upon completed valid message receive
dat[4] = 0; // data[4] is set to 0xFF
j = dat[3];
for (i = 1; i <= dat[3];i++){
lcd_chr(1,i,dat[i-1]);
}
dat[0] = 65;
dat[1]=66;
dat[2]=67; // increment received dat[0]
Delay_ms(30);
RS485Slave_Send(dat,3); // and send it back to master
}
}
}
please any one guide me.
Thanks advance.