CAN on STR9
Company  
ST Home | Microcontrollers

Index  »  CAN  »  CAN on STR9
     
   CAN on STR9
 Moderated by :   »  Jatin

Author
beginning argument    ( Replies received: 3 )
s_bhujbal   Posted 19-04-2008 at 13:05   



Registered on :
03-20-2009

Messages : 11

 OFF-Line

Dear All,
I am trying CAN on STR9. I tried examples given on ST site & those are working on STR910-EVAL board. But those examples are for Loop Back mode of CAN. I require to communicate with other chips through CAN.
I want to know how to configure CAN & send data to external device through CAN using ST CAN APIs.
Can anybody help me in this issue ?

Thanks




 Profile   Quote  
senthilnathans   Posted 19-04-2008 at 14:43   



Registered on :
04-07-2009

Messages : 3

 OFF-Line

Hi,
This is Senthilnathan.
I have attached the CAN_Init() function with this mail.
This function configures the GPIO, bit timing, message objects and VIC.

Use the same SCU_Configuration of the sample program from ST9.

void CAN_Init(void)
{

GPIO_InitTypeDef GPIO_InitStructure;

/*********************GPIO config**********************/
/* Initialize the ports for internal CAN communication */
/* P5.0 alternate input 1, CAN_RX pin 12*/
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;
GPIO_InitStructure.GPIO_Direction=GPIO_PinInput;
GPIO_InitStructure.GPIO_Type=GPIO_Type_PushPull;
GPIO_InitStructure.GPIO_IPConnected=GPIO_IPConnected_Enable;
GPIO_InitStructure.GPIO_Alternate=GPIO_InputAlt1;
GPIO_Init(GPIO5,&GPIO_InitStructure);

/* P3.6 alternate output 2, CAN_TX pin 66*/
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6;
GPIO_InitStructure.GPIO_Direction=GPIO_PinOutput;
GPIO_InitStructure.GPIO_Type=GPIO_Type_PushPull;
GPIO_InitStructure.GPIO_IPConnected=GPIO_IPConnected_Enable;
GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt3;
GPIO_Init(GPIO3,&GPIO_InitStructure);

/********************BIT timing config****************/
/* Initialize the internal CAN at a standard bitrate, interrupts disabled */
/* Set internal CAN BIT Timing */
CAN_EnterInitMode(CAN_CR_CCE);
CAN_SetTiming(11,4,4,5);
CAN_LeaveInitMode();

/*****************Message object config****************/
CAN_InvalidateAllMsgObj();
/* Configure the internal CAN message Tx object */
CAN_SetTxMsgObj(CAN_TX_MSGOBJ, CAN_EXT_ID);
/* Configure the internal CAN message Rx object */
CAN_SetRxMsgObj(CAN_RX_MSGOBJ, CAN_EXT_ID, 0, CAN_LAST_EXT_ID, TRUE);
/* initialize the interrupt controller */

/*****************VIC and interrupt Config***************************/
VIC_Config(CAN_ITLine, VIC_IRQ, 1);
/* Enable and Configure the interrupts for internal CAN */
VIC_ITCmd(CAN_ITLine, ENABLE);

/* Enable all CAN interrupts and disable auto matic retransmission */
CAN->CR = CAN->CR | CAN_CR_EIE | CAN_CR_SIE | CAN_CR_IE | CAN_CR_DAR;
}
main()
{
SCU_Configuration;/*PCLK=8MHz*/
CAN_Init; /* 100 kbps */
TxCanMsg loaded with data;
CAN_SendMessage(0,&TxCanMsg );
}


when you send a message via CAN to other node check the TEC register.
It should be 0. If it is greater than 0 then a transmission have occured. So correct the bit timing of the other node.


[ This message was edited by: senthilnathans on 19-04-2008 14:44 ]




Attachments : CAN_Init.txt   
 Profile   Quote  
s_bhujbal   Posted 21-04-2008 at 13:55   



Registered on :
03-20-2009

Messages : 11

 OFF-Line

Dear senthilnathans,
Thanks for replying & giving so much stuff. I copied & paste Your code but it doen't worked. Today I tried CAN communication betwwen STR9 & STR7 ( with REVA kit ). I tried it multiple ways, but still I am not successful. Now I am doubting about Physical connection between CAN.
I am doing connection like follows
STR9 CANH <----> STR7 CANH
STR9 CANL <----> STR7 CANL
STR9 GND <----> STR7 GND
Is it right ?
Please tell every doubt & suggetion You have.



 Profile   Quote  
senthilnathans   Posted 28-04-2008 at 07:56   



Registered on :
04-07-2009

Messages : 3

 OFF-Line

I hope you have a transreceiver between the bus and the microcontoller.
If you have an oscilloscope you can just check whether there is any data transmission in the bus when you transmit or receive.

And also when you transmit the data in the bus from one node to other and if there is a error in tx, Tx error counter (TEC)is incremented in Tx controller and the Rx error counter (REC) is incremented in the rx controller. If this happens then the line is ok. The problem can be the bit timing configuration values and baud rate.



 Profile   Quote  
On Top

Search in the forums
 
Jump To