Author Topic: CAN on SBC68EC  (Read 2170 times)

mzninja

  • Newbie
  • *
  • Posts: 2
    • View Profile
CAN on SBC68EC
« on: April 25, 2013, 01:21:53 AM »
Hi, we are two german students trying to get the CAN-modul working. Has anyboby ever got this modul working? We already wrote some source code and implemented it to the webserver. We also tried to write a standalone program which should write a message to the can. We never got any response.

Could anybody help us with our problem.

this is the code we wrote. It only should send a message to the CAN.

#include <p18cxxx.h>
#include <p18f6680.h>
#include <CAN18XX8.h>
#include <compiler.h>

BYTE* Data[8];   
BYTE DataLen;   
int RXFilterMatch;

unsigned short init_flag, send_flag, dt, len, read_flag;
BYTE SJW, BRP, Phase_Seg1, Phase_Seg2, Prop_Seg;
char txt[4];
unsigned long id, mask;

BOOL CANSendMessage(unsigned long id, BYTE *Data, BYTE DataLen , enum CAN_TX_MSG_FLAGS MsgFlags);                 
void CANInitialize(BYTE, BYTE, BYTE, BYTE, BYTE,  enum CAN_CONFIG_FLAGS Type);             
void CANSetMask(enum CAN_MASK code, unsigned long, enum CAN_CONFIG_FLAGS Type);
void CANSetFilter (enum CAN_FILTER code ,unsigned long, enum CAN_CONFIG_FLAGS Type);
void CANSetOperationMode(enum CAN_OP_MODE mode);
         
void canbus(void)
{

SJW = 1;                              
BRP = 1;                     
Phase_Seg1 = 6;
Phase_Seg2 = 7;
Prop_Seg = 6;

init_flag = CAN_CONFIG_SAMPLE_THRICE &                     
         CAN_CONFIG_PHSEG_PRG_ON &
         CAN_CONFIG_STD_MSG &
         CAN_CONFIG_DBL_BUFFER_ON &
         CAN_CONFIG_VALID_XTD_MSG &
         CAN_CONFIG_LINE_FILTER_OFF;

send_flag = CAN_TX_PRIORITY_0 &
         CAN_TX_XTD_FRAME &
         CAN_TX_NO_RTR_FRAME;

read_flag = 0;

TRISGbits.TRISG0 = 0;
TRISGbits.TRISG2 = 1;


//Initialize CAN module

CANInitialize(SJW, BRP, Phase_Seg1, Phase_Seg2, Prop_Seg, init_flag);

//Set CAN CONFIG mode

CANSetOperationMode(CAN_OP_MODE_CONFIG);                                    

mask = 1;

//Set all MASK1 bits to 1s

CANSetMask(CAN_MASK_B1, mask, CAN_CONFIG_STD_MSG);

//Set all MASK2 bits to 1s

CANSetMask(CAN_MASK_B2, mask, CAN_CONFIG_STD_MSG);

//Set id of filter B2_F3 to 3

CANSetFilter(CAN_FILTER_B1_F1, 3, CAN_CONFIG_STD_MSG);

//Set CAN module to NORMAL mode

CANSetOperationMode(CAN_OP_MODE_NORMAL);

//Daten fr CAN-Nachricht erzeugen

*Data[0] = '1';
*Data[1] = '2';
*Data[2] = '4';
*Data[3] = '8';
*Data[4] = '16';
*Data[5] = '32';
*Data[6] = '64';
*Data[7] = '128';

id = 111;
CANSendMessage(id, *Data, 8,
CAN_TX_STD_FRAME &
CAN_TX_NO_RTR_FRAME);                              
}

mzninja

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: CAN on SBC68EC
« Reply #1 on: April 25, 2013, 11:21:18 AM »
Why doesn't even this simple program work?? Only trying to switch the LED

#include <p18f6680.h>

#pragma config OSC = HSPLL, OSCS = OFF
        #pragma config PWRT = ON
        #pragma config BOR = ON, BORV = 42  /* Brown out reset on */
        #pragma config WDT = OFF
        #pragma config CCP2MX = ON          /* Use C1 for CCP2 */
        #pragma config LVP = OFF
        #pragma config DEBUG = OFF
        #pragma config WDTPS = 32   /* Watchdog prescaler = 32. This gives: min=224ms, typ=576ms, max=1056ms */
        #pragma config MCLRE = ON
        #pragma config STVR = ON   /* Stack overflow reset on */

        //All code protection off
        #pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF
        //Data EEPROM protect off
        #pragma config CPD = OFF, WRTD = OFF
        //All write protection off
        #pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF
        //Table read protection off
        #pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF

        #pragma config CPB = OFF
        #pragma config WRTB = OFF
        #pragma config WRTC = OFF
        #pragma config EBTRB = OFF

void main(void)
{
        TRISB = 0b110111111;
        LATB = 0b001000000;
 while(1)
 {
 }
   
}