/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / USB to CAN

Username:     
Password:     
             

Forum

# 1   2012-07-23 13:19:36 USB to CAN

chowdaiah
New member
Registered: 2011-10-27
Posts: 3

USB to CAN

Hello,

I am working on the STM32F103C8T6 controller for completing a data transfer task. Here on one end, the USB has to be used and on the side, the CAN needs to be used.

However, this transfer has to be done simultaneously on the USB and the CAN. That is these two peripherals must work at the same time.

I would like to know if this can be done using STM32F103 series. If so, Could you point me to any application note on your website, which can illustrate this task.


regards,
chowdaiah

Online

Offline

 

# 2   2012-11-10 18:13:59 USB to CAN

MCSolution
New member
Registered: 2010-11-27
Posts: 5

Re: USB to CAN

I can recommend the following projects for a CAN example:
STM32-baudrate-calculation-1.0.zip
Circle_4.11/OS/library/stm32f10x_can.c


int CAN_driver_init(BaudRateT rate)
{
    comBaudRate = rate;

   CAN_InitTypeDef        CAN_InitStructure;
   CAN_FilterInitTypeDef  CAN_FilterInitStructure;
   /* CAN register init */
   CAN_DeInit(CAN1);
   
   CAN_StructInit(&CAN_InitStructure);
   
   /* CAN cell init */
// Reference Manual: If ABOM is set, the bxCAN will start the recovering 
// sequence automatically after it has entered Bus-Off state.
    CAN_InitStructure.CAN_TTCM = DISABLE;
   CAN_InitStructure.CAN_ABOM = ENABLE;    // ENABLE
   CAN_InitStructure.CAN_AWUM = DISABLE;
   CAN_InitStructure.CAN_NART = DISABLE;
   CAN_InitStructure.CAN_RFLM = DISABLE;
   CAN_InitStructure.CAN_TXFP = DISABLE;
   CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
   CAN_InitStructure.CAN_SJW  = CAN_SJW_1tq;

    switch (rate)
    {
    case BAUD_10KBIT:
        // LCD_display_Text(0,40," 10kBit");
        CAN_InitStructure.CAN_Prescaler = 200;
        CAN_InitStructure.CAN_BS1       = 8;
        CAN_InitStructure.CAN_BS2       = 7;
        break;
    case BAUD_20KBIT:
        // LCD_display_Text(0,40," 20kBit");
        CAN_InitStructure.CAN_Prescaler = 100;
        CAN_InitStructure.CAN_BS1       = 8;
        CAN_InitStructure.CAN_BS2       = 7;
        break;
    case BAUD_50KBIT:
        // LCD_display_Text(0,40," 50kBit");
        CAN_InitStructure.CAN_Prescaler = 40;
        CAN_InitStructure.CAN_BS1       = 8;
        CAN_InitStructure.CAN_BS2       = 7;
        break;
    case BAUD_125KBIT:
        // LCD_display_Text(0,40,"125kBit");
        CAN_InitStructure.CAN_Prescaler = 16;
        CAN_InitStructure.CAN_BS1       = 8;
        CAN_InitStructure.CAN_BS2       = 7;
        break;
    case BAUD_250KBIT:
        // LCD_display_Text(0,40,"250kBit");
        CAN_InitStructure.CAN_Prescaler = 8;
        CAN_InitStructure.CAN_BS1       = 8;
        CAN_InitStructure.CAN_BS2       = 7;
        break;
    case BAUD_500KBIT:
        // LCD_display_Text(0,40,"500kBit");
        CAN_InitStructure.CAN_Prescaler = 4;
        CAN_InitStructure.CAN_BS1       = 8;
        CAN_InitStructure.CAN_BS2       = 7;
        break;
    case BAUD_800KBIT:
        // LCD_display_Text(0,40,"800kBit");
        CAN_InitStructure.CAN_Prescaler = 3;
        CAN_InitStructure.CAN_BS1       = 7;
        CAN_InitStructure.CAN_BS2       = 5;
        break;
    case BAUD_1MBIT:
        // LCD_display_Text(0,40,"  1MBit");
        CAN_InitStructure.CAN_Prescaler = 2;
        CAN_InitStructure.CAN_BS1       = 8;
        CAN_InitStructure.CAN_BS2       = 7;
        break;
    default:
        // LCD_display_Text(0,40,"defBaud");
        // 500kBit
       CAN_InitStructure.CAN_Prescaler = 4;
       CAN_InitStructure.CAN_BS1       = 8;
       CAN_InitStructure.CAN_BS2       = 7;
        break;
    }

   CAN_Init(CAN1, &CAN_InitStructure);
   
   /* CAN filter init */
   CAN_FilterInitStructure.CAN_FilterNumber         =      0;
   CAN_FilterInitStructure.CAN_FilterMode           = CAN_FilterMode_IdMask;
   CAN_FilterInitStructure.CAN_FilterScale          = CAN_FilterScale_32bit;
   CAN_FilterInitStructure.CAN_FilterIdHigh         = 0x0000;
   CAN_FilterInitStructure.CAN_FilterIdLow          = 0x0000;
   CAN_FilterInitStructure.CAN_FilterMaskIdHigh     = 0x0000;
   CAN_FilterInitStructure.CAN_FilterMaskIdLow      = 0x0000;
   CAN_FilterInitStructure.CAN_FilterFIFOAssignment =      0;
   CAN_FilterInitStructure.CAN_FilterActivation     = ENABLE;
   CAN_FilterInit(&CAN_FilterInitStructure);
   
    // CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
    return 0;
}

Offline

 

Board footer