Hello Everyone i m interfacing pic18f458 with mcp2551....but it is not giving me the required output
this is my code for transmitter side
Code C - [expand] |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
| void main()
{
InitECAN();
}
void InitECAN(void)
{
// Enter CAN module into config mode
CANCON = 0x80; //REQOP<2:0>=100
while(!(CANSTATbits.OPMODE2==1));
BRGCON1 = 0x01;
BRGCON2 = 0x90;
BRGCON3 = 0x02;
// Enter CAN module into normal mode
CANCON = 0x00;
while(!(CANSTATbits.OPMODE2==0));
TXB1CON =0x03;
TXB1SIDH=0x7E;
TXB1SIDL=0x00;
TXB1DLC =0x01;
TXB1D0 ='A';
TXB1CONbits.TXREQ = 1; //Set the buffer to transmit
}
and this is the code for receiver side
void main()
{
InitECAN();
}
void InitECAN(void)
{
// Enter CAN module into config mode
CANCON = 0x80; //REQOP<2:0>=100
while(!(CANSTATbits.OPMODE2==1));
BRGCON1 = 0x01;
BRGCON2 = 0x90;
BRGCON3 = 0x02;
RXM0SIDH=0xFF;
RXM0SIDL=0xFF; // Set to all ‘1’s so filter must match every bit
RXF0SIDH=0xFF;
RXF0SIDL=0xFF;
RXF1SIDH=0xFF;
RXF1SIDL=0xFF;
RXM1SIDH=0x7E; //
RXM1SIDL=0x00;
RXF2SIDH=0x7E; //Filter 2 matches 0x3f0
RXF2SIDL=0x00;
// Enter CAN module into normal mode
CANCON = 0x00;
while(!(CANSTATbits.OPMODE2==0));
while(!RXB1CONbits.RXFUL); //CheckRXB1
data=RXB1D0;
SendByteSerially(data);
} |
please help me....
thank you