AnsweredAssumed Answered

Problems with CAN Controller

Question asked by netto.moraes on Dec 5, 2013
Latest reply on Dec 5, 2013 by netto.moraes
Hoy!

I'm using the CAN1 and CAN2 controller micorcontrolador STM32F207IG. but I have the following problem:

Both controllers are communicating normally, but when the communication cable from the controller 1 is open, the microcontroller hangs.

Could someone help me on this problem, is it possible to enable and disable the CAN controller??

Thank you. The following code:


#include <RTL.h>                      /* RTX kernel functions & defines      */
#include <stm32f2xx.h>                /* STM32F40x register definitions      */
#include <RTX_CAN.h>                  /* CAN Generic functions & defines     */


__task void task_init                         (void);
__task void task_WATCHDOG          (void);
__task void task_SENDING_DATA      (void);
__task void task_RECEIVING_DATA      (void);


void RCC_Configuration(void);
void GPIO_Configuration(void);

void RCC_Configuration(void)
{
     /* GPIOA Periph clock enable */
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
     /* GPIOB Periph clock enable */
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
     /* GPIOC Periph clock enable */
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); 
     /* GPIOD Periph clock enable */
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
     /* GPIOE Periph clock enable */
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
     /* GPIOF Periph clock enable */
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
     /* GPIOG Periph clock enable */
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE);
          /* GPIOG Periph clock enable */
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOH, ENABLE);
          /* GPIOG Periph clock enable */
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOI, ENABLE);
}
/*--------------------------------------------------------------------------------*/


void GPIO_Configuration(void)
{
     /* Configuração Portas CAN1 --------------------------------------------------*/ 
       GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_CAN1); // CAN1 RX
       GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_CAN1); // CAN1 TX 
  
       GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
       GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
       GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
       GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
       GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
       GPIO_Init(GPIOD, &GPIO_InitStructure);
     /*----------------------------------------------------------------------------*/
     /* Configuração Portas CAN2 --------------------------------------------------*/ 
       GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_CAN2); // CAN2 RX
       GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_CAN2); // CAN2 TX 
  
       GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6;
       GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
       GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
       GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
       GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
       GPIO_Init(GPIOB, &GPIO_InitStructure);
     /*----------------------------------------------------------------------------*/
}

__task void task_init (void)  
{
     os_tsk_create (task_WATCHDOG,          8);
       os_tsk_create (task_SENDING_DATA,     6);
     os_tsk_create (task_RECEIVING_DATA, 4);                  
       os_tsk_delete_self();                         
}
__task void task_WATCHDOG (void)
{


       for (;;)
     {
          GPIOD->ODR ^= WATCHDOG_LED;


          if((com_CAN_1==1) && (com_CAN_2==1)) {GPIOE->BSRRL = SCAN_LED;}
          else {GPIOE->BSRRH = SCAN_LED;}


          os_dly_wait (100);                
     }
}

__task void task_SENDING_DATA (void)
{
     /* Inicializa Mensagem={ID, {data[0]..data[7]}, LEN, CHANNEL, FORMAT, TYPE} */
     CAN_msg msg_send_30_1  = { 30, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 8, 2, STANDARD_FORMAT, DATA_FRAME };
     /* Inicializa Mensagem={ID, {data[0]..data[7]}, LEN, CHANNEL, FORMAT, TYPE} */
     CAN_msg msg_send_20_2  = { 20, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 8, 2, STANDARD_FORMAT, DATA_FRAME };
     /* CAN1 Init, 1Mbit/s */


        CAN_init (1, 1000000);
     CAN_init (2, 1000000);


     CAN_start (1); /* Inicializa CAN1 */   
       CAN_start (2); /* Inicializa CAN2 */

       for (;;)
     {
         CAN_send (1, &msg_send_30_1, 15);
          msg_send_30_1.data[0] = 100;

          CAN_send (2, &msg_send_20_2, 15);

          os_dly_wait (50);                 
     }
}

__task void task_RECEIVING_DATA (void)
{
     CAN_msg msg_rece;

       CAN_rx_object (1, 2, 40, DATA_TYPE | STANDARD_TYPE);
     CAN_rx_object (2, 2, 10, DATA_TYPE | STANDARD_TYPE);

       for (;;)
     {
         if((CAN_receive (1, &msg_rece, 15) == CAN_OK))  
          {
               com_CAN_1=1;
                    if(msg_rece.id==40)
                  {
                    Rece_CAN1 = msg_rece.data[0]; 
                  }
          }
          else {com_CAN_1=0, Rece_CAN1=0;}

         if(CAN_receive (2, &msg_rece, 15) == CAN_OK) 
          {
               com_CAN_2=1;     
                    if(msg_rece.id==10)
                  {
                    // = msg_rece.data[0]; 
                  }
          }
          else {Rece_CAN1=0,com_CAN_2=0;} 

          //os_dly_wait (1);                
     }
}


int main (void)
{
     /* System clocks configuration -----------------------------------------------*/
       RCC_Configuration();

       /* GPIO configuration --------------------------------------------------------*/
       GPIO_Configuration();

     GPIOE->BSRRH = SCAN_LED;
     GPIOE->BSRRH = ERRO_LED;

    os_sys_init (task_init);
}


I'm using the CAN1 and CAN2 controller micorcontrolador STM32F207IGbut I have the following problem:

Both controllers are communicating normallybut when the communication cable from the controller microcontroller 1 is open latch.

Could someone help me on this problem, is it possible to enable and disable the CAN controller??


Thank you. The following code:
I'm using the CAN1 and CAN2 controller micorcontrolador STM32F207IGbut I have the following problem:

Both controllers are communicating normallybut when the communication cable from the controller microcontroller 1 is open latch.

Could someone help me on this problem, is it possible to enable and disable the CAN controller??


Thank you. The following code:
I'm using the CAN1 and CAN2 controller micorcontrolador STM32F207IGbut I have the following problem:

Both controllers are communicating normallybut when the communication cable from the controller microcontroller 1 is open latch.

Could someone help me on this problem, is it possible to enable and disable the CAN controller??


Thank you. The following code:
I'm using the CAN1 and CAN2 controller micorcontrolador STM32F207IGbut I have the following problem:

Both controllers are communicating normallybut when the communication cable from the controller microcontroller 1 is open latch.

Could someone help me on this problem, is it possible to enable and disable the CAN controller??


Thank you. The following code:

Outcomes