i need to transmit a can message from PIC18f45f. cann anoyone please tell me what is wrong here. This is my code. I use CAN-MCP2551. # include <p18f458.h> # include <p18cxxx.h> # include <can2510.h> # define RXF5 101 # define RXF4 100 # define RXF3 011 # define RXF2 010 # define RXF1 001 \\ only possible when RXB0DBENbit is set # define RXF0 000 \\ only possible when RXB0DBENbit is set # define CAN_TX_PRIORITY_0 0 # define CAN_TX_STD_FRAME 0 # define CAN_TX_NO_RTR_FRAME 0 typedef struct CANMessage { unsigned long Address; unsigned char MessageData[8]; unsigned char NoOfBytes; unsigned char Priority; unsigned Ext:1; unsigned Remote:1; }; char CANPut(CANMessage) void Can_Config (void); void Can_Init (void); void Can_Txmsg (void); void Can_Txinit (void); /* for can_message receive unsigned char NewMessage[8]; unsigned char NewMessageData[8]; unsigned char NewMessageLen; unsigned int NewMessageFlags;*/ unsigned char bus_free; unsigned char r ; void main() { Can_Config(); // to configure CANRX and TX as interface Can_Init(); // can_initialising and configuring CANCON = 0x00; // Normal mode , to send or receive a message ,can should be in the normal mode CANSTAT = 0x00; // Normal mode Can_Txinit();// initialising to transmit message TXB0CONbits.TXREQ = 1; // TXREQ is set, the TXABT, TXLARB and TXERR bits will be cleared if(bus_free == 0) { r = 1; // breakpoint CANPut(0x02,0x01,1,CAN_TX_PRIORITY_0 & CAN_TX_STD_FRAME & CAN_TX_NO_RTR_FRAME); while(bus_free == 0) continue; } r = 0; } void Can_Txinit() { TXB0CON = 0x00; PIE3bits.TXB0IE = 0; TXB0SIDL = 0; // lower byte transmit buffer with standard identifier TXB0SIDH = 0; // higher byte transmit buffer with standard identifier TXB0DLC = 0; // data length code } void Can_Config() { TRISBbits.TRISB3 = 1; //to configure CANRX as interface TRISBbits.TRISB2 = 0; //to configure CANTX as interface } void Can_Init() { CANCON = 0x10; //Request configuration mode CANSTAT = 0x10; // Configuration mode RXB0CON = 0x64; // Receive all messages (including those with errors, Roll over from receive buffer0to1 RXB1CON = 0x60; // Receive all messages (including those with errors, Roll over from receive buffer0to1 BRGCON1 = 0x01; BRGCON2 = 0x00; BRGCON3 = 0x00; } Antworten können aud Deutsch, Englich oder Französisch erfolgen besten Dank
Vor allem fehlt was. Erstens ein Semikolon hinter der Deklaration von CANPut, zweitens der Code davon, drittens die Schilderung des Problems. Und als Anhang macht sich der Code auch besser, weil die Formatierung nicht so vor die Hunde geht.
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.