cancel
Showing results for 
Search instead for 
Did you mean: 

CAN problems

magicobob
Associate
Posted on April 23, 2009 at 02:52

CAN problems

6 REPLIES 6
magicobob
Associate
Posted on May 17, 2011 at 09:55

Hi! I have some problems configuring the STR912-SK board to send a message to another board via CAN bus. I'm using the CAN in LoopBack Mode (the library example) and I have no problem. But I'm not able to modify the example to get my CAN bus work with another board.

Have you got any examples about how to configure (or initialize) the microcontroller? In particular I get from the status register the Bit0Error. Do you know ho to solve this error?

Thank you for your help!

For any suggestions:

mailto:magicobob@yahoo.it

sr_shinde
Associate II
Posted on May 17, 2011 at 09:55

HI

Check out Mes ID type (STD/EXT).

Try with both.

If none of them works checkout with timing configuration for CAN bus.

Regards

Sai

subashiniv
Associate II
Posted on May 17, 2011 at 09:55

Hi, i am also facing the same problem using the same microcontroller...it works fine in Loopback mode but i get a Bit0Error when i send a message, i have set the bit rate to 100 kbit/s. Please provide me some example or guide me to solve the above problem.

s_bhujbal
Associate II
Posted on May 17, 2011 at 09:55

Check out following sequence for configuring CAN,

1) Enable Clock for CAN Module

2) Disable Reset for CAN Module

3) Check pin configuration You are using.( Assuret that You are enabled

clock & disabled Reset for those GPIO module )

4) CAN Module configuration i.e. Interrupt & bit rate, etc.

I am giving one example code for it, You customise it for Yourself.

Pin Initialisation

/* Rx Pin configuration */

GPIO_StructInit(&GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin= < Your pin no >;

GPIO_InitStructure.GPIO_Direction=GPIO_PinInput;

GPIO_InitStructure.GPIO_Type=GPIO_Type_PushPull;

GPIO_InitStructure.GPIO_IPInputConnected=GPIO_IPInputConnected_Enable;

GPIO_InitStructure.GPIO_Alternate= < Your pin alternate option >;

GPIO_Init( < Your port no >,&GPIO_InitStructure);

/* Tx pin configuration*/

GPIO_StructInit(&GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin= < Your pin no >;

GPIO_InitStructure.GPIO_Direction=GPIO_PinOutput;

GPIO_InitStructure.GPIO_Type=GPIO_Type_PushPull;

GPIO_InitStructure.GPIO_IPInputConnected=GPIO_IPInputConnected_Disable; //GPIO_InitStructure.GPIO_Alternate=< Your pin alternate option >;

GPIO_Init(< Your port no >,&GPIO_InitStructure);

CAN_InitStructure.CAN_ConfigParameters=CAN_CR_IE;

CAN_InitStructure.CAN_Bitrate=CAN_BITRATE_250K; < Your bit rate >

CAN_Init(&CAN_InitStructure);

CAN_SetUnusedAllMsgObj();

CAN_SetTxMsgObj( , CAN_STD_ID, ENABLE);

CAN_SetRxMsgObj(, CAN_STD_ID, 0, CAN_LAST_STD_ID, TRUE);

/* Interrupt Configuration */

VIC_Config(CAN_ITLine, VIC_IRQ, < Your slot no >); //Initialise VIC for CAN

VIC_ITCmd(CAN_ITLine,ENABLE); //Enable Interrupt

CAN->CR = CAN->CR | CAN_CR_EIE | CAN_CR_SIE | CAN_CR_IE ;

Remember that bit rate setting changes if You change PCLK

All the Best 😉

subashiniv
Associate II
Posted on May 17, 2011 at 09:55

hi,

Thank you for providing me with the example. I have developed my piece of code and still i face the same problem(Bit0Error). Could you please tell me what might be the possible causes. Here is the code which i developed

void InitialiseProcessor( void )

{

GPIO_InitTypeDef GPIO_InitStruct ;

BYTE TempByte ;

/* configure system clock to osc clock frequency of 25MHz */

SCU_MCLKSourceConfig( SCU_MCLK_OSC ) ;

/*insert a delay, disable the PLL as it is not selected as the clock source */

for( TempByte = 0 ; TempByte < 10 ; TempByte++ )

{

;

}

PLL_Status = SCU_PLLCmd( DISABLE );

/* Enable clock for CAN, GPIO and interrupts */

SCU_APBPeriphClockConfig( __CAN, ENABLE ) ;

SCU_APBPeriphClockConfig( __GPIO1, ENABLE ) ;

SCU_AHBPeriphClockConfig( __VIC, ENABLE ) ;

SCU_APBPeriphReset( __CAN, DISABLE ) ;

SCU_APBPeriphReset( __GPIO1, DISABLE ) ;

SCU_AHBPeriphReset( __VIC, DISABLE ) ;

/* configure GPIO pins P1.5 for CAN_rx and P1.6 for CAN_tx */

GPIO_DeInit( GPIO1 ) ;

/* Configure GPIO P1.6 for CAN_tx */

GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 ;

GPIO_InitStruct.GPIO_Direction = GPIO_PinOutput ;

GPIO_InitStruct.GPIO_Type = GPIO_Type_PushPull ;

GPIO_InitStruct.GPIO_IPConnected = GPIO_IPConnected_Disable;

GPIO_InitStruct.GPIO_Alternate = GPIO_OutputAlt2 ;

GPIO_Init( GPIO1, &GPIO_InitStruct ) ;

/* Configure GPIO P1.5 for CAN_rx */

GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5 ;

GPIO_InitStruct.GPIO_Direction = GPIO_PinInput ;

GPIO_InitStruct.GPIO_Type = GPIO_Type_PushPull ;

GPIO_InitStruct.GPIO_IPConnected = GPIO_IPConnected_Enable ;

GPIO_InitStruct.GPIO_Alternate = GPIO_InputAlt1 ;

GPIO_Init( GPIO1, &GPIO_InitStruct ) ;

/*Enable the CAN interrupt request line */

VIC_ITCmd( CAN_ITLine, ENABLE ) ;

/*Configure the CAN interrupt as an IRQ interrupt with priority 2 */

VIC_Config( CAN_ITLine, VIC_IRQ, 2 ) ;

InitialiseCAN_Module();

CAN_Check();

}

void InitialiseCAN_Module( void )

{

CAN_InitTypeDef CAN_InitStructure ;

int j;

/* Initializes the CAN peripheral registers to their default values */

CAN_DeInit( ) ;

/* Initialize CAN peripheral */

CAN_InitStructure.CAN_ConfigParameters = CAN_CR_DAR | CAN_CR_SIE | CAN_CR_IE;

CAN_InitStructure.CAN_Bitrate = CAN_BITRATE_100K;

CAN_Init(&CAN_InitStructure);

/* clear CCE and INIT bit */

CAN_LeaveInitMode( ) ;

/* configure the message objects 2 to 31 as unused */

for (j = 2; j<=31; j++)

{

CAN_SetUnusedMsgObj(j);

}

/* configure msg box 0 for CAN TX */

CAN_SetTxMsgObj(CAN_TX_MSGOBJ, CAN_EXT_ID);

/* configure msg box 1 for CAN RX */

CAN_SetRxMsgObj(CAN_RX_MSGOBJ, CAN_EXT_ID, 0, CAN_LAST_EXT_ID, TRUE);

}

sr_shinde
Associate II
Posted on May 17, 2011 at 09:55

Hi

check out the clock configuration for CAN and accordingly configure can timing array in can c file. Try with different values of SJW.

Regards

Sai