arafatronics
Newbie level 3
- Joined
- Apr 10, 2013
- Messages
- 3
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,323
Hi
I'm Programming 2 pic18f4550 -Master and slave- for the RS485 communication using MAX485
when i tried it in protus it worked very nice but in hardware there is nothing work at all
the slave code is :
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() {
ADCON1 |= 0x0F; // Configure all ports with analog function as digital
CMCON |= 7; // Disable comparators
PORTB = 0;
PORTD = 0;
TRISB = 0;
TRISC6_bit = 0;
TRISC7_bit = 1;
TRISC1_bit = 0;
TRISD = 0;
UART1_Init(9600); // initialize UART1 module
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[0] == 0x01){
RD3_bit ^= 1;
Delay_ms(1000);
dat[0] = 0;
}
if(dat[0] == 0x02){
RD2_bit ^= 1;
Delay_ms(1000);
dat[0] = 0;
}
if(!RC1_bit){
Delay_ms(50);
if(!RC1_bit){
RD3_bit ^= 1;
}
}
}
}
I suppose that the problem is in the slave code
i tried to connect the A and B to VCC and GND by resistors but no action happens
could please help me
thanks a lot
I'm Programming 2 pic18f4550 -Master and slave- for the RS485 communication using MAX485
when i tried it in protus it worked very nice but in hardware there is nothing work at all
the slave code is :
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() {
ADCON1 |= 0x0F; // Configure all ports with analog function as digital
CMCON |= 7; // Disable comparators
PORTB = 0;
PORTD = 0;
TRISB = 0;
TRISC6_bit = 0;
TRISC7_bit = 1;
TRISC1_bit = 0;
TRISD = 0;
UART1_Init(9600); // initialize UART1 module
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[0] == 0x01){
RD3_bit ^= 1;
Delay_ms(1000);
dat[0] = 0;
}
if(dat[0] == 0x02){
RD2_bit ^= 1;
Delay_ms(1000);
dat[0] = 0;
}
if(!RC1_bit){
Delay_ms(50);
if(!RC1_bit){
RD3_bit ^= 1;
}
}
}
}
I suppose that the problem is in the slave code
i tried to connect the A and B to VCC and GND by resistors but no action happens
could please help me
thanks a lot